View unanswered posts | View active topics It is currently Wed Dec 19, 2018 5:38 am






Reply to topic  [ 3 posts ] 
Vex Line Follower 
Author Message
Rookie

Joined: Thu Oct 01, 2015 11:33 am
Posts: 2
Post 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

}


Thu Oct 01, 2015 11:44 am
Profile
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
Post Re: Vex Line Follower
You could try something like...
if ((SensorValue(MarbleSensor) >1899) && (SensorValue(MarbleSensor) < 2001))
{
code
}


Thu Oct 01, 2015 12:47 pm
Profile
Moderator
Moderator

Joined: Tue May 19, 2015 3:07 pm
Posts: 91
Post 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);
            }
        }


Fri Nov 06, 2015 1:53 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.