Learn 4: Experiment With Color Sensing

This is the fifth challenge within the Robotics with GoPiGo and Python Curriculum.

Your task is to design a robot program to deliver a selection of mail to the residents of GoPiGo Drive, a small cul-de-sac containing 3 houses.

Learn how to how to use and calibrate the color sensor.

6. Demo: Now with Color Sensor

Now let’s add some code that:

          • senses a green marker
          • turns the robot around by 180 degrees so that it can return the way it came.

We’ve written some template functions that you can use here.

These functions:

          • read the color sensor (read_color_sensor(  )),
          • record the values read in container attributes for use by the data analysis graph,
          • light both of the courier’s eyes up to show the color just read (record_color(  )).

Add these lines just above the time.sleep(0.1) line

read_color_sensor()
record_color('both')
if var.color_name == ‘green’:
    courier.turn_degrees(180)