Asked — Edited

Help In Programming

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.

User-inserted image

*Note: that the flowchart doesn't have an " end " because we are going to stop the robot manually.

User-inserted image


ARC Pro

Upgrade to ARC Pro

Harnessing the power of ARC Pro, your robot can be more than just a simple automated machine.

United Kingdom
#9  

Also, to use the light itself for distance you would need to determine the size of it for when you want it to stop.

There are two variables used with the camera tracking, $CameraObjectWidth and $CameraObjectHeight

The easiest way to do this is to add the variable watcher in to ARC and look at the two variables values when it is the right distance to stop, then change the IF statement for the GetPing to check the variables against the pre-determined sizes...

Define the two new variables at the start of the script;


$WidthMax = 20
$HeightMax = 20

The replace the IF statement for the Ping sensor to use the camera variables


If($CameraObjectHeight >= $HeightMax or $CameraObjectWidth >= $WidthMax)
  Stop()
EndIf

And the new code should be something like;


# Set up the maximum values for stopping
$WidthMax = 20
$HeightMax = 20

# Start the main code
:start
Forward()
ControlCommand("Camera", CameraColorTracking, red)
IF($CameraIsTracking=1)
  If($CameraObjectHeight >= $HeightMax or $CameraObjectWidth >= $WidthMax)
    Stop()
  ENDIF 
ENDIF 
Goto(start)

Something like that should do it. Again, this has been done with no prior use of those two variables and without testing. Also note that the WidthMax and HeightMax variables will need to be determined as mentioned at the start.

Have a read (when you have half an hour or so) of the topic I made the other day An Introduction To Scripting. It has some great tips in it on how to start with scripting.