Wednesday, October 28, 2015

UPDATE: 10/28/15

Today, we met to discuss the algorithm that the robot should take to accomplish the main tasks associated with the goal of this assignment. We want to be able to have the robot track a line, sense an object through the use of the sonar sensor and the touch sensor. We started further discussing the methods of using while loops and if-else statements to get closer to our goal. We created a sample program that we think is gonna get us closer to our goal, here is a sneak peak of the code:

#pragma config(Sensor, S1,     lightsensor,    sensorLightActive)
#pragma config(Sensor, S2,     touchsensor,    sensorTouch)
#pragma config(Sensor, S3,     sonar,          sensorSONAR)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
    while(SensorValue(touchsensor) == 0) //not hitting anything
        {
            while(SensorValue(lightsensor) < 50)//black region,
                {
                motor[motorA] = 0;
                motor[motorB] = 50;
                }
            while(SensorValue(lightsensor) >= 50)//light region, keep switching motor directions
                {
                motor[motorA] = 50;
                motor[motorB] = 0;
                }
        }
    while (SensorValue(touchsensor) == 1) //hits a wall
        {
        //back up
        wait10Msec(2000);//wait a bit first
        motor[motorA] = -25;
        motor[motorB]= -25;
        wait1Msec(1000);

        //Turn right at an angle
        motor[motorA]= -100;
        motor[motorB]=0;
        wait10Msec(500);

        while(SensorValue(sonar) >= 50)
            motor[motorA]=100;
            motor[motorB]=50;

        }
}

No comments:

Post a Comment