Thank you so much people!
This is to test the autonomous code without the intereference of the controller. I want the robot to run on the autonomous code after the program is downloaded and the USB cable removed. The robot doesn’t seem to pick up the autonomous code automatically with the USB unplugged from the laptop and cortex.
I have 2 autonomous tasks and 1 driver challenge task( the robot is controlled by the controller) and it has to count the number of ping pong balls that it picks up.
Here is my code:
#pragma config(Sensor, in1, RightSensor, sensorNone)
#pragma config(Sensor, in2, CenterSensor, sensorReflection)
#pragma config(Sensor, in3, LeftSensor, sensorReflection)
#pragma config(Sensor, dgtl4, LimitSwitch, sensorTouch)
#pragma config(Sensor, dgtl5, LeftEncoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl7, RightEncoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl10, sonarSensor, sensorSONAR_inch)
#pragma config(Motor, port1, RightMotor, tmotorVex393_HBridge, openLoop, reversed)
#pragma config(Motor, port2, ArmMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3, ClawMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port10, LeftMotor, tmotorVex393_HBridge, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//
//const short LeftButton=1;
//const short CenterButton=2;
//const short RightButton=4;
int pressed=0;
void Not_Pressed_Yet()
{
while (nLCDButtons==0) {}
wait1Msec(5);
}
void Not_Released_Yet()
{
while (nLCDButtons!=0) {}
wait1Msec(5);
}
void pressed_button()
{
while (Sensorvalue[dgtl4]==1)
{
pressed=1
}
wait1Msec(5);
}
void released_button()
{
while (SensorValue[LimitSwitch]==0)
{
pressed=0;
}
wait1Msec(5);
}
void Straight()
{
// if (SensorValue[LeftEncoder] > SensorValue[RightEncoder])
//{
// motor[port1]=50;
// motor[port10]=63;
// }
// if (SensorValue[LeftEncoder] < SensorValue[RightEncoder])
// {
// motor[port1]=63;
// motor[port10]=50;
// }
// if (SensorValue[LeftEncoder]==SensorValue[RightEncoder])
// {
motor[port1]=30;
motor[port10]=30;
//}
}
void TurnLeft()
{ motor[port1] = 0;
motor[port10] = 40;
}
void TurnRight()
{
motor[port1] = 40;
motor[port10] = 0;
}
void PowerRight()
{
motor[port1]=-50;
motor[port10]=50;
}
void PowerLeft()
{
motor[port1]=50;
motor[port10]=-50;
}
task autonomous_1()
{
motor[port1]=0;
motor[port10]=0;
wait1Msec(10000);
//bMotorReflected[port2]=1;
displayLCDCenteredString(0,“Have a nice Day!”);
SensorValue[LeftEncoder]=0;
SensorValue[RightEncoder]=0;
wait1Msec(5000);
motor[ArmMotor]=63;
Straight();
repeatUntil(SensorValue[dgtl10]<=1);
motor[ClawMotor]=63;
//stopAllMotors();
//}
//while (SensorValue[sonarSensor]<=1)
//{
//motor[ClawMotor]=25;
//} //Ultrasonic Range Finder code
}
task autonomous_2()
{
displayLCDCenteredString(0,“God s Great”);
while(1==1) // Center sensor sees black
{
if (SensorValue[in2] <= 2300)
{
Straight(); // Goes forward
}
if(SensorValue[in1] < 2300) // Right sensor sees black
{
TurnLeft(); // Turns left
}
if(SensorValue[in3] < 2300) // Left sensor sees black
{
TurnRight(); // Turns right
}
} // Sensor challenge code
}
task driver_challenge ()
{
motor[port1]=0;
motor[port10]=0;
int ball_counter=0;
int pressed=0;
while (true) {
clearLCDLine(0);
clearLCDLine(1);
displayNextLCDString("Count: ")
displayNextLCDNumber(ball_counter) //check what the 4 is for
pressed_button();
if(sensorvalue[dgtl4]==1){
released_button();
ball_counter++;
}
}
}
task main()
{
int count=0;
clearLCDLine(0);
clearLCDLine(1);
Not_Pressed_Yet();
while (1==1)
if (nLCDButtons==1)
{
Not_Released_Yet();
count=1;
starttask (autonomous_1); // check if you need to call the function here! (20 secs auto)
}
else if (nLCDButtons==4)
{
Not_Released_Yet();
count=2;
starttask (autonomous_2); // Sensor challenge round
}
else if (nLCDButtons==2)
{
Not_Released_Yet();
count=3;
starttask (driver_challenge); // Driver challenge round
}
}
Thanks again!