Rosanswers logo

At the moment I'm reading bag files and publishing back the results:

bag = rosbag.Bag('2017-09-04-16-11-56.bag')
rospy.init_node('talker', anonymous=True)
rate = rospy.Rate(0.5) # Not sure what this should be set to  
pub = rospy.Publisher('cmd_vel', Twist, queue_size=10)
for topic, msg, t in bag.read_messages(topics=['cmd_vel']): 

But this is not the same as playing back the data since it does not take into account the time difference between each message.

In this answer (https://answers.ros.org/question/144646/how-to-play-rosbag-file-from-node/) the poster included their solution which as far as I can tell, just publishes all the messages to a topic.

So now the only thing I can think of is to go look through the source code of the player.cpp and see how they are publishing rosbag messages at the same rate at which they were recorded (https://github.com/ros/ros_comm/blob/indigo-devel/tools/rosbag/src/player.cpp)

Is there a better way?


I'm trying to build a model of a real life differential drive robot in gazebo. I created a URDF which is just some simple shapes but think it should be accurate enough.

However it's difficult to figure out the right parameters that the URDF should have. For example, I don't know what the weight of the caster wheels are or how much torque is being applied to the front wheels. I can't take the robot apart and measure each component.

So my plan was to take the real robot outside for a test run and use rosbag to record all the commands being sent to it. Then use rosbag to playback all those commands on various different URDF models until I find one that accurately matches the behavior of the real robot (was hoping to use a genetic algorithm to find the best parameters).

Originally posted by Auton0mous on ROS Answers with karma: 38 on 2017-09-04

Post score: 0


2 Answers 2


Rosanswers logo

I would try calling rosbag play directly.

import subprocess
player_proc = subprocess.Popen(['rosbag', 'play', bag_filename, ... (other args)], cwd=bagfile_folder_path)

Originally posted by huanxiner with karma: 271 on 2017-09-06

This answer was ACCEPTED on the original site

Post score: 2

Original comments

Comment by Auton0mous on 2017-09-07:
Thanks, that saves me a lot of trouble. However I've noticed that the playbag is fairly inconsistent. I'm playing back a recording of a robot that drives around in a circle and returns to a spot but every time it returns to a different location. It's subscribed to the cmd_vel topic. Is this normal?

Comment by gvdhoorn on 2017-09-07:
Just to make sure we can avoid an xy-problem: can you update your original question with some more info on what it is that you are actually trying to do? It might be that you are expecting something to work which is not supposed to be used in that way.

Comment by Auton0mous on 2017-09-07:
Updated with explanation of what I'm trying to do. Again not sure if it's the best way to go about it but don't know of any other way. I've already tried to manually tweak the parameters but it's a pretty tedious task.

Comment by gvdhoorn on 2017-09-07:
Your approach is ok - I don't know how successful it will be though. I'm guessing you're going to use the other topics to compare performance?

Note that a simulation will never be like the real thing, as simulators are always limited.


Rosanswers logo

Instead of running rosbag as a subprocess as @huanxiner suggests, perhaps you'd want to take a look at osrf/nodelet_rosbag.

That exposes an Action interface which lets you control a rosbag-like node with an action client.

Doing it that way would be a bit more 'the ROS way'.

Originally posted by gvdhoorn with karma: 86574 on 2017-09-07

This answer was NOT ACCEPTED on the original site

Post score: 1


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.