RobotC Autonomous Issue

Hey everyone! We are currently having problems getting our autonomous working correctly. At the moment, the robot will run during autonomous but will only keep driving forward for the whole 15 seconds. Here is the code:

void pre_auton()
{
  // Set bStopTasksBetweenModes to false if you want to keep user created tasks running between
  // Autonomous and Tele-Op modes. You will need to manage all user created tasks if set to false.
  bStopTasksBetweenModes = true;

	// All activities that occur before the competition starts
	// Example: clearing encoders, setting servo positions, ...
}

/////////////////////////////////////////////////////////////////////////////////////////
//
//                                 Autonomous Task
//
// This task is used to control your robot during the autonomous phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////

task autonomous()
{
	SensorValue[rightEncoder] = 0;  //Clear the right encoder value
  SensorValue[leftEncoder] = 0;   //Clear the left encoder value

	while(SensorValue[rightEncoder] < 420)
  {
    motor[leftFront] = 63;
    motor[leftMid] = 63;
    motor[leftRear] = 63;
    motor[rightFront] = 63;
    motor[rightMid] = 63;
    motor[rightRear] = 63;
  }
SensorValue[rightEncoder] = 0;  //Clear the right encoder value
SensorValue[leftEncoder] = 0;   //Clear the left encoder value

while(SensorValue[rightEncoder]<260)

{
motor[rightFront] = 63;
motor[rightMid] = 63;
motor[rightRear] = 63;
}

SensorValue[rightEncoder] = 0;  //Clear the right encoder value
SensorValue[leftEncoder] = 0;   //Clear the left encoder value

What is the issue here? Thank you.

I would suggest doing a bit of debugging, the problem seems to be with the encoder. Use the sensors debugger window to make sure your encoders are properly reading and such.

Off the top of my head, (assuming everything is working/plugged in), one likely possibility is that your encoder is mounted so that when your robot drives forwards, the encoder reads negative. As such, this line:

the encoder value will keep getting smaller and you get stuck in the while loop. Try this:


while(abs(SensorValue[rightEncoder]) < 420)

which will make the direction of the encoder mount irrelevant since abs() takes the absolute value.

nah the issue is he never tells the motors to stop.

@Ashwin Gupta we made sure that the senors were properly set up (used the debug window to check). “abs” is definitely something we’ll implement though to make sure everything functions correctly.

@tabor473 where and how do we add the motor stops to this? Tried to do that but it would still shoot forward (most likely did it wrong).

Just call

motor[leftRear] = 0;

on every motor after each while loop.

@tabor473 ok we’ll try and see if that works.

whoops… brain fart… totally missed that. Yeah thats the main issue.

@tabor473 @Ashwin Gupta got it running thanks! What we had done wrong earlier was trying to use the “stopallmotors” command. We were trying to use natural language but it just won’t work out for whatever reason.