def csv2rosbag(csvPath, outputBag): """ Creates a ROS bag file from a CSV file. In this script, only the time and altitude informations written into the ROS bag. """ log = pd.read_csv(csvPath) try: with rosbag.Bag(outputBag, 'w') as bag: for row in range(log.shape[0]): # Populate the data elements for time in seconds timestamp = rospy.Time.from_sec(log['Time(seconds)'][row]) altitude_msg = Altitude() altitude_msg.header.stamp = timestamp # Populate the data elements for altitude in meters # e.g. altitude_msg.relative = df['Relative'][row] altitude_msg.local = log['Altitude(meters)'][row] bag.write(TOPIC, altitude_msg, timestamp) print(bag) except: print("Error: Unable to open CSV file!") sys.exit() finally: bag.close()
def csv2rosbag(csvFile, outputFile): log = pd.read_csv(csvFile) try: with rosbag.Bag(outputFile, 'w') as bag: for row in range(log.shape[0]): timestamp = rospy.Time.from_sec(log['Time(seconds)'][row]) altitude_msg = Altitude() altitude_msg.header.stamp = timestamp altitude_msg.local = (log['Altitude(meters)'][row]) # Populate the data elements for IMU # e.g. imu_msg.angular_velocity.x = df['a_v_x'][row] bag.write(TOPIC, altitude_msg, timestamp) print(bag) finally: bag.close()