Go to Post Why do things the easy way when you can do it with a robot? - MissInformation [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rating: Thread Rating: 9 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 07-04-2014, 13:29
Spacemonkey619 Spacemonkey619 is offline
Registered User
None #4899
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: California
Posts: 7
Spacemonkey619 is an unknown quantity at this point
How to loop peices of code forever?

Hello I am a programmer for my school's robotics team and engineering class and i ran into a code problem. A team project is to program a claw bot that when a button is pressed it will follow a line with encoders and with the claw bot grab a box line track backwards and let go of the box, it is supposed to do this forever when the button at the beginning is pressed. Not only that but when a button is pressed while its looping it will do this task one more time before ending the program. So my problem is that i can't get the code to run forever when the button is pressed, what happens is that the line track moves forever and never moves on to the next step. Here is how my code looks below.

PS: I know i didn't include the part when the button is pressed again it runs one more time. It's not included because that's not the problem.








#pragma config(Sensor, in1, pot, sensorPotentiometer)
#pragma config(Sensor, in3, LineLeft, sensorLineFollower)
#pragma config(Sensor, in4, LineRight, sensorLineFollower)
#pragma config(Sensor, in5, LineCenter, sensorLineFollower)
#pragma config(Sensor, dgtl1, touch, sensorTouch)
#pragma config(Sensor, dgtl2, Encoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl7, Encoder2, sensorQuadEncoder)
#pragma config(Motor, port2, arm, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port3, elbow, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port7, rightMotor, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor, port8, leftMotor, tmotorServoContinuousRotation, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{



if(SensorValue(touch) == 0)
{
motor[arm] = 0;
}




if(SensorValue(touch) == 1)
{

while(true)// i also tried while(1 == 1)

{
motor[elbow] = -63;
wait1Msec(1500);
}

motor[elbow] = 0;
wait1Msec(100);





int threshold = 2000;

SensorValue[Encoder] = 0;


while(SensorValue[Encoder] < 210)
{




if(SensorValue(LineRight) > threshold)
{
// counter-steer right:
motor[leftMotor] = 50;
motor[rightMotor] = 0;
}
// CENTER sensor sees dark:
if(SensorValue(LineCenter) > threshold)
{
// go straight
motor[leftMotor] = 30;
motor[rightMotor] = 30;
}


if(SensorValue(LineLeft) > threshold)
{
// counter-steer left:
motor[leftMotor] = 0;
motor[rightMotor] = 50;
}

}
}

{
motor[arm] = 63;
wait1Msec(2000);

motor[elbow] = 63;
wait1Msec(200);

motor[rightMotor] = 0;
motor[leftMotor] = 0;
wait1Msec(1000);

motor[arm] = -63;
wait1Msec(1800);

motor[elbow] = -63;
wait1Msec(2500);

motor[elbow] = 0;
wait1Msec(1000);

motor[rightMotor] = -43;
motor[leftMotor] = -43;
wait1Msec(500);


}

int threshold = 2000;

SensorValue[Encoder] = 0;


while(SensorValue[Encoder] > -450)
{




if(SensorValue(LineRight) > threshold)
{
// counter-steer right:
motor[leftMotor] = -50;
motor[rightMotor] = 0;
}
// CENTER sensor sees dark:
if(SensorValue(LineCenter) > threshold)
{
// go straight
motor[leftMotor] = -30;
motor[rightMotor] = -30;
}


if(SensorValue(LineLeft) > threshold)
{
// counter-steer left:
motor[leftMotor] = 0;
motor[rightMotor] = -50;
}



}




}
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 22:05.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi