ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
If you want the last message on a topic to be "remembered" and getting sent to new subscribers, latching a topic provides that capability.
To keep track of when messages arrive, you can update a "last_received" timestamp inside the topic callback (for example your "cmd_vel" callback). This way, your node always knows when the last message arrived. You can then have a Timer running and in it´s callback check if the "last_received" timestamp is within a tolerance threshold of current time. If it is not, you send a motor stop command. That´s one way of doing things. You could also use Threads, but using Timers and callbacks appears easier.