ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

How to read ros2 bag file in a node

asked 2022-06-28 13:32:55 -0600

Flash gravatar image

updated 2022-06-28 13:49:49 -0600

Hi,
I was wondering is there a better method to read ros2 bag files inside the ros2 node, I just want to send a command to run the bag files.
The only source I found is this but this requires me to include this package in my workspace, which I am trying to avoid it or might be I am not importing that library properly. I assume there might be a better solution that can help me to do this.
Thanks in advance

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-07-21 11:10:16 -0600

Flash gravatar image

Hi, Just in case anyone wondering how to solve this there is one non-ROS method. I used the subprocess package from python to do that.

import subprocess
process = subprocess.Popen(['/bin/sh', '-c', 'ros2 bag play '+bag_file_path+'/'])
process.communicate()
process.terminate()

this way I send a command to the terminal which will run a bag file and on another end my ROS topic will read it.
This is not the best way I assume but it's the least coding way I was able to do it. But still, if anyone has a better solution or ROS solution please let me know.
Just to give a background about the problem I am running thetest node which subscribes to topics and then does some testing on that data. For that, I need the sensor data that I can either read from hardware or from the bag file.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-06-28 13:32:55 -0600

Seen: 470 times

Last updated: Jul 21 '22