Skip to content

Working with ROS bag files can be a bit tricky. This guide lays out the tools in CRS to work with ROS bags.

The following are instructions on how to play parts (or all) of a ROS bag, allowing for testing ROS nodes on data recorded in a previous simulation or hardware experiment.

Rosbag Docs

Check out the rosbag package documentation, especially the Commandline section, for more information on how to work with rosbags.

Replaying a ROS bag file

  1. Add your .bag file to the bags folder. Create a new experiment in the experiments folder and include all of the config files from your ROS bag file (estimator.yaml, controller.yaml, etc.).

  2. Determine the topics to publish from the ROS bag.

rosbag info bags/<bagname>.bag
  1. Check out the bags/play.sh script. This script allows you to set the topics you wish to use from the rosbag. Note that $2 refers to namespace of the, e.g., car used during the experiment. This will be set in the terminal when running the script. $1 refers to the bag name you wish to use, and will also be set in the terminal when running the script.

  2. Start a ROS master in a terminal attached to the container.

roscore
  1. In a second, also attached, terminal, make ROS use the time published from the bag.
rosparam set use_sim_time true
  1. Run the script by navigating to the bags folder and execute

./play.sh <bag_name> <namespace>
This will start the bag but immediately pause it. By pressing the space bar you can play and pause the bag.
E.g: ./play.sh myBag.bag car1

  1. In a new terminal attached to the container, run the experiment.
roslaunch crs_launch run_single_bag.launch experiment_name:=<experiment_name>

For example, set namespace:=car1 and experiment_name:=myBagExperiment.

  1. Play around with the simulation. If you wish to make changes to, e.g., the estimator, you will need to change the .yaml file in your newly created experiment. By pressing the space bar the simulation will pause/resume.

CLI Car Plotter

You can use the bags/car_plotter.py to visualize the trajectories of the car from a rosbag. Usage (assuming your located in the bags folder):

python3 car_plotter.py -h

for all the info. TLDR:

python3 car_plotter.py -f <your_bag_file.bag> -t </YOUR_NAMESPACE/your_car_topic> -s

The functions should be relatively self contained and embeddable in your own custom script if you need custom plots with custom layouts (for reports, papers, etc.).