Hi al, I am new to Robotics and coding. To put it simply, I am trying to autonomously control my robot for 2:30 minutes then remote control my robot for the following minute. I have a code file the I am needing some help with. I put comments into it to help understand the file and also the issues I am having. Basically, I am trying to limit the arm with a potentiometer after some other basic commands. The potentiometer code seems to be the issue. I took the timer out because I thought that was part of the problem. Can you give a look and see if there is something obvious that I am doing wrong? We are using the Vex 2.0 Cortex and using Robot C to code. Thanks
#pragma config(Sensor, in1, armPot, sensorPotentiometer)
#pragma config(Sensor, in2, lineFollowerRIGHT, sensorLineFollower)
#pragma config(Sensor, in3, lineFollowerCENTER, sensorLineFollower)
#pragma config(Sensor, in4, lineFollowerLEFT, sensorLineFollower)
#pragma config(Sensor, in5, lightSensor, sensorReflection)
#pragma config(Sensor, dgtl1, rightEncoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl3, leftEncoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl5, frontLimit, sensorTouch)
#pragma config(Sensor, dgtl6, sonarSensor, sensorSONAR_cm)
#pragma config(Motor, port1, rightMotor, tmotorVex393_HBridge, openLoop)
#pragma config(Motor, port8, clawMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port9, armMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port10, leftMotor, tmotorVex393_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
void moveStraight(int encoderCount)
{
SensorValue[rightEncoder] = 0;
SensorValue[leftEncoder] = 0;
while(SensorValue[leftEncoder] < encoderCount)
{
if(SensorValue[leftEncoder] > SensorValue[rightEncoder])
{
motor[rightMotor] = 63;
motor[leftMotor] = 50;
}
if(SensorValue[rightEncoder] > SensorValue[leftEncoder])
{
motor[rightMotor] = 50;
motor[leftMotor] = 63;
}
if(SensorValue[leftEncoder] == SensorValue[rightEncoder])
{
motor[rightMotor] = 63;
motor[leftMotor] = 63;
}
}
}
void turnLeft (int encodercount)
{
SensorValue[rightEncoder] = 0; //Set the encoder so that it starts counting at 0
SensorValue[leftEncoder] = 0;
while(SensorValue(rightEncoder) < encodercount) //While rightEncoder has counted less than parameter, turn left
{
//Turn Left
motor[rightMotor] = 127; //Motor on port2 is run at full (127) power forward
motor[leftMotor] = -127; //Motor on port3 is run at full (-127) power reverse
}
}
void turnRight (int encodercount)
{
SensorValue[rightEncoder] = 0;
SensorValue[leftEncoder] = 0; //Set the encoder so that it starts counting at 0
while(SensorValue(leftEncoder) < encodercount) //While leftEncoder has counted less than 1800 counts
{
//Turn Right
motor[rightMotor] = -127; //Motor on port2 is run at full (-127) power reverse
motor[leftMotor] = 127; //Motor on port3 is run at full (127) power forward
}
}
task main()
{
//This curly Brace opens the task main. This is where autonomous starts.
while(vexRT[Btn7D] == 0) //Remote Start Button
{
//Do Nothing, unless button is pressed. Once pressed, run next behavior.
}
//Had timer here, doesn't seem to be working
while(SensorValue(lightSensor) > 346) // While the ambient lightSensor reads a value greater than 346
{
// Do nothing
}
moveStraight(1800); //calling on function from the Void above
motor[rightMotor] = 0; //Brake for 1 second
motor[leftMotor] = 0;
wait1Msec(1000);
turnLeft(360);
motor[rightMotor] = 0; //Brake for 1 second
motor[leftMotor] = 0;
wait1Msec(1000);
turnRight(360);
motor[rightMotor] = 0; //Brake for 1 second
motor[leftMotor] = 0;
wait1Msec(1000);
moveStraight(1800); //calling on function from the Void above
motor[rightMotor] = 0; //Brake for 1 second
motor[leftMotor] = 0;
wait1Msec(1000);
//Potentiometer to limit the arm
while (1==1)
{
if(SensorValue(armPot) < 510) // While the armPot reads a value less than 510, raise the arm at a power of 63.
{
motor[armMotor] = 63;
motor[leftMotor] = 0;
motor[rightMotor] = 0;
}
else
{
motor[armMotor] = 10;
motor[leftMotor] = 0;
motor[rightMotor] = 0;
}
} //If this bracket isn't here, arm keep raising. If it is here, arm stops, but nothing after this executes.
//This is where the problem is. The arm raises and nothing else executes.
//Line Track until sonar senses an obstacle
int threshold = 1352;
while(SensorValue(sonarSensor) > 20 || SensorValue(sonarSensor) == -1)//Track the line until the sonar detects an obstacle
{
// RIGHT sensor sees dark:
if(SensorValue(lineFollowerRIGHT) > threshold)
{
// counter-steer right:
motor[leftMotor] = 63;
motor[rightMotor] = 0;
}
// CENTER sensor sees dark:
if(SensorValue(lineFollowerCENTER) > threshold)
{
// go straight
motor[leftMotor] = 63;
motor[rightMotor] = 63;
}
// LEFT sensor sees dark:
if(SensorValue(lineFollowerLEFT) > threshold)
{
// counter-steer left:
motor[leftMotor] = 0;
motor[rightMotor] = 63;
}
}//Closes line track while loop
motor[leftMotor] = 0;
motor[rightMotor] = 0;
//Wants to keep tracking line. Figure out why.
//Closes the Timer while loop
//This is where the Remote Control Section starts
while(vexRT[Btn8D] == 0)//Remote Start Button
{
//Do Nothing. If pressed, move onto the next behavior
}
clearTimer(T2);
while(time10[T2] < 6000)//Timer Runs for 60 seconds and runs code within the while loop
{//This curly brace opens the while loop
motor[leftMotor] = vexRT[Ch3] / 2;
motor[rightMotor] = vexRT[Ch2] / 2;//Remote Control Joysticks
if(vexRT[Btn6U] ==1 && SensorValue[armPot] < 546)
{
motor[armMotor] = 40;
}
else if(vexRT[Btn6D] ==1 && SensorValue[frontLimit] == 1)
{
motor[armMotor] = -40;
}
else
{
motor[armMotor] =0;
}
//If Button 6U is pushed, raise the arm up at a power of 40, if Button 6D is pushed, lower the arm at a power of 40
if(vexRT[Btn5U] ==1)
{
motor[clawMotor] = 40;
}
else if(vexRT[Btn5D] ==1)
{
motor[clawMotor] = -40;
}
else
{
motor[clawMotor] =0;
} //If Button 5U is pushed, raise the claw up at a power of 40, if Button 5D is pushed, lower the arm at a power of 40
//This bracket closes the timer while loop
}
}
edit: code tags added by mods, please remember to use them.