-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimu_to_bag.py
30 lines (24 loc) · 1.01 KB
/
imu_to_bag.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import pandas as pd
df = pd.read_csv('output.csv')
import rospy
import rosbag
from sensor_msgs.msg import Imu, NavSatFix
with rosbag.Bag('output.bag', 'w') as bag:
for row in range(df.shape[0]):
t = df['gps_timeofweek'][row] + df['gps_week'][row]*604800
timestamp = rospy.Time.from_sec(t)
imu_msg = Imu()
imu_msg.header.stamp = timestamp
# Populate the data elements for IMU
# e.g. imu_msg.angular_velocity.x = df['a_v_x'][row]
imu_msg.linear_acceleration.x = df['x_acc'][row]
imu_msg.linear_acceleration.y = df['y_acc'][row]
imu_msg.linear_acceleration.z = df['z_acc'][row]
imu_msg.angular_velocity.x = df['x_gyro'][row]
imu_msg.angular_velocity.y = df['y_gyro'][row]
imu_msg.angular_velocity.z = df['z_gyro'][row]
bag.write("/imu", imu_msg, timestamp)
# gps_msg = NavSatFix()
# gps_msg.header.stamp = timestamp
# # Populate the data elements for GPS
# bag.write("/gps", gpu_msg, timestamp)