Your goal in this project is to gain in-depth knowledge and experience with solving problem of robot localization using the particle filter algorithm. This problem set is designed to give you the opportunity to learn about probabilistic approaches within robotics and to continue to grow your skills in robot programming. Like before, If you have any questions about this project or find yourself getting stuck, please post on the course Slack or send a Slack DM to the teaching team. Even if you don't find yourself hitting roadblocks, feel free to share with your peers what's working well for you.
You are expected to work with 1 other student for this project. Your project partner may be in a different lab section than you, however, both of you are expected to attend the same lab section for the next 2 weeks while you're working on this project. If you and your partner cannot attend the same lab section due to schedule conflicts, you will need to find a different partner. If you strongly prefer working by yourself, please reach out to the teaching team to discuss your individual case. A team of 3 will only be allowed if there is an odd number of students. Your team will submit your code and writeup together (in 1 Github repo).
Selecting a partner: You can either choose your own partner, or you can can post in the #find-project-partner Slack channel that you're looking for a partner, and find someone else who's also looking for a partner.
Like last project, you'll submit this project using Github Classroom (both the code and the writeup). Both partners will contribute to the same github repo.
Please put your implementation plan within your README.md
file. Your implementation plan should
contain the following:
initialize_particle_cloud
)?update_particles_with_motion_model
)?update_particle_weights_with_measurement_model
)?normalize_particles
) and resample
the particles (resample_particles
)?update_estimated_robot_pose
)?
Like last project, please modify the README.md
file as your writeup for this project. Please add
pictures, Youtube videos, and/or embedded animated gifs to showcase and describe your work. Your writeup should:
Use our Github Classroom to access the starter git repo particle_filter_project
(here's a direct link to the starter repo), putting it within your ~/catkin_ws/src/
directory. The starter git repo / ROS package contains the following files:
particle_filter_project/gazebo_custom_meshes/turtlebot3_maze.dae
particle_filter_project/launch/navigate_to_goal.launch
particle_filter_project/launch/turtlebot3_maze.launch
particle_filter_project/launch/visualize_particle.launch
particle_filter_project/rviz/particle_filter_project_v2.rviz
particle_filter_project/scripts/particle_filter.py
particle_filter_project/worlds/turtlebot3_maze.world
particle_filter_project/CMakeLists.txt
particle_filter_project/package.xml
particle_filter_project/README.md
In addition to these files, you'll also create your own map of the maze, and store those files in a
map
folder in your particle_filter_project
ROS package:
particle_filter_project/map/maze_map.pgm
particle_filter_project/map/maze_map.yaml
You will write your code within the particle_filter.py
file we've provided. You may also create other
python scripts that may provide helper functions for the main steps of the particle filter localization contained
within particle_filter.py
.
Please remember that when grading your code, we'll be looking for:
At the beginning or end of your writeup please include a gif or embedded video (e.g., mp4) of one of your most successful particle filter localization runs. In your gif/video, (at minimum) please show what's happening in your rviz window. We should see the particles in your particle filter localization (visualized in rviz) converging on the actual location of the robot.
Note that, unfortunately, there are no recording options directly on rviz. We recommend that you record your RViz window directly from your base OS or within the Ubuntu VM.
If you are on MacOS, QuickTimePlayer would be a great out-of-the-box option for screen recording. On Windows, a few options work great such as OBS Studio, or the Windows 10 builtin Game bar. On Ubuntu, one option would be Simple Screen Recorder. Another quicker option is to record the whole screen using Ctrl+Shift+Alt+R to both start and stop a screen recording.
Record a run of your particle filter localization in a rosbag. Please record the following topics:
/map
, /scan
, /cmd_vel
, /particle_cloud
,
/estimated_robot_pose
, and any other topics you generate and use in your particle filter localization
project. Please do not record all of the topics, since the camera topics make the rosbags very large. For
ease of use, here's how to record a rosbag:
$ rosbag record -O filename.bag topic-names
Please refer to the ROS Resources page for further details on how to record
a rosbag.
The final deliverable is ensuring that each team member completes this Partner Contributions Google Survey. The purpose of this survey is to accurately capture the contributions of each partner to your combined particle filter localization project deliverables.
The Partile Filter Project will be graded as follows:
New to this project is the Individual Contribution grade. This will be assessed through your responses to the partner contributions survey. Your grade will reflect how much you contributed to your team's project.
initialize_particle_cloud()
and update_particles_with_motion_model()
. When we run your code, we should see the particles initalized within the boundaries of your map and when the robot moves, we expect to see your particles moving in the same way.As was true with the warmup project, you will use Gradescope to submit your particle filter project deliverables. As a reminder:
When testing and running your particle filter code, you'll have the following commands running in different terminals or terminal tabs.
When you're ready to test your particle filter code on a physical robot, run the following commands.
First terminal: run roscore.
$ roscore
Second terminal: run Bringup on the Pi.
$ ssh pi@IP_OF_TURTLEBOT
$ set_ip LAST_THREE_DIGITS
$ bringup
Third terminal: launch the launchfile that we've constructed that 1) starts up the map server, 2) sets up
some important coordinate transformations, and 3) runs rviz with some helpful configurations already in place for
you (visualizing the map, particle cloud, robot location). If the map doesn't show up when you run this command,
we recommend shutting down all of your terminals (including roscore
) and starting them all up again
in the order we present here.
$ roslaunch particle_filter_project visualize_particles.launch
Fourth terminal: run the Turtlebot3 provided code to teleoperate the robot.
$ roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
Fifth terminal: run your particle filter code.
$ rosrun particle_filter_project particle_filter.py
You may use Gazebo to test your particle filter code prior to running it on a physical Turtlebot, as the testing process is much faster and easier to tweak using Gazebo. However, make sure that your official run of the particle filter code is on the physical robot!
First terminal: run roscore.
$ roscore
Second terminal: run your Gazebo simulator. For this project, we're using a simulated version of the particle filter maze.
$ roslaunch particle_filter_project turtlebot3_maze.launch
particle_filter_project
(which happens with Github classroom creates a unique repository name for your project group). To fix this and allow the map to show up, simply change your directory name from something like particle-filter-project-sarah-sebo
to particle_filter_project
. On the command line, you can execute:
$ cd ~/catkin_ws/src/
$ mv particle-filter-project-sarah-sebo particle_filter_project
Third terminal: launch the launchfile that we've constructed that 1) starts up the map server, 2) sets up
some important coordinate transformations, and 3) runs rviz with some helpful configurations already in place for
you (visualizing the map, particle cloud, robot location). If the map doesn't show up when you run this command,
we recommend shutting down all of your terminals (including roscore
) and starting them all up again
in the order we present here.
$ roslaunch particle_filter_project visualize_particles.launch
Fourth terminal: run the Turtlebot3 provided code to teleoperate the robot.
$ roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
Fifth terminal: run your particle filter code.
$ rosrun particle_filter_project particle_filter.py
The goal of our particle filter localization (i.e., Monte Carlo localization) will be to help a robot answer the question of "where am I"? This problem assumes that the robot has a map of its environment, however, the robot either does not know or is unsure of its position and orientation within that environment.
To solve the localization problem, the particle filter localization approach (i.e., Monte Carlo Localization algorithm) makes many guesses (particles) for where it might think the robot could be, all over the map. Then, it compares what it's seeing (using its sensors) with what each guess (each particle) would see. Guesses that see similar things to the robot are more likely to be the true position of the robot. As the robot moves around in its environment, it should become clearer and clearer which guesses are the ones that are most likely to correspond to the actual robot's position. Please see the Class Meeting 04 page for more information about the MCL algorithm.
In more detail, the particle filter localization first initializes a set of particles in random locations and orientations within the map and then iterates over the following steps until the particles have converged to (hopefully) the position of the robot:
In the following sections, we'll walk through each of the main steps involved with programming your own particle filter localization algorithm.
Your first step with this project will involve recording a map of the maze (pictured below). You will record the
map using the built in turtlebot3 SLAM tools that we go over during Lab D: roslaunch
turtlebot3_slam turtlebot3_slam.launch slam_methods:=gmapping. Please save your map in the
particle_filter_project/map
directory under the name maze_map
.
Once you've created your map, you'll next want to initalize your particles. Ideally, you'll want your particles initiaized only within the light grey cells on the map (as opposed to the black obstacles/walls or the area outside the map), and randomly distributed across that area.
To initalize your particles within the map's boundaries, you'll need to work with the particle filter's map
attribute, which is of type nav_msgs/OccupancyGrid. The map data list (data
) uses row-major ordering and the map info
contains useful information about the width, height, resolution, and more. You'll also want to locate the origin of the map to help you debug.
rospy.sleep()
command in your code to allow time for the ROS node as well as its publishers and subscribers to set up before you publish your particle cloud for the first time.
Next, we need to ensure that when our robot moves around and turns (as you're teleoperating it), that the particles also move around and turn the exact same amount. You'll teleoperate the robot with either the alias teleop or the longer roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch. To keep track of the robot's movements, the starter code already computes the difference in the robot's xy position and orientation (yaw) in the robot_scan_received()
function. If the robot moves "enough" based on the linear and angular movement thresholds, it will trigger one iteration of the particle filter localization algorithm.
Your job, is to use the precomputed difference in the robot's xy position and orientation (yaw) to update the particle positions, and also adding in some movement noise.
For example, we recommend you test out the movement of your particles by lowering your number of partcles to something like 4-10 particles and then observing their movement closesly to see if their movement matches that of the turtlebot.
This is a crticial component of the particle filter localization algorithm, where you assign a weight to each particle that represents how well the robot's sensor measurements match up with the particle's location on the map. As we went over in Class Meeting 05, you are welcome to use either a ray casting approach or a likelihood field approach.
One helper function we've provided you to assist with this section is compute_prob_zero_centered_gaussian(dist, sd)
. This function takes in a distance, which represents the difference between the LiDAR distance you receive from the robot and the distance you compute for your particle based on either the ray casting or likelihood field algorithm. With that input, the function outputs a probability value. For example, if your robot "sees" a distance of 2.0m at 90 degrees and your particle also "sees" a distance of 2.0m at 90 degrees, the distance value you'd feed into compute_prob_zero_centered_gaussian(dist, sd)
would be 2.0 - 2.0 = 0, and you'd get a high probability output, since these values are closely aligned.
After you've computed the particle weights, you'll now resample with replacement a new set of particles (from the prior set of particles) with a probability in propotion to the particle weights.
Finally, you'll update the estimate of the robot's location based on the average position and orientation of the particles.
You will notice that your estimate will be very poor until your particles have begun to converge. This is ok and expected.
Parameter and code optimization is a large component of student success in this project. Notably, this algorithm can be very computationally expensive, so it's important that you adjust your code and particle filter parameters to enable your particle filter localization code to run successfully.
Code Optimization: There are ways you can restructure your code to enable better performance, such as:
Parameter Optimization: There are many parameters you can adjust in your code to either (1) improve runtime performance and reduce lag or (2) improve the performance of the algorithm itself, some examples of paramters we encourage you to change and optimize include:
The following example gifs show the progression of the particles over time. You can see that at the beginning, the particles are randomly distributed throughout the map. Over time, the particles converge on likely locations of the robot, based on its sensor measurements. And eventually, the particles converge on the true location of the robot.
And in this example, you can see the particle filter side-by-side with the real robot in the maze.
In many ways, I would not be a professor at UChicago and teaching this class had it not been for the particle filter that I programmed during my undergrad at Franklin W. Olin College of Engineering. My partner in crime, Keely, and I took a semester to learn about algorithms used in self-driving cars (under the guidance of Professor Lynn Stein) and implemented our own particle filter on a real robot within a maze that we constructed ourselves. It was this project that propelled me to get my PhD in Computer Science studying human-robot interaction, which then led me to UChicago. Below, I've included some photos of our project.
And here's the video of our particle filter working, where you can see the particles (blue) converging to the location of the robot (red).
The design of this course project was influenced by the particle filter project that Keely Haverstock and I completed in Fall 2013 at Olin College of Engineering as well as Paul Ruvolo and his Fall 2020 A Computational Introduction to Robotics course taught at Olin College of Engineering. The gifs providing examples of the particle filter are used with permission from former students Max Lederman, Emilia Lim, Shengjie Lin, Sam Nitkin, and David Pan.