SW/ROS
[humble]Recording and playing back data
Fun with x
2024. 3. 19. 22:59
ros2 run turtlesim turtlesim_node
ros2 run turtlesim turtle_teleop_key
ros2 topic list
/parameter_events
/rosout
/turtle1/cmd_vel
/turtle1/color_sensor
/turtle1/pose
ros2 topic echo /turtle1/cmd_vel
linear:
x: 2.0
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 0.0
---
ros2 bag record
#ros2 bag record <topic_name>
ros2 bag record /turtle1/cmd_vel
Record multiple topics
#
ros2 bag record -o subset /turtle1/cmd_vel /turtle1/pose
#
ros2 bag info
#ros2 bag info <bag_file_name>
ros2 bag info subset
#
ros2 bag play
#
ros2 bag play subset
Rosbag Read..........ddshoagbtlqk
from rosbags.rosbag2 import Reader
from rosbags.typesys import Stores, get_typestore
# Create a typestore and get the string class.
typestore = get_typestore(Stores.LATEST)
# Create reader instance and open for reading.
with Reader('subset') as reader:
# Topic and msgtype information is available on .connections list.
for connection in reader.connections:
print(connection.topic, connection.msgtype)
# Iterate over messages.
for connection, timestamp, rawdata in reader.messages():
if connection.topic == '/turtle1/cmd_vel':
msg = typestore.deserialize_cdr(rawdata, connection.msgtype)
print(msg.header.frame_id)
# The .messages() method accepts connection filters.
connections = [x for x in reader.connections if x.topic == '/turtle1/cmd_pose']
for connection, timestamp, rawdata in reader.messages(connections=connections):
msg = typestore.deserialize_cdr(rawdata, connection.msgtype)
print(msg.header.frame_id)