Advertisement
Trainlover08

Pure Pursuit Algorythm

Mar 7th, 2024 (edited)
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. int coordsX [] = {};
  2. int coordsY [] = {};
  3. int counter = 0;
  4. int setLookAhead = 60;
  5. float curveVelocityPenaltyCoef = 0.0;
  6. float driveVelocityTurnPenaltyCoef = 0.0;
  7. int width = 180;
  8. int trackWidth = 210;
  9. float lookAheadGain = 1.0;
  10.  
  11. while (true){
  12.     //psudo code for defining right and left x and y for the drive
  13.    
  14.     float lookAhead = setLookAhead * (curveVelocity * lookAheadGain);
  15.    
  16.     int l = (coordsX[counter] - robotX) ^ 2 + (coordsY[counter] - robotY) ^ 2;
  17.     float curvature = ( 2 * coordsX[counter] + .00000000001) / l;
  18.    
  19.     float side = sgn(sin(robotAngle) * (xLPos - xRPos) - cos(robotAngle) * (yLPos - yRPos));
  20.    
  21.     //to find the distance to the next point in the path, if less, then use it, if more, don't, keep the current one
  22.     if((sqrt((coordsX[counter + 1] - robotX) ^ 2 + (coordsY[counter + 1] - robotY) ^ 2)) < lookAhead){
  23.         counter++;
  24.     }
  25.    
  26.     float curveVelocity = curvature / (curveVelocityPenaltyCoef + 1);
  27.    
  28.     float leftDrive = (curveVelocity * ((2 + (curvature * trackWidth)) / 2));
  29.     float rightDrive = (curveVelocity * ((2 - (curvature * trackWidth)) / 2));
  30.    
  31.     //add PID to control motors
  32.        
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement