View unanswered posts | View active topics It is currently Wed Sep 19, 2018 3:24 pm






Reply to topic  [ 3 posts ] 
Return to start 
Author Message
Rookie

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


Tue Oct 13, 2015 12:10 pm
Profile
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
Post 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.


Tue Oct 20, 2015 9:40 pm
Profile
Moderator
Moderator

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


Sat Nov 07, 2015 7:18 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.