How to change a urdf model property using a roscpp node
Hi, I am trying to change the color of a part in a URDF model that is visualized in RVIZZ whenever a contact occurs. I have already written a roscpp node that detects the contact at the previously mentioned part but I want this node to change the color property of this part in the URDF file in live mode. I tried using a ros server parameter for the color but I didn't know how access its value in the URDF file. It would be really appreciated if someone can tell me how to properly do this. Thanks!
Quick comment: it's certainly possible to load the
robot_description
parameter, parse it using something like urdfdom, change a property of some entity.However, what is less than trivial is getting consumers of
robot_description
to reload that parameter. Updating parameter values at runtime is not a pattern that's often used: parameters are only read once during initialisation. For parameters changing at runtime you'd use dynamic_reconfigure, but that's not often (at all?) used forrobot_description
.If you can control your consumers of
robot_description
, you could force them to reload that parameter, but that's non-trivial again.I would suggest to take a look at how MoveIt implements this, using its special MoveIt RViz plugin. You'll see it doesn't change the URDF, but only the way it renders it inside RViz.
I agree with @gvdhoorn that changing the urdf is not a good way to do this. In addition to the plugin he pointed you to, take a look a the rviz Marker feature. It may not be as pretty, but it'll take much less code to implement.