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;
}
}
}