ROBOTC.net forums
http://www.robotc.net/forums/

Vex Line Follower
http://www.robotc.net/forums/viewtopic.php?f=11&t=12328
Page 1 of 1

Author:  Bromtheman [ Thu Oct 01, 2015 11:44 am ]
Post subject:  Vex Line Follower

Currently I use the PLTW language platform since it is easier and it is what I have been taught to use. I want to make a range value so that once a marble with a different color runs into a line follow it will trigger if the marble is in a certain range this works perfect when I use a single value but if I use a range for the sensor value it will never trigger.

Script that doesn't seem to work (Disregard the test script)
#pragma config(Sensor, in1, MarbleSensor, sensorLineFollower)
#pragma config(Sensor, in2, Pot, sensorPotentiometer)
#pragma config(Sensor, in3, Light, sensorReflection)
#pragma config(Sensor, dgtl1, Start, sensorTouch)
#pragma config(Sensor, dgtl2, Test, sensorTouch)
#pragma config(Motor, port1, Flash, tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor, port2, Gate, tmotorServoStandard, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
while (1==1)
{
if (SensorValue(Start)==1)
// press button to start
{
while (1==1)
{
turnFlashlightOn(Flash, 127);
if (SensorValue(MarbleSensor) <= 1900-2000)
{
setServo(Gate, -127);
wait(0.25);
setServo(Gate, 0);
wait(0.25);

}
// If 2000-2100 end script
}
// While end script
}
// First if end script
if (SensorValue(dgtl2)==1)
{
while (1==1)
{
setServo(Gate, -127);
wait(0.25);
setServo(Gate, 0);
wait(0.25);
}
}
}
// Start of bump 2

}



--------------------------------------
Script that does work but doesn't contain the range



#pragma config(Sensor, in1, MarbleSensor, sensorLineFollower)
#pragma config(Sensor, in2, Pot, sensorPotentiometer)
#pragma config(Sensor, in3, Light, sensorReflection)
#pragma config(Sensor, dgtl1, Start, sensorTouch)
#pragma config(Sensor, dgtl2, Test, sensorTouch)
#pragma config(Motor, port1, Flash, tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor, port2, Gate, tmotorServoStandard, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
while (1==1)
{
if (SensorValue(Start)==1)
// press button to start
{
while (1==1)
{
turnFlashlightOn(Flash, 127);
if (SensorValue(MarbleSensor) <= 1900)
{
setServo(Gate, -127);
wait(0.25);
setServo(Gate, 0);
wait(0.25);

}
// If 2000-2100 end script
}
// While end script
}
// First if end script
if (SensorValue(dgtl2)==1)
{
while (1==1)
{
setServo(Gate, -127);
wait(0.25);
setServo(Gate, 0);
wait(0.25);
}
}
}
// Start of bump 2

}

Author:  CARBOT [ Thu Oct 01, 2015 12:47 pm ]
Post subject:  Re: Vex Line Follower

You could try something like...
if ((SensorValue(MarbleSensor) >1899) && (SensorValue(MarbleSensor) < 2001))
{
code
}

Author:  Tabor473 [ Fri Nov 06, 2015 1:53 pm ]
Post subject:  Re: Vex Line Follower

Code:
#pragma config(Sensor, in1, MarbleSensor, sensorLineFollower)
#pragma config(Sensor, in2, Pot, sensorPotentiometer)
#pragma config(Sensor, in3, Light, sensorReflection)
#pragma config(Sensor, dgtl1, Start, sensorTouch)
#pragma config(Sensor, dgtl2, Test, sensorTouch)
#pragma config(Motor, port1, Flash, tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor, port2, Gate, tmotorServoStandard, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
    while (1==1)
    {
        if (SensorValue(Start)==1)
            // press button to start
        {
            while (1==1)
            {
                turnFlashlightOn(Flash, 127);
                if (SensorValue(MarbleSensor) <= 1900-2000)
                {
                    setServo(Gate, -127);
                    wait(0.25);
                    setServo(Gate, 0);
                    wait(0.25);

                }
                // If 2000-2100 end script
            }
            // While end script
        }
        // First if end script
        if (SensorValue(dgtl2)==1)
        {
            while (1==1)
            {
                setServo(Gate, -127);
                wait(0.25);
                setServo(Gate, 0);
                wait(0.25);
            }
        }
    }
    // Start of bump 2

}


In the future please put all your code in the tags like shown above. It maintains the formatting(from the ROBOTC fix formatting button).

So currently
Code:
if (SensorValue(MarbleSensor) <= 1900-2000)
                {
                    setServo(Gate, -127);
                    wait(0.25);
                    setServo(Gate, 0);
                    wait(0.25);

                }

Will only run if the sensor value is less than or equal to 100 which is almost never. I am not sure what you are trying to do with the subtraction there but I assume you are trying to say in
psuedo code
if sensor is between 1900 and 2000
which is written like
Quote:
if(SensorValue(MarbleSensor)<=2000&&SensorValue(MarbleSensor)>=1900)

The && means AND so the code only executes if the sensor is less than 2000 and greater than 1900.

Also a large portion of your code will never be run currently.
Code:
while (1==1)
            {
                turnFlashlightOn(Flash, 127);
                if (SensorValue(MarbleSensor) <= 1900-2000)
                {
                    setServo(Gate, -127);
                    wait(0.25);
                    setServo(Gate, 0);
                    wait(0.25);

                }
                // If 2000-2100 end script
            }

You will be stuck in this portion of the code because the robot will keep hitting the bottom of the while loop and then repeating without seeing the next part of the code shown here.
Code:
if (SensorValue(dgtl2)==1)
        {
            while (1==1)
            {
                setServo(Gate, -127);
                wait(0.25);
                setServo(Gate, 0);
                wait(0.25);
            }
        }

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/