Skip to content

Commit

Permalink
holonomic controller for following a trajectory
Browse files Browse the repository at this point in the history
  • Loading branch information
elvizer committed Jan 9, 2025
1 parent 98f4be7 commit c70cb3d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/frc/robot/utils/HolonomicController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package frc.robot.utils;

import choreo.trajectory.SwerveSample;
import edu.wpi.first.math.MathUtil;
import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.math.geometry.Pose2d;
Expand Down Expand Up @@ -47,4 +48,19 @@ public boolean atReference() {
public ChassisSpeeds calculate(State current, State goal, double t) {
return new ChassisSpeeds();
}

/**
* Calculates the next speeds for the robot using a sample from the trajectory.
* @param current The current state of the robot.
* @param sample A sample in a trajectory.
*/
public ChassisSpeeds calculate(State current, SwerveSample sample){
ChassisSpeeds targetSpeeds = sample.getChassisSpeeds();

targetSpeeds.vxMetersPerSecond += _xController.calculate(current.pose().getX(), sample.x);
targetSpeeds.vyMetersPerSecond += _yController.calculate(current.pose().getY(), sample.y);
targetSpeeds.omegaRadiansPerSecond += _headingController.calculate(current.pose().getRotation().getRadians(), sample.heading);

return targetSpeeds;
}
}

0 comments on commit c70cb3d

Please sign in to comment.