Lab 2: Color Images

In this lab, you will program the car to respond to images captured by the camera.

Presentation Slides: 2A: Color Images, 2B: State Machines

Video Lectures: lab 2A and lab 2B.

You can view the starter code for this lab in the labs directory of your student repository.


Main objective

Use the color camera to recognize and respond to objects of certain colors.

Learning objectives

  • Extract contours from a color image to identify the location and closeness of key objects.
  • Implement proportional control to allow for smooth responses to stimuli.
  • Use the Camera Module to capture color images with the car’s camera.
  • Use the Display Module to print images to the onboard monitor.


Jupyter Notebook

Work through the lab 2 Jupyter notebook (labs/lab2/lab2.ipynb). This Jupyter notebook will help you experiment with image processing and build up functions that you will need for the main challenges.

See Using Jupyter for instructions on how to use the Jupyter Notebook with RacecarSim or a physical RACECAR-MN.

Lab 2A - Line Following

Open the racecar directory on your computer in Visual Studio Code. The starter code for lab 2A (labs/lab2/ instructs the car to to follow a blue line. However, this implementation is very jerky.

Replace the TODO: (warm up) comment with code that allows the car to follow a blue line more smoothly.

Replace the TODO: (challenge 1) comments with code that allows the car to follow lines of the following colors with the following priorities:

  1. Red (highest priority)
  2. Green
  3. Blue (lowest priority)

For example, if the car sees a red, green, and blue line at the same time, it should follow the red line. The car should only follow a blue line if it does not see any red or green lines.

Lab 2B - Cone Parking

The starter code for lab 2B (labs/lab2/ has similar helper functions to lab 2A, but it currently has no instructions for moving the car. Replace the TODO: comment with code that allows the car to drive up to an orange cone and stop 30 cm in front of it. If the car is not pointing directly towards the cone, it should steer towards it. If the car is too close to the cone, it should back up. If you pick up the cone and move it, the car should follow the cone.