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

[SOLVED] How to publish two synchronized messages?

asked 2016-12-16 10:00:51 -0600

ManMan88 gravatar image

updated 2016-12-16 11:51:20 -0600

Hi,

I build a robot which has two encoders. I want the encoders to publish their count at the exact same time.

Right now, the subscriber node is using the ApproximateTimeSynchronizer, since with the TimeSynchronizer I get nothing (as expected).

So, my question is, is there a way to publish the 2 messages at the exact same time? I'm looking for a code solution. (I build the robot using BBB, I'm not in a lab and I dont have signal generators, etc,.)

Thanks for the help, Ron

edit retag flag offensive close merge delete

Comments

Not sure I completely understand the question, are the encoders both being published by the BeagleBone Black? (I take it that's what BBB stands for) Can you put them both in one message?

rbbg gravatar image rbbg  ( 2016-12-16 11:14:08 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted
1

answered 2016-12-16 11:22:11 -0600

lucasw gravatar image

Assuming your encoder messages have headers with time stamps, it doesn't really matter if the messages are actually published at the same time as long as the time stamp field is set to the same value for each. The exact TimeSynchronizer will consider them to have happened at the same time provided they aren't received too far apart in time.

Alternatively publish the two encoders in a single message with two fields and skip the synchronizer subscriber.

If the encoders aren't in fact being captured at the same time at the hardware level then it is questionable to force the synchronization, you'd rather timestamp them as accurately as possible. If your encoders later get turned into for example angles that are reflected in the tf tree you could use the tf interpolation to get reasonable intermediate angles that are decently accurate for a certain instant in time.

edit flag offensive delete link more
1

answered 2016-12-16 11:19:28 -0600

ahendrix gravatar image

The simple answer here is that the TimeSynchronizer expects messages to have the same timestamp, so you should publish both messages using the exact same timestamp in the header.

The better answer here is that, unless you really need these encoder values separately later, it's probably better to publish both of them in the same message. If you describe how you're capturing encoder data and what you're doing with this encoder data we might be able to give you better advice.

edit flag offensive delete link more
0

answered 2016-12-16 11:49:41 -0600

ManMan88 gravatar image

updated 2017-11-07 06:27:15 -0600

Thank you all for the answers. I guess I'll just publish both encoders in the same message. Actually that is what I was doing in my original code :o

I'm new to ROS and for some reason I thought it would be more professional to divide all the sensors to different nodes. I think there was another reason I wanted to do it which I don't remember now. I started separating them and then I figured out I have the problem of the synchronization.

So I'll go back to the original method.

Thanks again!

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2016-12-16 10:00:51 -0600

Seen: 1,673 times

Last updated: Nov 07 '17