Define time in synthetic rosbag
I am creating a rosbag from a csv file. I am using the python api. My question is how can I set the time information in the bag with which it will be player back. the relevant parts of my current code look like this:
import os
import rosbag
import rospy
from nav_msgs.msg import Odometry
import numpy as np
try:
file = os.path.expanduser('test.csv')
# Get data from text file(s)
data = np.genfromtxt(file, delimiter=',', skip_header=0, skip_footer=0, names=True)
bag = rosbag.Bag('test.bag', 'w')
time = data['Nano_from_start_of_regions']
time = time - time[0]
v_x = data['Velocity_forwardms']
v_y = data['Velocity_lateralms']
v_z = data['Velocity_downms']
odom = Odometry()
time = np.array(time)
sec_time = time.astype(int)
nsec_time = (time-sec_time)*10e8
nsec_time = np.array(nsec_time)
nsec_time = nsec_time.astype(int)
for i in range(len(time)):
odom.header.frame_id = 'odom'
odom.child_frame_id = 'base_link'
odom.header.stamp.secs = sec_time[i]
odom.header.stamp.nsecs= nsec_time[i]
odom.twist.twist.linear.x = v_x[i]
odom.twist.twist.linear.y = v_y[i]
odom.twist.twist.linear.z = v_z[i]
bag.write('odom',odom)
finally:
bag.close()
how ever the time in the header doesnt seem to have an influence on the bag. its just saves it as fast as possible and replays at the same speed. How could I change that speed? Clock topic?