Skip to content

Commit

Permalink
almost done with holonomic controller
Browse files Browse the repository at this point in the history
  • Loading branch information
PGgit08 committed Jan 11, 2025
1 parent 101be8f commit 84562b2
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/main/java/frc/robot/utils/HolonomicController.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ public boolean atSetpoint() {
}

/** Resets the motion profile at the current drive pose and chassis speeds. */
public void reset(Pose2d currentPose, ChassisSpeeds currentSpeeds) {
// TODO translation
public void reset(Pose2d currentPose, Pose2d desiredPose, ChassisSpeeds currentSpeeds) {
_translationProfiled.reset(
currentPose.getTranslation().getDistance(desiredPose.getTranslation())
// TODO: how to reset speed?
);

_headingProfiled.reset(
currentPose.getRotation().getRadians(), currentSpeeds.omegaRadiansPerSecond);
}
Expand All @@ -67,7 +71,20 @@ public void reset(Pose2d currentPose, ChassisSpeeds currentSpeeds) {
* next timestep.
*/
public ChassisSpeeds calculate(Pose2d currentPose, Pose2d goalPose) {
return new ChassisSpeeds();
Transform2d transform = currentPose.minus(goalPose);

// vector where tail is at goal pose and head is at current pose
Vector<N2> difference = VecBuilder.fill(transform.getX(), transform.getY());

double velScalar = _translationProfiled.calculate(difference.norm(), 0);

Vector<N2> vel = difference.unit().times(velScalar);

return new ChassisSpeeds(
vel.get(0),
vel.get(1),
_headingController.calculate(
currentPose.getRotation().getRadians(), goalPose.getRotation().getRadians()));
}

/**
Expand Down

0 comments on commit 84562b2

Please sign in to comment.