Hi! My team recently started working on PID to make our autonomous more consistent, and so far it has been working great. However, we have one function where we want to run our intakes at the same time as our wheel motors, and we want our intakes to move at a constant 100% velocity. For some reason, our function works perfectly the first and third time that it is called in our autonomous code, but the second time it is called, only the wheels move and the intakes do not move at all.
Here is the function:
void getBallPID(double target){
leftForward.setPosition(0,vex::rotationUnits::rev);
wait(750, msec);
while(drivePos < target){
drivePos = leftForward.position(vex::rotationUnits::rev);
error = target - drivePos;
integral = integral + error;
if(error <= 0){
integral = 0;
}
if(error > 25){
integral = 0;
}
derivative = error - prevError;
prevError = error;
power = ((error*kP) + (integral*kI) + (derivative*kD));
wait(15, msec);
leftForward.spin(vex::directionType::fwd,power,velocityUnits::rpm);
rightForward.spin(vex::directionType::fwd,power,velocityUnits::rpm);
leftBack.spin(vex::directionType::fwd,power,velocityUnits::rpm);
rightBack.spin(vex::directionType::fwd,power,velocityUnits::rpm);
intakeMotorLeft.spin(vex::directionType::fwd,100,velocityUnits::pct);
intakeMotorRight.spin(vex::directionType::fwd,100,velocityUnits::pct);
}
leftForward.stop(vex::brakeType::coast);
leftBack.stop(vex::brakeType::coast);
rightForward.stop(vex::brakeType::coast);
rightBack.stop(vex::brakeType::coast);
intakeMotorLeft.stop(vex::brakeType::coast);
intakeMotorRight.stop(vex::brakeType::coast);
}
And here is where it is called in our autonomous route.
void skills(){
//gets first ball
getBallPID(os);
//scores the preload in the first goal
inertiaTurnPID(-125);
bumpForward(60);
scoreBall(0.8, 100);
//gets second ball
backPID(0.65);
inertiaTurnPID(0.05);
forwardPID(2.5);
getBallPID(2.3);
//scores first ball/second goal
inertiaTurnPID(-90);
bumpForward(50);
scoreBall(0.85, 100);
//gets third ball
backPID(1.4);
inertiaTurnPID(0.1);
getBallPID(os*2);
I’m not sure if the problem is something really simple that I’m missing, so help is appreciated. Thank you!