We have built a robot car that contains two continuous servos for movement, a camera that is mounted on two standard servos used as heads, and an ultrasonic sensor. The purpose of our project is to respond to a traffic light. We want the robot to recognize the red color by the camera and stop in a certain distance away from the traffic light using the ultrasonic sensor. And, the robot should start moving again when the red color disappears.
The following is the algorithm we have in mind,
The algorithm of the program starts with moving forward while "tracking" is enabled aiming to find Red. If Red is detected, the Distance between the robot and Red is calculated. This Distance is compared with Y, which is a set value in inches corresponding to a distance away from Red where the robot should stop. If the Distance is not less than or equal to Y, the robot keeps moving until this condition is satisfied. If the Distance is less than or equal to Y, the robot stops. When the color changes (becomes not Red anymore), the program starts again with moving forward.
Attached is a flowchart of the algorithm and a picture of the robot.
We would appreciate it if you could give us a script that helps us to accomplish such a job.
*Note: that the flowchart doesn't have an " end " because we are going to stop the robot manually.