Ask Your Question
0

rosserial: How do I make a subscriber read the newest message of a topic?

asked 2016-11-15 02:34:07 -0600

Matthew Kleinsmith gravatar image

updated 2016-11-16 02:38:52 -0600

How do I make a rosserial_arduino-based subscriber read the newest message of a topic? (Edit: By "newest message" I mean the message that was published most recently.)

I tried to set the queue size of the subscriber to 1, but I couldn't find the string "queue" in the ros_lib Arduino files; and so I believe it's not a feature of rosserial_arduino.

Here's an example of a rosserial_arduino subscriber from a rosserial_arduino tutorial:

ros::Subscriber<std_msgs::Empty> sub("toggle_led", &messageCb );

void setup()
{
  pinMode(13, OUTPUT);
  nh.initNode();
  nh.subscribe(sub);
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-11-15 06:22:36 -0600

codenotes gravatar image

While I am not familiar with the arduino variant of ROS, It sounds like you are thinking of a ROS subscriber as a queue that you manually pull from. It may be that internally..but it exposes a callback mechanism that you are to use. Internally there is, I think, a circular buffer you could possibly access, but this is not commonly done.

I may not fully understand what you mean by "newest" message. If you mean, the message that your client application receives in its callback as a result of calling spinOnce, well then you are already getting the "newest"...your client (at least on normal ROS) has, if I remember correctly, a circular buffer that enqueues messages it receives FIFO style; if you don't process those messages at the front thenI believe they are pushed into oblivion once new messages come in from the rear in order to maintain the fixed size of the queue. That said, I don't believe we have threads on arduino, so I would guess you have to be calling that spinOnce() call at a greater frequency than the messages are coming in...otherwise I think you could have stale or old messages in your queue because I don't believe ROS on Arduino could update that queue otherwise.

In short, I think if you are processing messages on the client (calling spinonce) at a faster rate then they are coming in, and with a small queue, you should always get the "newest". You might also create a local buffer that queues all messages and then you can do whatever you like with them...pull from the tail, front, etc.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2016-11-15 02:34:07 -0600

Seen: 698 times

Last updated: Nov 16 '16