After a lot of troubleshooting steps, I’ve narrowed down that PROS is only running the last autonomous command that I give to it. It is reading the previous commands, but not waiting for the motors to actually finish spinning. Here’s a picture of the auton, and the functions that I use. (the strafe and turn functions are set up the same way as the drive function, they just have different + and - for the values)
This function simply sets the target for the motor, it does not block program execution until the movement finishes. The example code shows how to block until a movement is finished.
Ok I tried that code. Now what’s happening I think is it’s not exiting the first loop to move onto the turn command. It’ll just run whatever the first command is.
The PROS documentation for the move_relative function includes a method to fix this problem:
For your code, I would do something like this:
void drive(int inches, int speed){
leftFront.tare_position();
rightFront.tare_position();
leftBack.tare_position();
rightBack.tare_position();
leftFront.set_brake_mode(pros::E_MOTOR_BRAKE_COAST);
rightFront.set_brake_mode(pros::E_MOTOR_BRAKE_COAST);
leftBack.set_brake_mode(pros::E_MOTOR_BRAKE_COAST);
rightBack.set_brake_mode(pros::E_MOTOR_BRAKE_COAST);
leftFront.move_relative(inches * 50, speed);
rightFront.move_relative(inches * 50, speed);
leftBack.move_relative(inches * 50, speed);
rightBack.move_relative(inches * 50, speed);
double avgPos = (
leftFront.get_position() +
rightFront.get_position() +
leftBack.get_position() +
rightBack.get_position() ) / 4.0;
/**
* I'm using your inches to motor encoder unit distance conversion, along
* with a threshold of 20 motor encoder units for the loop to terminate
*/
while(abs(avgPos - inches * 50) > 20){
pros::delay(2);
avgPos = (
leftFront.get_position() +
rightFront.get_position() +
leftBack.get_position() +
rightBack.get_position() ) / 4.0;
}
}
In theory, this should delay the function from returning until the robot has moved to within the given threshold. I’m not sure if this is necessarily the best practice in this situation, but the PROS team presents this solution, so it should work fine for your needs.