I have seen manty teams robot make arcs or arc turns. I was wondering how they do this? I wrote this function with what I think this how you do it haven’t had much time to test it yet :
double kP = 0;
double kD = 0;
void ArcPID(bool arcSideLeft,double angleofarc,double radius){
resetEncoders();
double arcError = 0;
double error = 0;
double arcDeriviate = 0;
double arcPrevError = 0;
double deriviate = 0;
double prevError = 0;
double arcMotorPower = 0;
double MotorPower = 0;
double arcDistance = M_PI * 2 * radius * angleofarc/360; // Calulate the distance of the arc
while(true){
double LeftPosition = (LF.position(deg) + LM.position(deg) + LR.position(deg))/3* leftToInches;
double RightPosition = (RF.position(deg) + RM.position(deg) + RR.position(deg))/3 * rightToInches;
if(arcSideLeft){
arcError = arcDistance-LeftPosition;
error = radius-RightPosition;
}
else{
arcError = arcDistance-RightPosition;
error = radius-LeftPosition;
}
arcDeriviate = arcError-arcPrevError;
deriviate = error- prevError;
MotorPower = error * kP + deriviate *kD;
arcMotorPower = arcError *kP + arcDeriviate * kD;
if(arcSideLeft){
LF.spin(vex::fwd,arcMotorPower,percent);
LM.spin(vex::fwd,arcMotorPower,percent);
LR.spin(vex::fwd,arcMotorPower,percent);
RF.spin(vex::fwd,MotorPower,percent);
RM.spin(vex::fwd,MotorPower,percent);
RR.spin(vex::fwd,MotorPower,percent);
}
else{
RF.spin(vex::fwd,arcMotorPower,percent);
RM.spin(vex::fwd,arcMotorPower,percent);
RR.spin(vex::fwd,arcMotorPower,percent);
LF.spin(vex::fwd,MotorPower,percent);
LM.spin(vex::fwd,MotorPower,percent);
LR.spin(vex::fwd,MotorPower,percent);
}
arcPrevError = arcError;
prevError = error;
if(fabs(error) < 1 & fabs(arcError) < 1){
break; // We have reached our values :)
}
task::sleep(15);
}
stopallmotors(hold);
}
Any help is appreciated!