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

Return to start
http://www.robotc.net/forums/viewtopic.php?f=11&t=12358
Page 1 of 1

Author:  Bromtheman [ Tue Oct 13, 2015 12:10 pm ]
Post subject:  Return to start

Currently with my script I want the code to return to the start after it has detected a value and the bins have rotated but it keeps getting stuck in a loop and I will show you the current script and what I want it to do.

Current script -


#pragma config(Sensor, in1, MarbleSensor, sensorLineFollower)
#pragma config(Sensor, in3, Light, sensorReflection)
#pragma config(Sensor, dgtl1, Start, sensorTouch)
#pragma config(Sensor, dgtl2, Test, sensorTouch)
#pragma config(Sensor, dgtl3, Sonar, sensorSONAR_raw)
#pragma config(Motor, port1, Flash, tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor, port2, Gate, tmotorServoStandard, openLoop)
#pragma config(Motor, port3, Bin, tmotorVex393_MC29, 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) >300) && (SensorValue(MarbleSensor) < 850))

{
wait(1);
if ((SensorValue(MarbleSensor) >300) && (SensorValue(MarbleSensor) < 850))
startMotor(Bin, 12.5);
while ((SensorValue(Sonar) > 235) && (SensorValue(Sonar) < 245))
{
stopMotor(Bin);
setServo(Gate, -127);
wait(0.25);
setServo(Gate, 0);
wait(0.25);
startMotor(Bin, 16);
wait(0.75);
stopMotor(Bin);

}
}
// If 2000-2100 end script
}
// While end script
}
// First if end script
}
}


What I want it to do -

#pragma config(Sensor, in1, MarbleSensor, sensorLineFollower)
#pragma config(Sensor, in3, Light, sensorReflection)
#pragma config(Sensor, dgtl1, Start, sensorTouch)
#pragma config(Sensor, dgtl2, Test, sensorTouch)
#pragma config(Sensor, dgtl3, Sonar, sensorSONAR_raw)
#pragma config(Motor, port1, Flash, tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor, port2, Gate, tmotorServoStandard, openLoop)
#pragma config(Motor, port3, Bin, tmotorVex393_MC29, 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) >300) && (SensorValue(MarbleSensor) < 850))

{
wait(1);
if ((SensorValue(MarbleSensor) >300) && (SensorValue(MarbleSensor) < 850))
startMotor(Bin, 12.5);
while ((SensorValue(Sonar) > 235) && (SensorValue(Sonar) < 245))
{
stopMotor(Bin);
setServo(Gate, -127);
wait(0.25);
setServo(Gate, 0);
wait(0.25);
startMotor(Bin, 16);
wait(0.75);
stopMotor(Bin);
Return to the beginning of the script
}
}
// If 2000-2100 end script
}
// While end script
}
// First if end script
}
}

any help would be appreciated

Author:  CARBOT [ Tue Oct 20, 2015 9:40 pm ]
Post subject:  Re: Return to start

You may want to FORMAT your code so it is easier to follow.
One of your IF statements does not have braces{} after it to suggest what to do if the statement is true.

Author:  Tabor473 [ Sat Nov 07, 2015 7:18 pm ]
Post subject:  Re: Return to start

Here is part of my reply to your other thread.
Tabor473 wrote:

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/