Recording and Playing Back Data

From Lofaro Lab Wiki
Jump to: navigation, search

Close all previous terminals

1) In a terminal run the core:

roscore

2) In a new terminal (terminal 2) run the turtle simulator:

rosrun turtlesim turtlesim_node

This will bring up a new window with our turtle on it.

3) In a new terminal (terminal 3) run the turtle key controller:

rosrun turtlesim turtle_teleop_key

4) In a new terminal (terminal 4) let us look at the list of topics being published:

rostopic list -v

This is a list of all possible topics that can be recorded to a file.

5) In terminal 4, type in the following to create a new bagfile folder and move into it:

mkdir ~/bagfiles
cd ~/bagfiles

6) In terminal 4, start recording all topics of the simulator:

rosbag record -a

7) Click on the terminal that is running the key controller. Press the arrow keys and watch the turtle move around on the simulator for about 10 seconds.

8) In terminal 4, press ctrl+C to stop the recording. You can also effectively kill the process by closing this terminal.

9) Using Home Folder, navigate to Home/bagfiles. You will see a .bag file inside that has a long numeric name. This name is your bagfile name. (Ex. 2014-10-22-11-32-49.bag)

10) In terminal 4 (or a new terminal if it was killed) navigate to your bagfiles folder:

cd ~/bagfiles

11) View the information of your bag file:

rosbag info <your bagfile name> 

This will print to the terminal some information including bag, version start time, end time, etc.

12) Close terminal 3, the one with the key controller.

13) In terminal 4, allow the information of the bag file to be played back.

rosbag play <your bagfile>

Monitor the simulator with the turtle. After a few second, the turtle will start to move. The play command re-simulates the information that was captured by the recorded bag file.

Recording a Subset of Data Close all previous terminals

1) In a terminal run the core:

roscore

2) In a new terminal (terminal 2) run the turtle simulator:

rosrun turtlesim turtlesim_node

This will bring up a new window with our turtle on it.

3) In a new terminal (terminal 3) run the turtle key controller:

rosrun turtlesim turtle_teleop_key

4) In a new terminal (terminal 4) move into the bagfiles folder:

cd ~/bagfiles

5) In terminal 4, record only the topics pose and velocity (the list of possible topics can be viewed by using rostopic list -v like earlier).

rosbag record -O subset /turtle1/command_velocity /turtle1/pose

This creates a bagfile called subset.bag

6) Click on terminal 3 and move the turtle around for a few seconds.

7) In terminal 4 press ctrl+C to terminate the recording.

8) In terminal 4 view the bag file information:

rosbag info subset.bag

Note that this file only has two topics recorded rather than four like the original bag file.