• Moving forward a specific distance

    This simple program uses “Encoders” to measure the rotation of the axle.  This is helpful if you want your robot to go a very precise distance.  You will have to measure the circumference of your wheel and divide that by 360 to see how far your robot will go for each degree of rotation.  You program your robot to go a specific number of degrees and then you know exactly how far it will go.

     

    task main()
    {
    //reset right and left encoders to Zero
    SensorValue(rightEncoder)=0;
    SensorValue(leftEncoder)=0;

     //while right encoder is less than 1800 (five rotations = 360 * 5 = 1800)
    while(SensorValue(rightEncoder) < 1800)
    {
    startMotor(rightMotor, 63); //right motor goes half speed
    startMotor(leftMotor, 63); //left motor goes half speed
    }
    stopMotor(rightMotor); //right motors stop
    stopMotor(leftMotor); //left motor stops
    }