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

How to subscribe in a topic from bagfile?

asked Aug 22 '22

joantmor gravatar image

Hello guys, I'm newbie on ROS and I've trained with exercises, but I don't know how to subscribe in a topic from a bagfile, because the only hint and file attached of this exercise is a bagfile. I can read with the library bagpy and panda, but the order says the next: "Create a code to subscribe to the topic /lineal/velocity.". I'm using google colab with the library roslab to run the bagfile.

I'm really grateful with your answers. Best Regardings.

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
0

answered Aug 23 '22

ravijoshi gravatar image

updated Aug 23 '22

Subscribing a topic from a bag file is the same as subscribing to a ROS topic.

In one terminal, please play your bag file as shown below:

rosbag play file.bag

Please see the wiki page for more info on the rosbag play command. Next, in another terminal, please subscribe to your recorded topic. Again, please see the wiki page on how to write a subscriber.


By the way, are you trying to extract messages from a bag file? If yes, I recommend you look at the rosbag/Code API page.

Preview: (hide)
0

answered Aug 23 '22

bc524 gravatar image

http://wiki.ros.org/ROS/Tutorials/Wri...

This tutorial breaks down a bit on how topics are shared between a publishing source and a receiving subscriber.

It's the same thing when trying to subscribe a topic from a bagfile. Only this time, your publisher is the bagfile being played. As long as you reference the correct topic you're trying to subscribe to, you will be able to extract it.

To play the bagfiles, you can use:

rosbag play filename.bag

This will playback the bag file and publish all the topics recorded within the file. If you only want specific topics to be published, you can use:

rosbag play filename.bag --topics /topic1 /topic2 /topicEtc
Preview: (hide)

Question Tools

1 follower

Stats

Asked: Aug 22 '22

Seen: 871 times

Last updated: Aug 23 '22