2013年7月9日 星期二

The tracking line car

We can create a car which can follow a line with light sensor.  The car moves right and the sensor installed on the left front of the car.  When the sensor senses the line, the car turns left to correct the direction.

Example:

task main()
{

SetSensorLight(S1);
while(1)
{
if(Sensor(S1)< 40)
{
OnFwd(OUT_A,-100);
OnFwd(OUT_C,100);
}
else
{
OnFwd(OUT_A,100);
OnFwd(OUT_C,80);
}
}

}