- :-

Topics Covered

  • Move Until Color Behavior
  • Lesson Links

    Check Your Understanding:
    1. 1. What does this program do when run?
    2. Move forward when the Color Sensor sees a red object
      Move forward until the Color Sensor sees a red object
      Move forward until the Color Sensor sees a green object
      Move forward as long as nothing is in the robot's way
    3. 2. What would happen is the red cube was replaced with a green one and the same program was run?
    4. The robot would still stop when it came to the green cube.
      The robot would keep going since the condition for the robot stopping was the color sensor detecting the color red.
      The robot would not move since it is waiting for the color sensor to detect the color red before it starts moving
      The robot would begin moving backwards because that is what it was programmed to do when it saw the color green
    Try It!
    Try it! 1

    Color Sensor Values

    The VEX IQ Color sensor is capable of several different modes:
    Color Name, Grayscale, Hue, and Proximity. The readings from the color sensor are extremely sensitive to “ambient” light in the robots environment.

    Download and run this program to output the values from the sensor in each of the modes to the VEX IQ Screen. Try it!

    Real Robot users

    • After downloading the program, move the robot by hand to differently colored objects and surfaces, keeping the sensor 2-3 centimeters from the object.
    • Notice how different hue values correspond to different color names, and how changes in the ambient light of your environment affect the sensor.

    Virtual Robot users

    • After downloading the program, in ROBOTC go to Robot > Debugger Window > VEX IQ Remote Screen to view the values from your computer screen.
    • Use the WASD Keyboard keys to maneuver your robot around the virtual table, pointing the color sensor at the differently colored objects.
    • Notice how different hue values correspond to different color names.
    What happens?
    As the color sensor is pointed at differently colored objects, the values on the screen update. Certain hue values correspond with certain color names. If the lighting in the environment varies, so do the sensor readings.
    Mini Challenge

    Mini Challenge 1: Red Light, Green Light, Go!

    In addition to stopping at a red light, it’s important for self-driving cars to resume driving once the light switches to green.
    • Place the robot facing a "street light" object placed in a random distance.
    • Expand your previous program so that the robot resumes moving forward once the light switches to green (or in real life, removal of the red object). The robot should move forward for 1 wheel rotation.

    You will need an additional WaitUntil command block after the one configured to wait until Red.

    After the robot has detected a color Red, what is the color it should wait for before it moves forward?

    + hint
    • Use the same setup used in the lesson video.
    • Use the Touch LED to output red when the robot is stopped, and green when the robot is moving forward.
    Mini Challenge

    Mini Challenge 2: Forward to Stop Line

    In addition to signs and lights, self-driving cars also need to obey pavement markings, like this stop line that tells the car where to stop at an intersection:

    • Use the same setup used in the lesson video, but use the marker on the bottom as a 'finish' mark.
    • To allow VEX IQ to detect marks on the floor, change its configuration as shown below.
    Configuration Requirements
    Virtual VEX IQ Choose the following configuration in RVW.
    Physical VEX IQ Download and follow building instruction below if the robot is not yet built. VEX IQ Build Instructions [PDF]

    You can use the same waitUntil-behavior to make the robot stop at a line on the floor.

    If the road is dark, and the stop line is Yellow, the robot should be able to detect Yellow. If the road is white, and the stop line is Red, the robot should be able to detect Black.

    + hint
    How does it work?

    How does it work?

    Color Sensor

    You can use the following color names in your programs for the Color Sensor:

    colorNone colorRedViolet colorRed colorDarkOrange colorOrange
    colorDarkYellow colorYellow colorLimeGreen colorGreen colorBlueGreen
    colorBlue colorDarkBlue colorViolet