9. Practical Guide\9.6 Using RGB Colour Sensor

9.6  Using RGB Colour Sensor

Write a program to let robot to collect RED objects while navigating in the virtual world.

Flowchart:

Problem analysis:

The robot has three actions – Search for RED object and navigate in which including moving forward, and turning right. Therefore, three statements should be added:

v  1st statement: The robot will stop for 3 seconds with LED blinking if it senses RED block (either colour sensor detects RED object)

v  2nd statement: The robot will make a right turn if the front ultrasonic sensor reading is less than 20 cm (it has sensed the front obstacle is less than 20 cm away)

v  3rd statement: The robot moves forward if the 1st statement is not executed.

Procedure:

We will write the program code based on the example 9.5.

1.    Manual control the RED robot and move it over the RED object.

2.    Monitor the RGB colour sensor value. The red channel is closer to 255 and others are small if it detects RED object

3.    Record the RBG value when the robot detects the RED object.

4.    In the “Practice” panel, click on “AI” to launch the AI programming panel.

5.    Open the “Navigation” project.

6.    Choose the “Navigation.smp”.

7.    The Navigation project is loaded.

8.    Add new statements - “FoundRED_L” and “FoundRED_R”

The robot needs to check the colour object underneath the left RGB colour sensor. It only stops and blinks the LED for 3 sec if the RED object is detected. The robot will do the same action if the right RGB colour sensor detects the RED object. The robot will navigate in the virtual world if there is no RED object detected. Hence, the “FoundRED_L” and “FoundRED_R statements have the higher priority than “Navigation”.

9.    The “FoundRED_L” and “FoundRED_R” is now added.

10. Assign conditions and actions to the new statements.

v  Set the RGB value as found in sensor calibration (step 1);

v  Duration = 3000 ms (3 sec);

v  WheelLeft = 0; WheelRight = 0; (robot stops);

v  LED_1 = 1 (LED blinks);

11. Save project. You should change the project name as “SearchingRED”.

12. Build the project.

13. Load the “SearchingRED.dll” to the RED robot and monitor the performance.

 

 

Top of Page