Print subset of message
I would like to programmatically print a subset of this message, specifically only the flags set to true. I have found only this question regarding the display of messages, and the answer suggests to use ros::message_traits::Definition<franka_msgs::Errors>::value()
which, in this case is a method which returns a long string made like this:
return "bool joint_position_limits_violation\n\
bool cartesian_position_limits_violation\n\
...
";
Is storing this string and parsing it the only way I can get the names of the errors to use in a for loop that checks which flags are true? Is there no way to get the name of the single error from the message itself?
You could take a look at ros_type_introspection.
Afaik there is no OotB support for this, but that library tries to fill that gap.
If you know the message (thus all the fields) maybe you could compare each field in the callback and only print if true like that :
What @Delb suggests is certainly an approach for this specific message.
I took the question by @aPonza to be a bit more general in which case hard-coding wouldn't be feasible.
If you are still intereste to know the answer, I can write an example for you (I am the author of ros_type_introspection).
I am, I was looking at this question again exactly yesterday to do another similar thing to a message and couldn't remember the name of your package, but in the end delayed the task in favour of another.