ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Question on topic publication

asked 2014-03-19 21:44:32 -0500

Maya gravatar image

updated 2014-03-19 21:47:58 -0500

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.

edit retag flag offensive close merge delete

Comments

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.

Hamid Didari gravatar image Hamid Didari  ( 2014-03-19 22:23:04 -0500 )edit

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.

Maya gravatar image Maya  ( 2014-03-19 22:32:39 -0500 )edit

1 Answer

Sort by » oldest newest most voted
4

answered 2014-03-19 23:59:40 -0500

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.

edit flag offensive delete link more

Comments

That's what I was searching about. The timer and time stamp technique seems perfect.

Maya gravatar image Maya  ( 2014-03-20 00:24:34 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2014-03-19 21:44:32 -0500

Seen: 256 times

Last updated: Mar 19 '14