Skip to content

Commit

Permalink
AutoAlign fix
Browse files Browse the repository at this point in the history
  • Loading branch information
suryatho committed Feb 7, 2024
1 parent ddef4f0 commit 0c6ffb9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ spotless {
exclude "**/build/**", "**/build-*/**"
}
trimTrailingWhitespace()
indentWithSpaces(2)
indentWithSpaces(4)
endWithNewline()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public ChassisSpeeds update() {

// Control to setpoint
Pose2d currentPose = RobotState.getInstance().getEstimatedPose();
Twist2d fieldVelocity = RobotState.getInstance().fieldVelocity();

// Calculate feedback velocities (based on position error).
double linearVelocityScalar =
Expand All @@ -136,28 +135,16 @@ public ChassisSpeeds update() {
+ linearController.getSetpoint().velocity;
Rotation2d rotationToGoal =
goalPose.getTranslation().minus(currentPose.getTranslation()).getAngle();
double xVelocity = -linearVelocityScalar * rotationToGoal.getCos();
double yVelocity = -linearVelocityScalar * rotationToGoal.getSin();
Translation2d desiredLinearVelocity = new Translation2d(-linearVelocityScalar, rotationToGoal);

double angularVelocity =
thetaController.calculate(
currentPose.getRotation().getRadians(), goalPose.getRotation().getRadians())
+ thetaController.getSetpoint().velocity;

// Limit linear acceleration
Translation2d desiredLinearVelocity = new Translation2d(xVelocity, yVelocity);
Translation2d deltaVelocity = desiredLinearVelocity.minus(prevLinearVelocity);
double maxDeltaVelocity = maxLinearAcceleration.get() * 0.02;
if (deltaVelocity.getNorm() * 0.02 > maxDeltaVelocity) {
desiredLinearVelocity =
prevLinearVelocity.plus(
deltaVelocity.times(maxDeltaVelocity / deltaVelocity.getNorm() * 0.02));
}
prevLinearVelocity = new Translation2d(fieldVelocity.dx, fieldVelocity.dy);
xVelocity = desiredLinearVelocity.getX();
yVelocity = desiredLinearVelocity.getY();

ChassisSpeeds fieldRelativeSpeeds = new ChassisSpeeds(xVelocity, yVelocity, angularVelocity);
ChassisSpeeds fieldRelativeSpeeds =
new ChassisSpeeds(
desiredLinearVelocity.getX(), desiredLinearVelocity.getY(), angularVelocity);
Logger.recordOutput("AutoAlign/FieldRelativeSpeeds", fieldRelativeSpeeds);
Logger.recordOutput("AutoAlign/LinearError", linearController.getPositionError());
Logger.recordOutput("AutoAlign/RotationError", thetaController.getPositionError());
Expand Down

0 comments on commit 0c6ffb9

Please sign in to comment.