Pure Pursuit: Mecanum
double movementP = 0.05,
angleP = 0.01;
public void moveToPosition(double targetXPos, double targetYPos, double targetAngle){
resetCache();
odometry.updatePosition();
double xDiff = targetXPos - odometry.getX();
double yDiff = targetYPos - odometry.getY();
double angleDiff = normalizeAngle(odometry.getAngle() - targetAngle);
driveFieldCentric(movementP*yDiff), angleP*angleDiff, movementP*xDiff);
driveFieldCentric(0, 0, 0);
}
public void driveFieldCentric(double drive, double turn, double strafe) {
// https://gm0.org/en/latest/docs/software/tutorials/mecanum-drive.html#field-centric
double fRightPow, bRightPow, fLeftPow, bLeftPow;
double botHeading = -Math.toRadians(normalizeAngle(odometry.getAngle()));
System.out.println(drive + " " + turn + " " + strafe);
double rotX = drive * Math.cos(botHeading) - strafe * Math.sin(botHeading);
double rotY = drive * Math.sin(botHeading) + strafe * Math.cos(botHeading);
double denominator = Math.max(Math.abs(strafe) + Math.abs(drive) + Math.abs(turn), 1);
fLeftPow = (rotY + rotX + turn) / denominator;
bLeftPow = (rotY - rotX + turn) / denominator;
fRightPow = (rotY - rotX - turn) / denominator;
bRightPow = (rotY + rotX - turn) / denominator;
setDrivePowers(bLeftPow, fLeftPow, bRightPow, fRightPow);
}
// Remaps the given angle into the range (-180, 180].
public static double normalizeAngle(double degrees) {
double normalized_angle = Angle.normalizePositive(degrees);
if (normalized_angle > 180) {
normalized_angle -= 360;
}
return normalized_angle;
}
Solving the Endpoint Issue
Alternative Implementation
Last updated