Making Maps

Note: These instructions assume you have installed Google Cartographer according to these installation instructions.

Running off of live data

Running live is nice is that all happens all at once, but it can be laggy, and it can become messy if you wish to restart the process.

  1. If you haven't already, make a folder to store maps. We recommend making it in the home directory mkdir ~/mapfiles.
  2. Run teleop.
  3. In another car's terminal, run source ~/cartographer_ws/devel_isolated/setup.bash, then roslaunch cartographer_ros racecar_2d.launch to start making the map.

  4. If you forget to source the setup file, you will get an error like: "No such file or directory: /home/racecar/cartographer_ws/install_isolated/share/racecar_description/urdf/racecar.xacro..."

  5. If you get another error along the lines of "RLException: [racecar_2d.launch] is neither a launch file in package [cartographer_ros] nor is [cartographer_ros] a launch file name", try cd-ing into "~/cartographer_ws" and running catkin_make_isolated --install --use-ninja.

  6. Run rviz, and add the "\map" topic if it's not there already.

  7. Do this in Docker (make sure you ran it with the car number argument), or on your Ubuntu machine (with ROS installed), or on the car itself (if you have a monitor).
  8. If you are making a map with a rosbag, be warned that you will not see any map until you start playing the rosbag.
  9. To add a topic, click the "Add" button.

    Then go to the, "By Topic" tab, and add the topic you are interested in.

  10. Also, rviz can be finicky at times. If nothing appears even after running teleop or playing the rosbag, try changing the "Fixed Frame" to "map". Then check and uncheck the the checkboxes for the topics you are interested in. If that didn't work, try re-running Rviz. Check that you are running the programs you need to run.
  11. Drive the car around the area you wish to map out. Try to drive in closed loops when possible.
  12. When you are satisfied with your map, keep cartographer running. To save the map, run rosrun map_server map_saver -f ~/mapfiles/<your_map_name>
  13. Now you may kill cartographer.

Running off of a rosbag

Rosbags are nice in that they allow you to isolate data collection from data processing.

Recording the rosbag.

  1. If you haven't already, make a folder to store rosbags. We recommend making it in the home directory mkdir ~/bagfiles.
  2. Place the car in a good starting position.
  3. In a car's terminal, run teleop.
  4. cd into your rosbag folder and run rosbag record -a -o <your_rosbag_name> to start recording data on all the topics.
  5. Drive the car around the area you wish to map out. Try to drive in closed loops when possible.
  6. When you are satisfied with your data collection (try to shoot for a minute or two of good data), kill the rosbag to stop recording. It may take a few seconds to stop, so let it die in peace.
  7. (optional) The bagfile naming system is kinda gross. Use an mv command to rename your bag file to something pretty. If you don't know what we mean by that, Google (and by that I mean DuckDuckGo or Ecosia) "renaming files in terminal".

Creating the map

To get a .pgm file and a .yaml file (this is what our particle filter uses):
Follow the same instructions as for running off of live data, but in step 2, instead of running teleop, run roscore, and in step 6, instead of driving the car around, run rosbag play ~/bagfiles/<your_rosbag_name>.bag. Save the map when the rosbag stops playing. (You'll know it is done when it prints "Done." in the terminal).
Note: Remember to kill teleop! If you don't kill teleop, cartographer will see the rosbag data and current data at the same time! Plus, since the -a flag passed to rosbag record means record everything, playing the rosbag plays drive command data!

Alternatively, to get a .pbstream file (not recommended; this is usually for further use within Google Cartographer): 1. Run roslaunch cartographer_ros offline_racecar_2d.launch bag_filenames:=${HOME}/bagfiles/<your_rosbag_name>.bag
  Warning: this will pull up an rviz window. If you're ssh-ed in, then whoops.
2. Wait for the bag to finish playing, then watch the terminal and wait until it's done "optimizing".