How to do arc turns?

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!

Teams do this by using odometry, which uses X and y values instead of “drive this much, turn this much”. Basically the robot uses an imaginary coordinate grid.

Is arc turning basically like a drift-style turn? And does anyone know how to code for a turn while driving in autonomous using python?

You don’t need odometry to do a simple arc turn. You need odometry when following more complex paths such as bézier curves with a feedback controller.

For a simple arc turn you find the ratio of power between both sides by finding the distance each side needs to travel. When you follow an arc, the outer wheel will need to travel more distance in the same time so you find the distance both wheels travel, create a ratio, and multiply one side by that ratio. I have some sample code I may post later but looking at the current code I don’t think it’s correct.

4 Likes

By arc turning I mean that you make this movements :

Could the seperate PIDs create that ratio with the same kP and kD values? Since the current code calculates how far the outer wheel will need to travel and the inner wheel travels the “radius” used to calculate the length of the other arc. If not how can that ratio be implemented in to the current code?

Thank you for your help.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.