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

How to play and pause bagfile within the program?

asked 2017-01-07 11:34:28 -0600

baozhang gravatar image

Hello.

I would like to play and pause bagfile by joypad.

When I type "rosbag play example.bag" in a ternimal, example.bag is played and when I press space key, the bagfile is paused.

I could play example.bag within the program, however, couldn't pause it.

Will you please tell me how to do it or are there other ways to realize it?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
2

answered 2019-09-20 05:59:45 -0600

Christian Rauch gravatar image

The rosbag player provides a pause_playback service of type std_srvs/SetBool.

Since the play will be started as anonymous node, the service will be available as /play_<unique_number>/pause_playback.

To pause the playback, call the service with data: true:

rosservice call /play_<unique_number>/pause_playback "data: true" 
success: True
message: "Playback is now paused"

and to un-pause, with data: false:

rosservice call /play_<unique_number>/pause_playback "data: false" 
success: True
message: "Playback is now resumed"
edit flag offensive delete link more

Comments

rosrun my_package node_executable __name:=my_node1 set a user namespace

jxl gravatar image jxl  ( 2019-12-27 00:17:06 -0600 )edit
0

answered 2018-06-05 15:54:09 -0600

malharjajoo gravatar image

Hi,

I'm in a similar scenario, where I have recorded a ROS Bag and then want to use it but want to stop at some selected images, do some processing, then only proceed. Sadly, I don't see a way using ROS.

But you can do this -

  1. Play the ROS bag.
  2. convert it to a video using ROS video_recorder ( See this )
  3. Change your program (using something like openCV) to open the video file and using something like cv::waitKey(0) to pause the video from within your program.

Hope this helps.

edit flag offensive delete link more
0

answered 2018-06-05 16:06:11 -0600

You can do this using the rosbag API but it's not the easiest thing in the world, there are a range of examples here. If you back file only contains one or a small number of topics then you can hard code those in.

The rosbag API allows you to open the bag file view it's contents and extract messages in whatever order you want. Using this could you could create your own playback node which can play, pause and rewind. Alternatively you could play the bag file back in non-real time, so you could spend as long as you want processing a message without missing any of the following messages.

Hope this helps.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-01-07 11:34:28 -0600

Seen: 2,780 times

Last updated: Sep 20 '19