Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
angular acceleration & velocity constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
fcuellar13 authored and simonstoryparker committed Jan 3, 2025
1 parent 1f901be commit 487e089
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ public static ChassisSpeeds constrainLinearVelocity(

private static ChassisSpeeds constrainRotationalVelocity(
ChassisSpeeds inputSpeeds, AutoConstraintOptions options) {
// TODO: Implement rotational velocity constraint
double unconstrainedRotationalVelocity =
Math.hypot(inputSpeeds.vxMetersPerSecond, inputSpeeds.vyMetersPerSecond);
double currentAngularVelocity = inputSpeeds.omegaRadiansPerSecond;
if (currentAngularVelocity > options.maxAngularVelocity()) {
double clampingFactor = options.maxAngularVelocity() / currentAngularVelocity;
return new ChassisSpeeds(
inputSpeeds.vxMetersPerSecond,
inputSpeeds.vyMetersPerSecond,
inputSpeeds.omegaRadiansPerSecond * clampingFactor);
}

return inputSpeeds;
}
Expand Down Expand Up @@ -91,7 +96,21 @@ private static ChassisSpeeds constrainRotationalAcceleration(
ChassisSpeeds previousSpeeds,
double timeBetweenPreviousAndInputSpeeds,
AutoConstraintOptions options) {
// TODO: Implement angular acceleration constraint

double currentAngularSpeed = inputSpeeds.omegaRadiansPerSecond;
double previousAngularSpeed = previousSpeeds.omegaRadiansPerSecond;

double currentAngularAcceleration =
currentAngularSpeed - previousAngularSpeed / timeBetweenPreviousAndInputSpeeds;
if (currentAngularAcceleration > options.maxAngularAcceleration()) {
double constrainedAngularAcceleration =
previousAngularSpeed
+ options.maxAngularAcceleration() * timeBetweenPreviousAndInputSpeeds;
return new ChassisSpeeds(
inputSpeeds.vxMetersPerSecond,
inputSpeeds.vyMetersPerSecond,
constrainedAngularAcceleration);
}
return inputSpeeds;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void verifyRotationalAccelerationConstraints() {
new ChassisSpeeds(0.0, 0.0, -10.0),
new ChassisSpeeds(10.0, 10.0, 10.0),
new AutoConstraintOptions().withMaxAngularAcceleration(10.0),
new ChassisSpeeds(-7.5, 10.0, 10.0));
new ChassisSpeeds(10.0, 10.0, -7.5));
}

/** Verify that all constraints being applied on a complex problem at once works. */
Expand Down

0 comments on commit 487e089

Please sign in to comment.