Getting Started¶
Prerequisites¶
- Python 3.10+
- ROS2 environment (Humble / Jazzy)
Installation¶
From PyPI¶
From source¶
Basic usage¶
Load a rosbag¶
import baglab
bag = baglab.load("path/to/rosbag")
print(bag.topics)
# {"/motor/angle": "sensor_msgs/msg/JointState", ...}
Access topic data¶
Topic data is loaded lazily — only when you access it:
Dot-access for message fields¶
twist_df.msg.twist.linear.x # pandas Series
twist_df.msg.twist.linear.df # DataFrame with columns [x, y, z]
Timestamps¶
t = baglab.stamp_to_sec(twist_df) # absolute time [s]
t = baglab.stamp_to_sec(twist_df, relative=True) # relative time (starts at 0)
Reindex by stamp¶
Time slicing¶
Plot example¶
import baglab
import matplotlib.pyplot as plt
bag = baglab.load("path/to/rosbag")
twist_df = bag["/cmd_vel"]
t = baglab.stamp_to_sec(twist_df, relative=True)
vel = twist_df.msg.twist.linear.df
fig, axes = plt.subplots(3, 1, sharex=True)
for ax, axis_name in zip(axes, ["x", "y", "z"]):
ax.plot(t, vel[axis_name])
ax.set_ylabel(axis_name)
axes[-1].set_xlabel("time [s]")
plt.show()