6#define _USE_MATH_DEFINES
17#include <cmrc/cmrc.hpp>
31#define LOG_THROTTLE_PERIOD 1.0
45 if (request ==
"help")
48 out.
addString(
"get_transform <src> <dst>: print the transform from <src> to <dst>");
49 out.
addString(
"list_transforms: print all the stored frame transforms");
50 out.
addString(
"list_frames: print all the available reference frames");
51 out.
addString(
"list_ports: print all the opened ports for transform broadcasting");
52 out.
addString(
"publish_transform <src> <dst> <portname> [format]: opens a port to publish transform from src to dst");
53 out.
addString(
"unpublish_transform <portname>: closes a previously opened port to publish a transform");
54 out.
addString(
"unpublish_all: closes a all previously opened ports to publish a transform");
55 out.
addString(
"set_static_transform_rad <src> <dst> <x> <y> <z> <roll> <pitch> <yaw>': create a static transform (angles in radians)");
56 out.
addString(
"set_static_transform_deg <src> <dst> <x> <y> <z> <roll> <pitch> <yaw>': create a static transform (angles in degrees)");
57 out.
addString(
"delete_static_transform <src> <dst>': delete a static transform");
58 out.
addString(
"generate_view <option>': generate a frames.pdf file showing the transform tree diagram.");
59 out.
addString(
" The following values are valid for option (default=none)");
60 out.
addString(
" 'show_rpy': show rotation as rpy angles");
61 out.
addString(
" 'show_quaterion:'show rotation as a quaternion");
62 out.
addString(
" 'show_matrix:'show rotation as a 3x3 rotation matrix");
64 else if (request ==
"list_frames")
66 std::vector<std::string> v;
69 out.
addString(
"List of available reference frames:");
74 std::string str = std::to_string(count) +
"- " +
vec;
78 else if (request ==
"get_transform")
85 out.
addString(
"Transform from " + src +
" to " + dst +
" is: ");
88 else if (request ==
"list_ports")
93 out.
addString(
"No ports are currently active");
104 else if (request ==
"publish_transform")
117 if (port_name[0] ==
'/') {
118 port_name.erase(port_name.begin());
125 if (!
r1) {
return r1; }
128 out.
addString(
"Requested src frame " + src +
" does not exists.");
132 if (!
r2) {
return r2; }
135 out.
addString(
"Requested dst frame " + dst +
" does not exists.");
159 b->transform_dst = dst;
178 out.
addString(
"unable to perform operation");
181 else if (request ==
"unpublish_all")
195 else if (request ==
"unpublish_transform")
199 if (port_name[0] ==
'/') {
200 port_name.erase(port_name.begin());
205 if ((*it)->port.getName() == port_name)
227 else if (request ==
"set_static_transform_rad" ||
228 request ==
"set_static_transform_deg")
236 if (request ==
"set_static_transform_rad")
242 else if (request ==
"set_static_transform_deg")
253 out.
addString(
"set_static_transform done");
261 else if (request ==
"generate_view")
266 }
else if (in.
get(1).
asString() ==
"show_matrix") {
274 else if (request ==
"delete_static_transform")
280 out.
addString(
"delete_static_transform done");
329 auto fs = cmrc::frameTransformRC::get_filesystem();
331 cfg.unput(
"filexml_option");
339 cfg.unput(
"local_rpc");
344 cfg.put(
"FrameTransform_verbose_debug",
vval);
440 return ReturnValue::return_code::return_value_error_generic;
447 std::lock_guard<std::recursive_mutex>
l(
p_cont->m_trf_mutex);
472 std::lock_guard<std::recursive_mutex>
l(
p_cont->m_trf_mutex);
479 return ConnectionType::DIRECT;
490 return ConnectionType::INVERSE;
509 return ConnectionType::UNDIRECT;
514 return ConnectionType::DISCONNECTED;
522 return ReturnValue::return_code::return_value_error_generic;
525 if (
conntype != ConnectionType::DISCONNECTED)
541 return ReturnValue::return_code::return_value_error_not_ready;
548 return ReturnValue::return_code::return_value_error_not_ready;
556 return ReturnValue::return_code::return_value_error_not_ready;
563 std::lock_guard<std::recursive_mutex>
l(
p_cont->m_trf_mutex);
582 return ReturnValue::return_code::return_value_error_not_ready;
589 std::lock_guard<std::recursive_mutex>
l(
p_cont->m_trf_mutex);
595 for (
const auto&
id :
ids)
597 if (
it->src_frame_id ==
id) {
found =
true;
break; }
599 if (
found ==
false) {
600 ids.push_back(
it->src_frame_id);
607 for (
const auto&
id :
ids)
609 if (
it->dst_frame_id ==
id) {
found =
true;
break; }
611 if (
found ==
false) {
612 ids.push_back(
it->dst_frame_id);
624 return ReturnValue::return_code::return_value_error_not_ready;
631 std::lock_guard<std::recursive_mutex>
l(
p_cont->m_trf_mutex);
636 std::string
par(
it->dst_frame_id);
637 if (
it->dst_frame_id == frame_id)
643 return ReturnValue::return_code::return_value_error_method_failed;
653 std::lock_guard<std::recursive_mutex>
l(
p_cont->m_trf_mutex);
673 std::lock_guard<std::recursive_mutex>
l(
p_cont->m_trf_mutex);
682 transform =
it->toMatrix();
690 transform =
m *
it->toMatrix();
704 return ReturnValue::return_code::return_value_error_not_ready;
709 if (ct == ConnectionType::DIRECT)
718 return ReturnValue::return_code::return_value_error_method_failed;
721 else if (ct == ConnectionType::INVERSE)
728 else if(ct == ConnectionType::UNDIRECT)
736 else if (ct == ConnectionType::IDENTITY)
744 return ReturnValue::return_code::return_value_error_method_failed;
752 return ReturnValue::return_code::return_value_error_not_ready;
757 "\t Source frame and target frame are both equal to " <<
source_frame_id;
758 return ReturnValue::return_code::return_value_error_method_failed;
768 return ReturnValue::return_code::return_value_error_method_failed;
775 if (!
tf.fromMatrix(transform))
778 return ReturnValue::return_code::return_value_error_method_failed;
791 return ReturnValue::return_code::return_value_error_not_ready;
799 return ReturnValue::return_code::return_value_error_not_ready;
804 "\t Source frame and target frame are both equal to " <<
source_frame_id;
805 return ReturnValue::return_code::return_value_error_method_failed;
813 return ReturnValue::return_code::return_value_error_method_failed;
817 if (!
tf.fromMatrix(transform))
820 return ReturnValue::return_code::return_value_error_method_failed;
832 return ReturnValue::return_code::return_value_error_not_ready;
842 return ReturnValue::return_code::return_value_error_not_ready;
850 return ReturnValue::return_code::return_value_error_not_ready;
855 return ReturnValue::return_code::return_value_error_method_failed;
861 return ReturnValue::return_code::return_value_error_method_failed;
875 return ReturnValue::return_code::return_value_error_not_ready;
880 return ReturnValue::return_code::return_value_error_method_failed;
891 return ReturnValue::return_code::return_value_error_method_failed;
914 return ReturnValue::return_code::return_value_error_not_ready;
920 return ReturnValue::return_code::return_value_error_method_failed;
933 return ReturnValue::return_code::return_value_error_not_ready;
941 return ReturnValue::return_code::return_value_error_method_failed;
1007 return std::string(
",label=\" ") + t->
toString(FrameTransform::display_transform_mode_t::rotation_as_quaternion) +
"\"";
1011 return std::string(
",label=\" ") + t->
toString(FrameTransform::display_transform_mode_t::rotation_as_matrix) +
"\"";
1015 return std::string(
",label=\" ") + t->
toString(FrameTransform::display_transform_mode_t::rotation_as_rpy) +
"\"";
1037 std::lock_guard<std::recursive_mutex>
l(
p_cont->m_trf_mutex);
1045 std::string
trf_text =
it->src_frame_id +
"->" +
1046 it->dst_frame_id +
" " +
1051 std::string
legend =
"\n\
1053 node[shape=plaintext]\n\
1054 subgraph cluster_01 {\n\
1055 label = \"Legend\";\n\
1056 key[label=<<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" cellborder=\"0\">\n\
1057 <tr><td align=\"right\" port=\"i1\">YARP timed transform</td></tr>\n\
1058 <tr><td align=\"right\" port=\"i2\">YARP static transform</td></tr>\n\
1060 key2[label=<<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" cellborder=\"0\">\n\
1061 <tr><td port = \"i1\"> </td></tr>\n\
1062 <tr><td port = \"i2\"> </td></tr>\n\
1064 key:i1:e -> key2:i1:w [color = blue]\n\
1065 key:i2:e -> key2:i2:w [color = blue, style=dashed]\n\
1069#if defined (__linux__)
1070 int ret = std::system(
"dot -V");
constexpr yarp::conf::vocab32_t VOCAB_ERR
A simple collection of objects that can be described and transmitted in a portable way.
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
size_type size() const
Gets the number of elements in the bottle.
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
void clear()
Empties the bottle of any objects it contains.
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
A mini-server for performing network communication in the background.
An interface for reading from a network connection.
An interface for writing to a network connection.
static bool exists(const std::string &port, bool quiet=true, bool checkVer=true)
Check for a port to be ready and responsive.
An abstraction for a periodic thread.
void askToStop()
Stop the thread.
bool start()
Call this to start the thread.
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
void setReader(PortReader &reader) override
Set an external reader for port data.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
A class for storing options and configuration information.
Helper class for finding config files and other external resources.
A base class for nested structures that can be searched.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
static double nowSystem()
static void delaySystem(double seconds)
A single value (typically within a Bottle).
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual std::string asString() const
Get string value.
yarp::dev::PolyDriver * driver() const
bool hasParam(const std::string &name) const
bool hasDevice(const std::string &name) const
bool enterPhase(yarp::robotinterface::ActionPhase phase)
std::string findParam(const std::string &name) const
Device & device(const std::string &name)
Result of the parsing of yarp::robotinterface::XMLReader.
bool parsingIsSuccessful
True if the parsing was successful, false otherwise.
Robot robot
If parsingIsSuccessful is true, contains a valid robot instance.
Class to read an XML file.
XMLReaderResult getRobotFromString(const std::string &filename, const yarp::os::Searchable &config=yarp::os::Property())
Parse the XML description of a robotinterface from a string.
void push_back(const T &elem)
Push a new element in the vector: size is changed.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
#define yCErrorThrottle(component, period,...)
For streams capable of holding different kinds of content, check what they actually have.
yarp::sig::Matrix SE3inv(const yarp::sig::Matrix &H)
Returns the inverse of a 4 by 4 rototranslational matrix (defined in Math.h).
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface to the operating system, including Port based communication.