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

How to write to a file different parameters from different CallBacks with same timestamp?

asked 2013-12-18 19:16:47 -0500

Astronaut gravatar image

updated 2013-12-18 19:18:13 -0500

Hello

I would like to write to a text file different parameters obtained from different topics (scan, raw_imu, odom). I obtained some parameters in different CallBacks like scanCallback poseCallback, imuCallback. I would like to have those output parameters in on file but synchronized (with same frequency, like for example every 1 second.)

I know that can use the commands

myfile.open("/home/user/file.ttx");
myfile << "timestamp" << "....  "\n";

But I cant make it that all output parameters are written in same time stamp. Like for example

time in sec    parameter1   parameter2   parameter3
1                 value      value        value
2                 value      value        value
3                 value      value        value

I know that laser scaner and Imu publish with different frequencies.

Any help?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-12-18 21:44:50 -0500

timster gravatar image

You could try implementing one callback for all three messages using message_filters. You can either use an exact time policy if all topics are exactly in sync or an approximate time policy to allow small differences between their timestamps. An example and a more detailed description is given here:

http://wiki.ros.org/message_filters#Policy-Based_Synchronizer_.5BROS_1.1.2B-.5D

In the callback you could finally write the information you need from your three messages into one txt file.

Best

Tim

edit flag offensive delete link more

Comments

I cant implement one Callback as the ros topics are from different sensors( laser scan, Imu and Odom), So I need three Callbacks.Whats the option if I do not implement one Callback???

Astronaut gravatar image Astronaut  ( 2013-12-19 03:52:12 -0500 )edit

message_filters allow you to use one callback for multiple messages of any type, so it should not matter if the messages come from different sensors... Or did I miss something? Why do you think you have to use three callbacks?

timster gravatar image timster  ( 2014-01-01 20:15:05 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2013-12-18 19:16:47 -0500

Seen: 194 times

Last updated: Dec 18 '13