how to play bag files from c++ or python class
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']):
pub.publish(msg)
rate.sleep()
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/1446... ) 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/... )
Is there a better way?
EDIT:
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).