how to print name of elements of ros message
Hey, I would like to print the elements of ros messages dynamically, with a function similar to:
template <typename M>
void printElements()const{
const boost::shared_ptr<M> msgPtr;
/*
Extract element table
cout<< how can I access the name of the elements here?<<endl;
*/
};
How can I extract the message elements so that when I execute
<geometry_msgs::PoseStamped>printElements();
,I get for the example of a "geometry_msgs/PoseStamped" Message:
pose.header.sec
pose.header.nsec
pose.position.x
pose.position.x
pose.position.x
pose.orientation.x
pose.orientation.y
pose.orientation.z
pose.orientation.w
Do you have an idea how I can dynamically access the name, e.g. "pose.position.x","pose.position.y","pose.position.z", etc. For other message type, the printout shall be accordingly. Thank you very much for any ideas of solving this issue!
Do you need it in C++? This is probably going to be a bit involved, possibly including parsing the created header files. It would be much easier in python as python objects still contain the variable names.
Thanks a lot. Yes unfortunately I need it in c++. That's not good news. I thought that roscpp makes the variable names somewhere accessible. Thank you very much.