new AutoFactory(
drive::getPose,
drive::resetOdometry,
- sample -> drive.setChassisSpeeds(sample.getChassisSpeeds(), false),
+ sample -> drive.setChassisVelocities(sample.getChassisVelocities(), false),
true,
drive,
(trajectory, startOrFinish) -> {
(pose) -> {
drive.resetOdometry(pose);
},
- () -> drive.getChassisSpeeds(),
+ () -> drive.getChassisVelocities(),
(chassisSpeeds) -> {
if (!Constants.DISABLE_LOGGING) {
- Logger.recordOutput("Auto/ChassisSpeeds", chassisSpeeds);
+ Logger.recordOutput("Auto/ChassisVelocities", chassisSpeeds);
}
- drive.setChassisSpeeds(chassisSpeeds, false); // problem??
+ drive.setChassisVelocities(chassisSpeeds, false); // problem??
},
AutoConstants.AUTO_CONTROLLER,
AutoConstants.CONFIG,
-package frc.robot.commands.auto_comm;
+// TODO: 2027-ALPHA-FIX - Re-enable Choreo vendordep when JSON is updated
+// package frc.robot.commands.auto_comm;
-import choreo.auto.AutoFactory;
-import org.wpilib.command2.Command;
-import org.wpilib.command2.Commands;
-import org.wpilib.command2.InstantCommand;
-import frc.robot.commands.DoNothing;
+// import choreo.auto.AutoFactory;
+// import org.wpilib.command2.Command;
+// import org.wpilib.command2.Commands;
+// import org.wpilib.command2.InstantCommand;
+// import frc.robot.commands.DoNothing;
-public class ChoreoPathCommandBuilder {
+// public class ChoreoPathCommandBuilder {
- public ChoreoPathCommandBuilder() {}
+// public ChoreoPathCommandBuilder() {}
- public static Command basicTrajectoryAuto(
- String pathName, boolean resetOdemetry, AutoFactory factory) {
- Command command = factory.trajectoryCmd(pathName);
+// public static Command basicTrajectoryAuto(
+// String pathName, boolean resetOdemetry, AutoFactory factory) {
+// Command command = factory.trajectoryCmd(pathName);
- return Commands.sequence(
- resetOdemetry ? new InstantCommand(() -> factory.resetOdometry(pathName)) : new DoNothing(),
- command);
- }
-}
+// return Commands.sequence(
+// resetOdemetry ? new InstantCommand(() -> factory.resetOdometry(pathName)) : new DoNothing(),
+// command);
+// }
+// }
package frc.robot.commands.drive_comm;
import org.wpilib.math.controller.PIDController;
-import org.wpilib.math.kinematics.ChassisSpeeds;
+import org.wpilib.math.kinematics.ChassisVelocities;
import org.wpilib.driverstation.DriverStation.Alliance;
import org.wpilib.smartdashboard.SmartDashboard;
import org.wpilib.command2.Command;
import org.wpilib.math.geometry.Pose2d;
import org.wpilib.math.geometry.Rotation2d;
import org.wpilib.math.geometry.Translation2d;
-import org.wpilib.math.kinematics.ChassisSpeeds;
+import org.wpilib.math.kinematics.ChassisVelocities;
import org.wpilib.math.trajectory.TrapezoidProfile;
import org.wpilib.math.util.Units;
import org.wpilib.command2.Command;
targetPose = target.get();
Pose2d currentPose = robot.get();
- ChassisSpeeds fieldVelocity =
- ChassisSpeeds.fromRobotRelativeSpeeds(drive.getChassisSpeeds(), currentPose.getRotation());
+ ChassisVelocities fieldVelocity =
+ ChassisVelocities.fromRobotRelativeSpeeds(drive.getChassisVelocities(), currentPose.getRotation());
Translation2d linearFieldVelocity =
new Translation2d(fieldVelocity.vxMetersPerSecond, fieldVelocity.vyMetersPerSecond);
// Calculate drive speed
double currentDistance = currentPose.getTranslation().getDistance(targetPose.getTranslation());
double ffScaler =
- MathUtil.clamp((currentDistance - ffMinRadius) / (ffMaxRadius - ffMinRadius), 0.0, 1.0);
+ Math.max(0.0, Math.min(1.0,(currentDistance - ffMinRadius) / (ffMaxRadius - ffMinRadius)));
driveErrorAbs = currentDistance;
driveController.reset(
lastSetpointTranslation.getDistance(targetPose.getTranslation()),
package frc.robot.commands.drive_comm;
import org.wpilib.math.geometry.Pose2d;
-import org.wpilib.math.kinematics.ChassisSpeeds;
+import org.wpilib.math.kinematics.ChassisVelocities;
import org.wpilib.math.kinematics.SwerveModuleState;
import org.wpilib.math.trajectory.Trajectory;
import org.wpilib.math.trajectory.Trajectory.State;
double angularVelo =
(nextPose.getRotation().getRadians() - initialPose.getRotation().getRadians()) / time;
- ChassisSpeeds chassisSpeeds = new ChassisSpeeds(xVelocity, yVelocity, angularVelo);
+ ChassisVelocities chassisSpeeds = new ChassisVelocities(xVelocity, yVelocity, angularVelo);
chassisSpeeds =
- ChassisSpeeds.fromFieldRelativeSpeeds(chassisSpeeds, initialPose.getRotation());
+ ChassisVelocities.fromFieldRelativeSpeeds(chassisSpeeds, initialPose.getRotation());
SwerveModuleState[] swerveModuleStates =
DriveConstants.KINEMATICS.toSwerveModuleStates(chassisSpeeds);
import java.util.function.Supplier;
import org.wpilib.math.util.MathUtil;
-import org.wpilib.math.kinematics.ChassisSpeeds;
+import org.wpilib.math.kinematics.ChassisVelocities;
import frc.robot.commands.drive_comm.DefaultDriveCommand;
import frc.robot.constants.VisionConstants;
import frc.robot.controls.BaseDriverConfig;
}
@Override
- protected void drive(ChassisSpeeds speeds) {
+ protected void drive(ChassisVelocities speeds) {
if (!VisionConstants.OBJECT_DETECTION_ENABLED) {
super.drive(speeds);
return;
import org.wpilib.math.geometry.Pose2d;
import org.wpilib.math.geometry.Translation2d;
-import org.wpilib.math.kinematics.ChassisSpeeds;
+import org.wpilib.math.kinematics.ChassisVelocities;
import org.wpilib.command2.Command;
import frc.robot.constants.Constants;
import frc.robot.subsystems.drivetrain.Drivetrain;
@Override
public void initialize() {
pose = poseSupplier.get();
- ChassisSpeeds v = drive.getChassisSpeeds();
+ ChassisVelocities v = drive.getChassisVelocities();
vx = v.vxMetersPerSecond;
vy = v.vyMetersPerSecond;
error = null;
import org.wpilib.math.geometry.Pose2d;
import org.wpilib.math.geometry.Rotation2d;
import org.wpilib.math.geometry.Translation2d;
-import org.wpilib.math.kinematics.ChassisSpeeds;
+import org.wpilib.math.kinematics.ChassisVelocities;
import org.wpilib.math.kinematics.SwerveDriveKinematics;
import org.wpilib.math.kinematics.SwerveModulePosition;
import org.wpilib.math.kinematics.SwerveModuleState;
private SwerveSetpoint currentSetpoint =
new SwerveSetpoint(
- new ChassisSpeeds(),
+ new ChassisVelocities(),
new SwerveModuleState[] {
new SwerveModuleState(),
new SwerveModuleState(),
public void drive(
double xSpeed, double ySpeed, double rot, boolean fieldRelative, boolean isOpenLoop) {
// rot = headingControl(rot, xSpeed, ySpeed);
- ChassisSpeeds speeds = ChassisSpeeds.discretize(xSpeed, ySpeed, rot, Constants.LOOP_TIME);
+ ChassisVelocities speeds = ChassisVelocities.discretize(xSpeed, ySpeed, rot, Constants.LOOP_TIME);
if (fieldRelative) {
- speeds = ChassisSpeeds.fromFieldRelativeSpeeds(speeds, getYaw());
+ speeds = ChassisVelocities.fromFieldRelativeSpeeds(speeds, getYaw());
}
- setChassisSpeeds(speeds, isOpenLoop);
+ setChassisVelocities(speeds, isOpenLoop);
}
/**
*/
public void driveHeading(double xSpeed, double ySpeed, double heading, boolean fieldRelative) {
double rot = rotationController.calculate(getYaw().getRadians(), heading);
- ChassisSpeeds speeds = new ChassisSpeeds(xSpeed, ySpeed, rot);
+ ChassisVelocities speeds = new ChassisVelocities(xSpeed, ySpeed, rot);
if (fieldRelative) {
- speeds = ChassisSpeeds.fromFieldRelativeSpeeds(speeds, getYaw());
+ speeds = ChassisVelocities.fromFieldRelativeSpeeds(speeds, getYaw());
}
- setChassisSpeeds(speeds, false);
+ setChassisVelocities(speeds, false);
}
/**
* @param chassisSpeeds the target chassis speeds
* @param isOpenLoop if open loop control should be used for the drive velocity
*/
- public void setChassisSpeeds(ChassisSpeeds chassisSpeeds, boolean isOpenLoop) {
+ public void setChassisVelocities(ChassisVelocities chassisSpeeds, boolean isOpenLoop) {
if (DriveConstants.USE_ACTUAL_SPEED) {
- SwerveSetpoint currentState = new SwerveSetpoint(getChassisSpeeds(), getModuleStates());
+ SwerveSetpoint currentState = new SwerveSetpoint(getChassisVelocities(), getModuleStates());
currentSetpoint =
setpointGenerator.generateSetpoint(
DriveConstants.MODULE_LIMITS,
/**
* Calculates chassis speed of drivetrain using the current SwerveModuleStates
*
- * @return ChassisSpeeds object This is often used as an input for other methods
+ * @return ChassisVelocities object This is often used as an input for other methods
*/
- public ChassisSpeeds getChassisSpeeds() {
- return DriveConstants.KINEMATICS.toChassisSpeeds(getModuleStates());
+ public ChassisVelocities getChassisVelocities() {
+ return DriveConstants.KINEMATICS.toChassisVelocities(getModuleStates());
}
/**
import org.wpilib.math.geometry.Transform3d;
import org.wpilib.math.geometry.Translation2d;
import org.wpilib.math.geometry.Twist2d;
-import org.wpilib.math.kinematics.ChassisSpeeds;
+import org.wpilib.math.kinematics.ChassisVelocities;
/** Geometry utilities for working with translations, rotations, transforms, and poses. */
public class GeomUtil {
}
/**
- * Converts a ChassisSpeeds to a Twist2d by extracting two dimensions (Y and Z). chain
+ * Converts a ChassisVelocities to a Twist2d by extracting two dimensions (Y and Z). chain
*
* @param speeds The original translation
* @return The resulting translation
*/
- public static Twist2d toTwist2d(ChassisSpeeds speeds) {
+ public static Twist2d toTwist2d(ChassisVelocities speeds) {
return new Twist2d(
speeds.vxMetersPerSecond, speeds.vyMetersPerSecond, speeds.omegaRadiansPerSecond);
}
package frc.robot.util.SwerveStuff;
-import org.wpilib.math.kinematics.ChassisSpeeds;
+import org.wpilib.math.kinematics.ChassisVelocities;
import org.wpilib.math.kinematics.SwerveModuleState;
-public record SwerveSetpoint(ChassisSpeeds chassisSpeeds, SwerveModuleState[] moduleStates) {}
+public record SwerveSetpoint(ChassisVelocities chassisSpeeds, SwerveModuleState[] moduleStates) {}
import org.wpilib.math.geometry.Rotation2d;
import org.wpilib.math.geometry.Translation2d;
import org.wpilib.math.geometry.Twist2d;
-import org.wpilib.math.kinematics.ChassisSpeeds;
+import org.wpilib.math.kinematics.ChassisVelocities;
import org.wpilib.math.kinematics.SwerveDriveKinematics;
import org.wpilib.math.kinematics.SwerveModuleState;
import java.util.ArrayList;
/**
* "Inspired" by FRC team 254. See the license file in the root directory of this project.
*
- * <p>Takes a prior setpoint (ChassisSpeeds), a desired setpoint (from a driver, or from a path
+ * <p>Takes a prior setpoint (ChassisVelocities), a desired setpoint (from a driver, or from a path
* follower), and outputs a new setpoint that respects all of the kinematic constraints on module
* rotation speed and wheel velocity/acceleration. By generating a new setpoint every iteration, the
* robot will converge to the desired setpoint quickly while avoiding any intermediate state that is
final ModuleLimits limits,
double centerOfMassHeight,
final SwerveSetpoint prevSetpoint,
- ChassisSpeeds desiredState,
+ ChassisVelocities desiredState,
double dt) {
final Translation2d[] modules = moduleLocations;
// Make sure desiredState respects velocity limits.
if (limits.maxDriveVelocity() > 0.0) {
SwerveDriveKinematics.desaturateWheelSpeeds(desiredModuleState, limits.maxDriveVelocity());
- desiredState = kinematics.toChassisSpeeds(desiredModuleState);
+ desiredState = kinematics.toChassisVelocities(desiredModuleState);
}
// Special case: desiredState is a complete stop. In this case, module angle is arbitrary, so
// It will (likely) be faster to stop the robot, rotate the modules in place to the complement
// of the desired
// angle, and accelerate again.
- return generateSetpoint(limits, centerOfMassHeight, prevSetpoint, new ChassisSpeeds(), dt);
+ return generateSetpoint(limits, centerOfMassHeight, prevSetpoint, new ChassisVelocities(), dt);
}
// Compute the deltas between start and goal. We can then interpolate from the start state to
}
}
- ChassisSpeeds retSpeeds =
- new ChassisSpeeds(
+ ChassisVelocities retSpeeds =
+ new ChassisVelocities(
prevSetpoint.chassisSpeeds().vxMetersPerSecond + min_s * dx,
prevSetpoint.chassisSpeeds().vyMetersPerSecond + min_s * dy,
prevSetpoint.chassisSpeeds().omegaRadiansPerSecond + min_s * dtheta);
import org.wpilib.math.geometry.Rotation3d;
import org.wpilib.math.geometry.Transform3d;
import org.wpilib.math.geometry.Translation3d;
-import org.wpilib.math.kinematics.ChassisSpeeds;
+import org.wpilib.math.kinematics.ChassisVelocities;
import org.wpilib.math.util.Units;
import org.wpilib.driverstation.DriverStation.Alliance;
import frc.robot.Robot;
* @return The relative angle in radians
*/
public double getVelocityRelativeAngle() {
- ChassisSpeeds speeds = drive.getChassisSpeeds();
+ ChassisVelocities speeds = drive.getChassisVelocities();
double angle =
getRelativeAngle() - Math.atan2(speeds.vyMetersPerSecond, speeds.vxMetersPerSecond);
return MathUtil.angleModulus(angle);
import org.wpilib.math.geometry.Pose2d;
import org.wpilib.math.geometry.Rotation2d;
import org.wpilib.math.geometry.Translation2d;
-import org.wpilib.math.kinematics.ChassisSpeeds;
+import org.wpilib.math.kinematics.ChassisVelocities;
import org.wpilib.math.trajectory.TrapezoidProfile;
import org.wpilib.math.trajectory.TrapezoidProfile.Constraints;
import org.wpilib.math.trajectory.TrapezoidProfile.State;
* @param keepAngle True to use the angle in the pose, false to point hte robot toward the pose
* @return The new speed
*/
- private static ChassisSpeeds calculate2(
- Drivetrain drive, ChassisSpeeds driverInput, Pose2d desiredPose, boolean keepAngle) {
+ private static ChassisVelocities calculate2(
+ Drivetrain drive, ChassisVelocities driverInput, Pose2d desiredPose, boolean keepAngle) {
// Do nothing if there is no pose
if (desiredPose == null) {
return driverInput;
// Store current states
Pose2d currentPose = drive.getPose();
Rotation2d yaw = drive.getYaw();
- ChassisSpeeds driveSpeeds = drive.getChassisSpeeds();
+ ChassisVelocities driveSpeeds = drive.getChassisVelocities();
driveSpeeds =
- ChassisSpeeds.fromFieldRelativeSpeeds(
+ ChassisVelocities.fromFieldRelativeSpeeds(
driveSpeeds,
- yaw); // Changing this does not cause problems because getChassisSpeeds() creates a new
+ yaw); // Changing this does not cause problems because getChassisVelocities() creates a new
// object
State xState = new State(currentPose.getX(), driveSpeeds.vxMetersPerSecond);
State yState = new State(currentPose.getY(), driveSpeeds.vyMetersPerSecond);
State angleGoal = new State(rotation, 0);
// Calculate ideal speeds for next frame
- ChassisSpeeds goal =
- new ChassisSpeeds(
+ ChassisVelocities goal =
+ new ChassisVelocities(
xProfile.calculate(Constants.LOOP_TIME, xState, xGoal).velocity,
yProfile.calculate(Constants.LOOP_TIME, yState, yGoal).velocity,
angleProfile.calculate(Constants.LOOP_TIME, angleState, angleGoal).velocity);
// Robot-relataive goal
- ChassisSpeeds goalRobot = goal.times(1);
- goalRobot = ChassisSpeeds.fromRobotRelativeSpeeds(goalRobot, yaw);
+ ChassisVelocities goalRobot = goal.times(1);
+ goalRobot = ChassisVelocities.fromRobotRelativeSpeeds(goalRobot, yaw);
// This calculates the actual acceleration we can get
// This is the only thing that needs to be robot relative
drive.getCurrSetpoint(),
goalRobot,
Constants.LOOP_TIME);
- ChassisSpeeds nextChassisSpeed = nextSetpoint.chassisSpeeds();
- nextChassisSpeed = ChassisSpeeds.fromRobotRelativeSpeeds(nextChassisSpeed, yaw);
+ ChassisVelocities nextChassisSpeed = nextSetpoint.chassisSpeeds();
+ nextChassisSpeed = ChassisVelocities.fromRobotRelativeSpeeds(nextChassisSpeed, yaw);
// Robot relative driver inputs
- ChassisSpeeds driverInputRobot = driverInput.times(1); // Copy so original doesn't change
- driverInputRobot = ChassisSpeeds.fromFieldRelativeSpeeds(driverInputRobot, yaw);
+ ChassisVelocities driverInputRobot = driverInput.times(1); // Copy so original doesn't change
+ driverInputRobot = ChassisVelocities.fromFieldRelativeSpeeds(driverInputRobot, yaw);
// This is the speed the driver will be able to get next frame
// Both speeds need to be obtainable in 1 frame or the driver speed will always be farther away
SwerveSetpoint driverSetpoint =
drive.getCurrSetpoint(),
driverInputRobot,
Constants.LOOP_TIME);
- ChassisSpeeds driverSpeeds = driverSetpoint.chassisSpeeds();
- driverSpeeds = ChassisSpeeds.fromRobotRelativeSpeeds(driverSpeeds, yaw);
+ ChassisVelocities driverSpeeds = driverSetpoint.chassisSpeeds();
+ driverSpeeds = ChassisVelocities.fromRobotRelativeSpeeds(driverSpeeds, yaw);
// The difference between the 2 speeds
- ChassisSpeeds error = nextChassisSpeed.minus(driverSpeeds);
+ ChassisVelocities error = nextChassisSpeed.minus(driverSpeeds);
// 1.2*1.2^-distance decreases the amount it correct by as distance increases
double distanceFactor =
Math.hypot(driverInput.vxMetersPerSecond, driverInput.vyMetersPerSecond);
// The amount to correct by
- ChassisSpeeds correction =
+ ChassisVelocities correction =
error.times(
Math.min(
CORRECTION_FACTOR * distanceFactor * driverInputSpeed / DriveConstants.MAX_SPEED,
*/
@SuppressWarnings(
"unused") // Needed because some code might not run for some values of DRIVER_ASSIST_MODE
- public static ChassisSpeeds calculate(
- Drivetrain drive, ChassisSpeeds driverInput, Pose2d desiredPose, boolean keepAngle) {
+ public static ChassisVelocities calculate(
+ Drivetrain drive, ChassisVelocities driverInput, Pose2d desiredPose, boolean keepAngle) {
if (VisionConstants.DRIVER_ASSIST_MODE < 2 || desiredPose == null) {
return driverInput;
} else if (VisionConstants.DRIVER_ASSIST_MODE == 2) {
* Math.sqrt(2 * DriveConstants.MAX_ANGULAR_ACCEL * Math.abs(rotationError))
- ROTATION_CORRECTION_FACTOR * driverInput.omegaRadiansPerSecond;
return driverInput.plus(
- new ChassisSpeeds(
+ new ChassisVelocities(
correctionSpeed * Math.cos(perpendicularAngle),
correctionSpeed * Math.sin(perpendicularAngle),
rotationalSpeed));