Hello,
Does anyone see a problem with my code below? I’m trying to get the robot to go straight, stop for 2 seconds, make a turn, stop for 2 seconds, and then go straight again. When I compile and download the code, the robot goes straight, does not take the 2 second pause, turns, and then stops without executing the last set of commands to go straight. Also, since each encoder uses 2 ports on the Cortex, does it matter what order the plugs go in? Is there a plug 1 and plug 2 for each encoder? Any help would be greatly appreciated.
Thanks!
#pragma config(Sensor, dgtl1, leftEncoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl3, rightEncoder, sensorQuadEncoder)
#pragma config(Motor, port1, leftMotor, tmotorVex393_HBridge, openLoop, reversed)
#pragma config(Motor, port10, rightMotor, tmotorVex393_HBridge, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//
task main()
{
/Reset encoders to 0/
SensorValue [leftEncoder]=0;
SensorValue [rightEncoder]=0;
while (SensorValue [rightEncoder]<200)
{
motor[leftMotor]=50;
motor[rightMotor]=50;
}
/take a 2 second pause before the next command/
wait1Msec(2000);
/*Reset encoders to 0*/
SensorValue [leftEncoder]=0;
SensorValue [rightEncoder]=0;
/Make left point turn/
while (SensorValue [rightEncoder]<170)
{
motor[leftMotor]=-50;
motor[rightMotor]=50;
}
/take a 2 second pause before the next command/
wait1Msec(2000);
/Reset encoders to 0/
SensorValue [leftEncoder]=0;
SensorValue [rightEncoder]=0;
while (SensorValue [rightEncoder]<300)
{
motor[leftMotor]=50;
motor[rightMotor]=50;
}
}