0
$\begingroup$

Rosanswers logo

I'm trying to create some sort of base_controller for my motors in C++. I have two question about topics that I cannot answer for now.

First, if I read a message on the cmd_vel topic for example using a subscriber does the message I just read "disappeared" from the topic. Meaning if another Node try to read it, is the previously read message "gone" ?

Second, depending on the answer to the first question, how can I know if their is a steady stream of command coming from the cmd_vel topic ? Meaning if the message is erased when I read it how can I know that it was not 'outdated" or when to stop ? If it is not erase by reading but rather by if their more new information, how can two node send data on the same topic ?

To try to be clearer here is a situation example :

Let's say I publish a Twist for my robot to go forward on the cmd_vel for 3 second and I publish no stop Twist after those 3 seconds.

  • What is my subscriber to this topic going to read during the 3 first second and after ?
  • Same question but what if my subscriber is a little bit slow and start reading 1 second after I start publishing the twists ?

Thanks a lot.


Originally posted by Maya on ROS Answers with karma: 1172 on 2014-03-19

Post score: 1


Original comments

Comment by Hamid Didari on 2014-03-19:
when you publish a msg on a topic you give it an buffer to keep how many msgs in buffer and when you want to subscribe a msg you give it another buffer to keep how many msg in buffer. if you want to have two subscriber in one topic you can use header to separate msgs.

Comment by Maya on 2014-03-19:
If I publish one message, then I read it with my subscriber how can I know that there is no more input in the topic ? My question is more oriented at understanding how for example, turtlebot is able to know that the input is not steady.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Stefan Kohlbrecher with karma: 24361 on 2014-03-19

This answer was ACCEPTED on the original site

Post score: 4


Original comments

Comment by Maya on 2014-03-20:
That's what I was searching about. The timer and time stamp technique seems perfect.

$\endgroup$