From e0e774abde64272ff344aecdaaaee0a747195528 Mon Sep 17 00:00:00 2001
From: Gold856 <117957790+Gold856@users.noreply.github.com>
Date: Fri, 1 Aug 2025 02:05:42 -0400
Subject: [PATCH] [commands, wpimath] Remove Mecanum/SwerveControllerCommand
and HolonomicDriveController (#8119)
---
.../command/MecanumControllerCommand.java | 576 ------------------
.../command/SwerveControllerCommand.java | 236 -------
.../frc2/command/MecanumControllerCommand.cpp | 224 -------
.../frc2/command/MecanumControllerCommand.h | 269 --------
.../frc2/command/SwerveControllerCommand.h | 270 --------
.../command/MecanumControllerCommandTest.java | 142 -----
.../command/SwerveControllerCommandTest.java | 142 -----
.../command/MecanumControllerCommandTest.cpp | 135 ----
.../command/SwerveControllerCommandTest.cpp | 113 ----
wpilibcExamples/example_projects.bzl | 4 -
.../cpp/Constants.cpp | 22 -
.../MecanumControllerCommand/cpp/Robot.cpp | 72 ---
.../cpp/RobotContainer.cpp | 121 ----
.../cpp/subsystems/DriveSubsystem.cpp | 136 -----
.../include/Constants.h | 91 ---
.../MecanumControllerCommand/include/Robot.h | 32 -
.../include/RobotContainer.h | 48 --
.../include/subsystems/DriveSubsystem.h | 172 ------
.../SwerveControllerCommand/cpp/Constants.cpp | 12 -
.../SwerveControllerCommand/cpp/Robot.cpp | 72 ---
.../cpp/RobotContainer.cpp | 104 ----
.../cpp/subsystems/DriveSubsystem.cpp | 111 ----
.../cpp/subsystems/SwerveModule.cpp | 85 ---
.../include/Constants.h | 116 ----
.../SwerveControllerCommand/include/Robot.h | 32 -
.../include/RobotContainer.h | 43 --
.../include/subsystems/DriveSubsystem.h | 117 ----
.../include/subsystems/SwerveModule.h | 57 --
.../src/main/cpp/examples/examples.json | 36 --
.../cpp/MecanumControllerCommandTest.cpp | 64 --
.../MecanumControllerCommand/cpp/main.cpp | 16 -
.../cpp/SwerveControllerCommandTest.cpp | 69 ---
.../SwerveControllerCommand/cpp/main.cpp | 16 -
wpilibjExamples/example_projects.bzl | 2 -
.../wpi/first/wpilibj/examples/examples.json | 36 --
.../mecanumcontrollercommand/Constants.java | 87 ---
.../mecanumcontrollercommand/Main.java | 25 -
.../mecanumcontrollercommand/Robot.java | 100 ---
.../RobotContainer.java | 130 ----
.../subsystems/DriveSubsystem.java | 239 --------
.../swervecontrollercommand/Constants.java | 116 ----
.../swervecontrollercommand/Main.java | 25 -
.../swervecontrollercommand/Robot.java | 100 ---
.../RobotContainer.java | 120 ----
.../subsystems/DriveSubsystem.java | 179 ------
.../subsystems/SwerveModule.java | 137 -----
.../controller/HolonomicDriveController.java | 168 -----
.../kinematics/MecanumDriveMotorVoltages.java | 53 --
.../frc/controller/HolonomicDriveController.h | 218 -------
.../HolonomicDriveControllerTest.java | 85 ---
.../HolonomicDriveControllerTest.cpp | 67 --
51 files changed, 5642 deletions(-)
delete mode 100644 wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommand.java
delete mode 100644 wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommand.java
delete mode 100644 wpilibNewCommands/src/main/native/cpp/frc2/command/MecanumControllerCommand.cpp
delete mode 100644 wpilibNewCommands/src/main/native/include/frc2/command/MecanumControllerCommand.h
delete mode 100644 wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.h
delete mode 100644 wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommandTest.java
delete mode 100644 wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommandTest.java
delete mode 100644 wpilibNewCommands/src/test/native/cpp/frc2/command/MecanumControllerCommandTest.cpp
delete mode 100644 wpilibNewCommands/src/test/native/cpp/frc2/command/SwerveControllerCommandTest.cpp
delete mode 100644 wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Constants.cpp
delete mode 100644 wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Robot.cpp
delete mode 100644 wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp
delete mode 100644 wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp
delete mode 100644 wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Constants.h
delete mode 100644 wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Robot.h
delete mode 100644 wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/RobotContainer.h
delete mode 100644 wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/subsystems/DriveSubsystem.h
delete mode 100644 wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/Constants.cpp
delete mode 100644 wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/Robot.cpp
delete mode 100644 wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp
delete mode 100644 wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/DriveSubsystem.cpp
delete mode 100644 wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/subsystems/SwerveModule.cpp
delete mode 100644 wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/Constants.h
delete mode 100644 wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/Robot.h
delete mode 100644 wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/RobotContainer.h
delete mode 100644 wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/DriveSubsystem.h
delete mode 100644 wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/SwerveModule.h
delete mode 100644 wpilibcExamples/src/test/cpp/examples/MecanumControllerCommand/cpp/MecanumControllerCommandTest.cpp
delete mode 100644 wpilibcExamples/src/test/cpp/examples/MecanumControllerCommand/cpp/main.cpp
delete mode 100644 wpilibcExamples/src/test/cpp/examples/SwerveControllerCommand/cpp/SwerveControllerCommandTest.cpp
delete mode 100644 wpilibcExamples/src/test/cpp/examples/SwerveControllerCommand/cpp/main.cpp
delete mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/Constants.java
delete mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/Main.java
delete mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/Robot.java
delete mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/RobotContainer.java
delete mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/subsystems/DriveSubsystem.java
delete mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/Constants.java
delete mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/Main.java
delete mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/Robot.java
delete mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/RobotContainer.java
delete mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/subsystems/DriveSubsystem.java
delete mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/subsystems/SwerveModule.java
delete mode 100644 wpimath/src/main/java/edu/wpi/first/math/controller/HolonomicDriveController.java
delete mode 100644 wpimath/src/main/java/edu/wpi/first/math/kinematics/MecanumDriveMotorVoltages.java
delete mode 100644 wpimath/src/main/native/include/frc/controller/HolonomicDriveController.h
delete mode 100644 wpimath/src/test/java/edu/wpi/first/math/controller/HolonomicDriveControllerTest.java
delete mode 100644 wpimath/src/test/native/cpp/controller/HolonomicDriveControllerTest.cpp
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommand.java
deleted file mode 100644
index 65394cc0a6..0000000000
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommand.java
+++ /dev/null
@@ -1,576 +0,0 @@
-// Copyright (c) FIRST and other WPILib contributors.
-// Open Source Software; you can modify and/or share it under the terms of
-// the WPILib BSD license file in the root directory of this project.
-
-package edu.wpi.first.wpilibj2.command;
-
-import static edu.wpi.first.util.ErrorMessages.requireNonNullParam;
-
-import edu.wpi.first.math.controller.HolonomicDriveController;
-import edu.wpi.first.math.controller.PIDController;
-import edu.wpi.first.math.controller.ProfiledPIDController;
-import edu.wpi.first.math.controller.SimpleMotorFeedforward;
-import edu.wpi.first.math.geometry.Pose2d;
-import edu.wpi.first.math.geometry.Rotation2d;
-import edu.wpi.first.math.kinematics.ChassisSpeeds;
-import edu.wpi.first.math.kinematics.MecanumDriveKinematics;
-import edu.wpi.first.math.kinematics.MecanumDriveMotorVoltages;
-import edu.wpi.first.math.kinematics.MecanumDriveWheelSpeeds;
-import edu.wpi.first.math.trajectory.Trajectory;
-import edu.wpi.first.wpilibj.Timer;
-import java.util.function.Consumer;
-import java.util.function.Supplier;
-
-/**
- * A command that uses two PID controllers ({@link PIDController}) and a ProfiledPIDController
- * ({@link ProfiledPIDController}) to follow a trajectory {@link Trajectory} with a mecanum drive.
- *
- *
The command handles trajectory-following, Velocity PID calculations, and feedforwards
- * internally. This is intended to be a more-or-less "complete solution" that can be used by teams
- * without a great deal of controls expertise.
- *
- *
Advanced teams seeking more flexibility (for example, those who wish to use the onboard PID
- * functionality of a "smart" motor controller) may use the secondary constructor that omits the PID
- * and feedforward functionality, returning only the raw wheel speeds from the PID controllers.
- *
- *
The robot angle controller does not follow the angle given by the trajectory but rather goes
- * to the angle given in the final state of the trajectory.
- *
- *
This class is provided by the NewCommands VendorDep
- */
-@SuppressWarnings("removal")
-public class MecanumControllerCommand extends Command {
- private final Timer m_timer = new Timer();
- private final boolean m_usePID;
- private final Trajectory m_trajectory;
- private final Supplier m_pose;
- private final SimpleMotorFeedforward m_feedforward;
- private final MecanumDriveKinematics m_kinematics;
- private final HolonomicDriveController m_controller;
- private final Supplier m_desiredRotation;
- private final double m_maxWheelVelocity;
- private final PIDController m_frontLeftController;
- private final PIDController m_rearLeftController;
- private final PIDController m_frontRightController;
- private final PIDController m_rearRightController;
- private final Supplier m_currentWheelSpeeds;
- private final MecanumVoltagesConsumer m_outputDriveVoltages;
- private final Consumer m_outputWheelSpeeds;
- private double m_prevFrontLeftSpeedSetpoint; // m/s
- private double m_prevRearLeftSpeedSetpoint; // m/s
- private double m_prevFrontRightSpeedSetpoint; // m/s
- private double m_prevRearRightSpeedSetpoint; // m/s
-
- /**
- * Constructs a new MecanumControllerCommand that when executed will follow the provided
- * trajectory. PID control and feedforward are handled internally. Outputs are scaled from -12 to
- * 12 as a voltage output to the motor.
- *
- * Note: The controllers will *not* set the outputVolts to zero upon completion of the path
- * this is left to the user, since it is not appropriate for paths with nonstationary endstates.
- *
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one of the odometry classes to
- * provide this.
- * @param feedforward The feedforward to use for the drivetrain.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller for the robot's x position.
- * @param yController The Trajectory Tracker PID controller for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller for angle for the robot.
- * @param desiredRotation The angle that the robot should be facing. This is sampled at each time
- * step.
- * @param maxWheelVelocity The maximum velocity of a drivetrain wheel in m/s.
- * @param frontLeftController The front left wheel velocity PID.
- * @param rearLeftController The rear left wheel velocity PID.
- * @param frontRightController The front right wheel velocity PID.
- * @param rearRightController The rear right wheel velocity PID.
- * @param currentWheelSpeeds A MecanumDriveWheelSpeeds object containing the current wheel speeds.
- * @param outputDriveVoltages A MecanumVoltagesConsumer that consumes voltages of mecanum motors.
- * @param requirements The subsystems to require.
- */
- @SuppressWarnings("this-escape")
- public MecanumControllerCommand(
- Trajectory trajectory,
- Supplier pose,
- SimpleMotorFeedforward feedforward,
- MecanumDriveKinematics kinematics,
- PIDController xController,
- PIDController yController,
- ProfiledPIDController thetaController,
- Supplier desiredRotation,
- double maxWheelVelocity,
- PIDController frontLeftController,
- PIDController rearLeftController,
- PIDController frontRightController,
- PIDController rearRightController,
- Supplier currentWheelSpeeds,
- MecanumVoltagesConsumer outputDriveVoltages,
- Subsystem... requirements) {
- m_trajectory = requireNonNullParam(trajectory, "trajectory", "MecanumControllerCommand");
- m_pose = requireNonNullParam(pose, "pose", "MecanumControllerCommand");
- m_feedforward = requireNonNullParam(feedforward, "feedforward", "MecanumControllerCommand");
- m_kinematics = requireNonNullParam(kinematics, "kinematics", "MecanumControllerCommand");
-
- m_controller =
- new HolonomicDriveController(
- requireNonNullParam(xController, "xController", "MecanumControllerCommand"),
- requireNonNullParam(yController, "yController", "MecanumControllerCommand"),
- requireNonNullParam(thetaController, "thetaController", "MecanumControllerCommand"));
-
- m_desiredRotation =
- requireNonNullParam(desiredRotation, "desiredRotation", "MecanumControllerCommand");
-
- m_maxWheelVelocity = maxWheelVelocity;
-
- m_frontLeftController =
- requireNonNullParam(frontLeftController, "frontLeftController", "MecanumControllerCommand");
- m_rearLeftController =
- requireNonNullParam(rearLeftController, "rearLeftController", "MecanumControllerCommand");
- m_frontRightController =
- requireNonNullParam(
- frontRightController, "frontRightController", "MecanumControllerCommand");
- m_rearRightController =
- requireNonNullParam(rearRightController, "rearRightController", "MecanumControllerCommand");
-
- m_currentWheelSpeeds =
- requireNonNullParam(currentWheelSpeeds, "currentWheelSpeeds", "MecanumControllerCommand");
-
- m_outputDriveVoltages =
- requireNonNullParam(outputDriveVoltages, "outputDriveVoltages", "MecanumControllerCommand");
-
- m_outputWheelSpeeds = null;
-
- m_usePID = true;
-
- addRequirements(requirements);
- }
-
- /**
- * Constructs a new MecanumControllerCommand that when executed will follow the provided
- * trajectory. PID control and feedforward are handled internally. Outputs are scaled from -12 to
- * 12 as a voltage output to the motor.
- *
- * Note: The controllers will *not* set the outputVolts to zero upon completion of the path
- * this is left to the user, since it is not appropriate for paths with nonstationary endstates.
- *
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one of the odometry classes to
- * provide this.
- * @param feedforward The feedforward to use for the drivetrain.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller for the robot's x position.
- * @param yController The Trajectory Tracker PID controller for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller for angle for the robot.
- * @param desiredRotation The angle that the robot should be facing. This is sampled at each time
- * step.
- * @param maxWheelVelocityMetersPerSecond The maximum velocity of a drivetrain wheel.
- * @param frontLeftController The front left wheel velocity PID.
- * @param rearLeftController The rear left wheel velocity PID.
- * @param frontRightController The front right wheel velocity PID.
- * @param rearRightController The rear right wheel velocity PID.
- * @param currentWheelSpeeds A MecanumDriveWheelSpeeds object containing the current wheel speeds.
- * @param outputDriveVoltages A MecanumDriveMotorVoltages object containing the output motor
- * voltages.
- * @param requirements The subsystems to require.
- * @deprecated Use {@link MecanumVoltagesConsumer} instead of {@code
- * Consumer pose,
- SimpleMotorFeedforward feedforward,
- MecanumDriveKinematics kinematics,
- PIDController xController,
- PIDController yController,
- ProfiledPIDController thetaController,
- Supplier desiredRotation,
- double maxWheelVelocityMetersPerSecond,
- PIDController frontLeftController,
- PIDController rearLeftController,
- PIDController frontRightController,
- PIDController rearRightController,
- Supplier currentWheelSpeeds,
- Consumer outputDriveVoltages,
- Subsystem... requirements) {
- this(
- trajectory,
- pose,
- feedforward,
- kinematics,
- xController,
- yController,
- thetaController,
- desiredRotation,
- maxWheelVelocityMetersPerSecond,
- frontLeftController,
- rearLeftController,
- frontRightController,
- rearRightController,
- currentWheelSpeeds,
- (frontLeft, frontRight, rearLeft, rearRight) ->
- outputDriveVoltages.accept(
- new MecanumDriveMotorVoltages(frontLeft, frontRight, rearLeft, rearRight)),
- requirements);
- }
-
- /**
- * Constructs a new MecanumControllerCommand that when executed will follow the provided
- * trajectory. PID control and feedforward are handled internally. Outputs are scaled from -12 to
- * 12 as a voltage output to the motor.
- *
- * Note: The controllers will *not* set the outputVolts to zero upon completion of the path
- * this is left to the user, since it is not appropriate for paths with nonstationary endstates.
- *
- *
Note 2: The final rotation of the robot will be set to the rotation of the final pose in the
- * trajectory. The robot will not follow the rotations from the poses at each timestep. If
- * alternate rotation behavior is desired, the other constructor with a supplier for rotation
- * should be used.
- *
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one of the odometry classes to
- * provide this.
- * @param feedforward The feedforward to use for the drivetrain.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller for the robot's x position.
- * @param yController The Trajectory Tracker PID controller for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller for angle for the robot.
- * @param maxWheelVelocityMetersPerSecond The maximum velocity of a drivetrain wheel.
- * @param frontLeftController The front left wheel velocity PID.
- * @param rearLeftController The rear left wheel velocity PID.
- * @param frontRightController The front right wheel velocity PID.
- * @param rearRightController The rear right wheel velocity PID.
- * @param currentWheelSpeeds A MecanumDriveWheelSpeeds object containing the current wheel speeds.
- * @param outputDriveVoltages A MecanumVoltagesConsumer that consumes voltages of mecanum motors.
- * @param requirements The subsystems to require.
- */
- public MecanumControllerCommand(
- Trajectory trajectory,
- Supplier pose,
- SimpleMotorFeedforward feedforward,
- MecanumDriveKinematics kinematics,
- PIDController xController,
- PIDController yController,
- ProfiledPIDController thetaController,
- double maxWheelVelocityMetersPerSecond,
- PIDController frontLeftController,
- PIDController rearLeftController,
- PIDController frontRightController,
- PIDController rearRightController,
- Supplier currentWheelSpeeds,
- MecanumVoltagesConsumer outputDriveVoltages,
- Subsystem... requirements) {
- this(
- trajectory,
- pose,
- feedforward,
- kinematics,
- xController,
- yController,
- thetaController,
- () -> trajectory.getStates().get(trajectory.getStates().size() - 1).pose.getRotation(),
- maxWheelVelocityMetersPerSecond,
- frontLeftController,
- rearLeftController,
- frontRightController,
- rearRightController,
- currentWheelSpeeds,
- outputDriveVoltages,
- requirements);
- }
-
- /**
- * Constructs a new MecanumControllerCommand that when executed will follow the provided
- * trajectory. PID control and feedforward are handled internally. Outputs are scaled from -12 to
- * 12 as a voltage output to the motor.
- *
- * Note: The controllers will *not* set the outputVolts to zero upon completion of the path
- * this is left to the user, since it is not appropriate for paths with nonstationary endstates.
- *
- *
Note 2: The final rotation of the robot will be set to the rotation of the final pose in the
- * trajectory. The robot will not follow the rotations from the poses at each timestep. If
- * alternate rotation behavior is desired, the other constructor with a supplier for rotation
- * should be used.
- *
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one of the odometry classes to
- * provide this.
- * @param feedforward The feedforward to use for the drivetrain.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller for the robot's x position.
- * @param yController The Trajectory Tracker PID controller for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller for angle for the robot.
- * @param maxWheelVelocity The maximum velocity of a drivetrain wheel in m/s.
- * @param frontLeftController The front left wheel velocity PID.
- * @param rearLeftController The rear left wheel velocity PID.
- * @param frontRightController The front right wheel velocity PID.
- * @param rearRightController The rear right wheel velocity PID.
- * @param currentWheelSpeeds A MecanumDriveWheelSpeeds object containing the current wheel speeds.
- * @param outputDriveVoltages A MecanumDriveMotorVoltages object containing the output motor
- * voltages.
- * @param requirements The subsystems to require.
- * @deprecated Use {@link MecanumVoltagesConsumer} instead of {@code
- * Consumer}.
- */
- @Deprecated(since = "2025", forRemoval = true)
- public MecanumControllerCommand(
- Trajectory trajectory,
- Supplier pose,
- SimpleMotorFeedforward feedforward,
- MecanumDriveKinematics kinematics,
- PIDController xController,
- PIDController yController,
- ProfiledPIDController thetaController,
- double maxWheelVelocity,
- PIDController frontLeftController,
- PIDController rearLeftController,
- PIDController frontRightController,
- PIDController rearRightController,
- Supplier currentWheelSpeeds,
- Consumer outputDriveVoltages,
- Subsystem... requirements) {
- this(
- trajectory,
- pose,
- feedforward,
- kinematics,
- xController,
- yController,
- thetaController,
- maxWheelVelocity,
- frontLeftController,
- rearLeftController,
- frontRightController,
- rearRightController,
- currentWheelSpeeds,
- (frontLeft, frontRight, rearLeft, rearRight) ->
- outputDriveVoltages.accept(
- new MecanumDriveMotorVoltages(frontLeft, frontRight, rearLeft, rearRight)),
- requirements);
- }
-
- /**
- * Constructs a new MecanumControllerCommand that when executed will follow the provided
- * trajectory. The user should implement a velocity PID on the desired output wheel velocities.
- *
- * Note: The controllers will *not* set the outputVolts to zero upon completion of the path -
- * this is left to the user, since it is not appropriate for paths with nonstationary end-states.
- *
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one of the odometry classes to
- * provide this.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller for the robot's x position.
- * @param yController The Trajectory Tracker PID controller for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller for angle for the robot.
- * @param desiredRotation The angle that the robot should be facing. This is sampled at each time
- * step.
- * @param maxWheelVelocity The maximum velocity of a drivetrain wheel in m/s.
- * @param outputWheelSpeeds A MecanumDriveWheelSpeeds object containing the output wheel speeds.
- * @param requirements The subsystems to require.
- */
- @SuppressWarnings("this-escape")
- public MecanumControllerCommand(
- Trajectory trajectory,
- Supplier pose,
- MecanumDriveKinematics kinematics,
- PIDController xController,
- PIDController yController,
- ProfiledPIDController thetaController,
- Supplier desiredRotation,
- double maxWheelVelocity,
- Consumer outputWheelSpeeds,
- Subsystem... requirements) {
- m_trajectory = requireNonNullParam(trajectory, "trajectory", "MecanumControllerCommand");
- m_pose = requireNonNullParam(pose, "pose", "MecanumControllerCommand");
- m_feedforward = new SimpleMotorFeedforward(0, 0, 0);
- m_kinematics = requireNonNullParam(kinematics, "kinematics", "MecanumControllerCommand");
-
- m_controller =
- new HolonomicDriveController(
- requireNonNullParam(xController, "xController", "MecanumControllerCommand"),
- requireNonNullParam(yController, "yController", "MecanumControllerCommand"),
- requireNonNullParam(thetaController, "thetaController", "MecanumControllerCommand"));
-
- m_desiredRotation =
- requireNonNullParam(desiredRotation, "desiredRotation", "MecanumControllerCommand");
-
- m_maxWheelVelocity = maxWheelVelocity;
-
- m_frontLeftController = null;
- m_rearLeftController = null;
- m_frontRightController = null;
- m_rearRightController = null;
-
- m_currentWheelSpeeds = null;
-
- m_outputWheelSpeeds =
- requireNonNullParam(outputWheelSpeeds, "outputWheelSpeeds", "MecanumControllerCommand");
-
- m_outputDriveVoltages = null;
-
- m_usePID = false;
-
- addRequirements(requirements);
- }
-
- /**
- * Constructs a new MecanumControllerCommand that when executed will follow the provided
- * trajectory. The user should implement a velocity PID on the desired output wheel velocities.
- *
- * Note: The controllers will *not* set the outputVolts to zero upon completion of the path -
- * this is left to the user, since it is not appropriate for paths with nonstationary end-states.
- *
- *
Note 2: The final rotation of the robot will be set to the rotation of the final pose in the
- * trajectory. The robot will not follow the rotations from the poses at each timestep. If
- * alternate rotation behavior is desired, the other constructor with a supplier for rotation
- * should be used.
- *
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one of the odometry classes to
- * provide this.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller for the robot's x position.
- * @param yController The Trajectory Tracker PID controller for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller for angle for the robot.
- * @param maxWheelVelocity The maximum velocity of a drivetrain wheel.
- * @param outputWheelSpeeds A MecanumDriveWheelSpeeds object containing the output wheel speeds.
- * @param requirements The subsystems to require.
- */
- public MecanumControllerCommand(
- Trajectory trajectory,
- Supplier pose,
- MecanumDriveKinematics kinematics,
- PIDController xController,
- PIDController yController,
- ProfiledPIDController thetaController,
- double maxWheelVelocity,
- Consumer outputWheelSpeeds,
- Subsystem... requirements) {
- this(
- trajectory,
- pose,
- kinematics,
- xController,
- yController,
- thetaController,
- () -> trajectory.getStates().get(trajectory.getStates().size() - 1).pose.getRotation(),
- maxWheelVelocity,
- outputWheelSpeeds,
- requirements);
- }
-
- @Override
- public void initialize() {
- var initialState = m_trajectory.sample(0);
-
- var initialXVelocity = initialState.velocity * initialState.pose.getRotation().getCos();
- var initialYVelocity = initialState.velocity * initialState.pose.getRotation().getSin();
-
- MecanumDriveWheelSpeeds prevSpeeds =
- m_kinematics.toWheelSpeeds(new ChassisSpeeds(initialXVelocity, initialYVelocity, 0.0));
-
- m_prevFrontLeftSpeedSetpoint = prevSpeeds.frontLeft;
- m_prevRearLeftSpeedSetpoint = prevSpeeds.rearLeft;
- m_prevFrontRightSpeedSetpoint = prevSpeeds.frontRight;
- m_prevRearRightSpeedSetpoint = prevSpeeds.rearRight;
-
- m_timer.restart();
- }
-
- @Override
- public void execute() {
- double curTime = m_timer.get();
-
- var desiredState = m_trajectory.sample(curTime);
-
- var targetChassisSpeeds =
- m_controller.calculate(m_pose.get(), desiredState, m_desiredRotation.get());
- var targetWheelSpeeds = m_kinematics.toWheelSpeeds(targetChassisSpeeds);
-
- targetWheelSpeeds = targetWheelSpeeds.desaturate(m_maxWheelVelocity);
-
- double frontLeftSpeedSetpoint = targetWheelSpeeds.frontLeft;
- double rearLeftSpeedSetpoint = targetWheelSpeeds.rearLeft;
- double frontRightSpeedSetpoint = targetWheelSpeeds.frontRight;
- double rearRightSpeedSetpoint = targetWheelSpeeds.rearRight;
-
- double frontLeftOutput;
- double rearLeftOutput;
- double frontRightOutput;
- double rearRightOutput;
-
- if (m_usePID) {
- final double frontLeftFeedforward =
- m_feedforward.calculate(m_prevFrontLeftSpeedSetpoint, frontLeftSpeedSetpoint);
-
- final double rearLeftFeedforward =
- m_feedforward.calculate(m_prevRearLeftSpeedSetpoint, rearLeftSpeedSetpoint);
-
- final double frontRightFeedforward =
- m_feedforward.calculate(m_prevFrontRightSpeedSetpoint, frontRightSpeedSetpoint);
-
- final double rearRightFeedforward =
- m_feedforward.calculate(m_prevRearRightSpeedSetpoint, rearRightSpeedSetpoint);
-
- frontLeftOutput =
- frontLeftFeedforward
- + m_frontLeftController.calculate(
- m_currentWheelSpeeds.get().frontLeft, frontLeftSpeedSetpoint);
-
- rearLeftOutput =
- rearLeftFeedforward
- + m_rearLeftController.calculate(
- m_currentWheelSpeeds.get().rearLeft, rearLeftSpeedSetpoint);
-
- frontRightOutput =
- frontRightFeedforward
- + m_frontRightController.calculate(
- m_currentWheelSpeeds.get().frontRight, frontRightSpeedSetpoint);
-
- rearRightOutput =
- rearRightFeedforward
- + m_rearRightController.calculate(
- m_currentWheelSpeeds.get().rearRight, rearRightSpeedSetpoint);
-
- m_outputDriveVoltages.accept(
- frontLeftOutput, frontRightOutput, rearLeftOutput, rearRightOutput);
-
- } else {
- m_outputWheelSpeeds.accept(
- new MecanumDriveWheelSpeeds(
- frontLeftSpeedSetpoint,
- frontRightSpeedSetpoint,
- rearLeftSpeedSetpoint,
- rearRightSpeedSetpoint));
- }
- }
-
- @Override
- public void end(boolean interrupted) {
- m_timer.stop();
- }
-
- @Override
- public boolean isFinished() {
- return m_timer.hasElapsed(m_trajectory.getTotalTime());
- }
-
- /** A consumer to represent an operation on the voltages of a mecanum drive. */
- @FunctionalInterface
- public interface MecanumVoltagesConsumer {
- /**
- * Accepts the voltages to perform some operation with them.
- *
- * @param frontLeftVoltage The voltage of the front left motor.
- * @param frontRightVoltage The voltage of the front right motor.
- * @param rearLeftVoltage The voltage of the rear left motor.
- * @param rearRightVoltage The voltage of the rear left motor.
- */
- void accept(
- double frontLeftVoltage,
- double frontRightVoltage,
- double rearLeftVoltage,
- double rearRightVoltage);
- }
-}
diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommand.java
deleted file mode 100644
index 06d63ebb2e..0000000000
--- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommand.java
+++ /dev/null
@@ -1,236 +0,0 @@
-// Copyright (c) FIRST and other WPILib contributors.
-// Open Source Software; you can modify and/or share it under the terms of
-// the WPILib BSD license file in the root directory of this project.
-
-package edu.wpi.first.wpilibj2.command;
-
-import static edu.wpi.first.util.ErrorMessages.requireNonNullParam;
-
-import edu.wpi.first.math.controller.HolonomicDriveController;
-import edu.wpi.first.math.controller.PIDController;
-import edu.wpi.first.math.controller.ProfiledPIDController;
-import edu.wpi.first.math.geometry.Pose2d;
-import edu.wpi.first.math.geometry.Rotation2d;
-import edu.wpi.first.math.kinematics.SwerveDriveKinematics;
-import edu.wpi.first.math.kinematics.SwerveModuleState;
-import edu.wpi.first.math.trajectory.Trajectory;
-import edu.wpi.first.wpilibj.Timer;
-import java.util.function.Consumer;
-import java.util.function.Supplier;
-
-/**
- * A command that uses two PID controllers ({@link PIDController}) and a ProfiledPIDController
- * ({@link ProfiledPIDController}) to follow a trajectory {@link Trajectory} with a swerve drive.
- *
- * This command outputs the raw desired Swerve Module States ({@link SwerveModuleState}) in an
- * array. The desired wheel and module rotation velocities should be taken from those and used in
- * velocity PIDs.
- *
- *
The robot angle controller does not follow the angle given by the trajectory but rather goes
- * to the angle given in the final state of the trajectory.
- *
- *
This class is provided by the NewCommands VendorDep
- */
-public class SwerveControllerCommand extends Command {
- private final Timer m_timer = new Timer();
- private final Trajectory m_trajectory;
- private final Supplier m_pose;
- private final SwerveDriveKinematics m_kinematics;
- private final HolonomicDriveController m_controller;
- private final Consumer m_outputModuleStates;
- private final Supplier m_desiredRotation;
-
- /**
- * Constructs a new SwerveControllerCommand that when executed will follow the provided
- * trajectory. This command will not return output voltages but rather raw module states from the
- * position controllers which need to be put into a velocity PID.
- *
- * Note: The controllers will *not* set the outputVolts to zero upon completion of the path.
- * This is left to the user to do since it is not appropriate for paths with nonstationary
- * endstates.
- *
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one of the odometry classes to
- * provide this.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller for the robot's x position.
- * @param yController The Trajectory Tracker PID controller for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller for angle for the robot.
- * @param desiredRotation The angle that the drivetrain should be facing. This is sampled at each
- * time step.
- * @param outputModuleStates The raw output module states from the position controllers.
- * @param requirements The subsystems to require.
- */
- public SwerveControllerCommand(
- Trajectory trajectory,
- Supplier pose,
- SwerveDriveKinematics kinematics,
- PIDController xController,
- PIDController yController,
- ProfiledPIDController thetaController,
- Supplier desiredRotation,
- Consumer outputModuleStates,
- Subsystem... requirements) {
- this(
- trajectory,
- pose,
- kinematics,
- new HolonomicDriveController(
- requireNonNullParam(xController, "xController", "SwerveControllerCommand"),
- requireNonNullParam(yController, "yController", "SwerveControllerCommand"),
- requireNonNullParam(thetaController, "thetaController", "SwerveControllerCommand")),
- desiredRotation,
- outputModuleStates,
- requirements);
- }
-
- /**
- * Constructs a new SwerveControllerCommand that when executed will follow the provided
- * trajectory. This command will not return output voltages but rather raw module states from the
- * position controllers which need to be put into a velocity PID.
- *
- * Note: The controllers will *not* set the outputVolts to zero upon completion of the path.
- * This is left to the user since it is not appropriate for paths with nonstationary endstates.
- *
- *
Note 2: The final rotation of the robot will be set to the rotation of the final pose in the
- * trajectory. The robot will not follow the rotations from the poses at each timestep. If
- * alternate rotation behavior is desired, the other constructor with a supplier for rotation
- * should be used.
- *
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one of the odometry classes to
- * provide this.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller for the robot's x position.
- * @param yController The Trajectory Tracker PID controller for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller for angle for the robot.
- * @param outputModuleStates The raw output module states from the position controllers.
- * @param requirements The subsystems to require.
- */
- public SwerveControllerCommand(
- Trajectory trajectory,
- Supplier pose,
- SwerveDriveKinematics kinematics,
- PIDController xController,
- PIDController yController,
- ProfiledPIDController thetaController,
- Consumer outputModuleStates,
- Subsystem... requirements) {
- this(
- trajectory,
- pose,
- kinematics,
- xController,
- yController,
- thetaController,
- () -> trajectory.getStates().get(trajectory.getStates().size() - 1).pose.getRotation(),
- outputModuleStates,
- requirements);
- }
-
- /**
- * Constructs a new SwerveControllerCommand that when executed will follow the provided
- * trajectory. This command will not return output voltages but rather raw module states from the
- * position controllers which need to be put into a velocity PID.
- *
- * Note: The controllers will *not* set the outputVolts to zero upon completion of the path-
- * this is left to the user, since it is not appropriate for paths with nonstationary endstates.
- *
- *
Note 2: The final rotation of the robot will be set to the rotation of the final pose in the
- * trajectory. The robot will not follow the rotations from the poses at each timestep. If
- * alternate rotation behavior is desired, the other constructor with a supplier for rotation
- * should be used.
- *
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one of the odometry classes to
- * provide this.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param controller The HolonomicDriveController for the drivetrain.
- * @param outputModuleStates The raw output module states from the position controllers.
- * @param requirements The subsystems to require.
- */
- public SwerveControllerCommand(
- Trajectory trajectory,
- Supplier pose,
- SwerveDriveKinematics kinematics,
- HolonomicDriveController controller,
- Consumer outputModuleStates,
- Subsystem... requirements) {
- this(
- trajectory,
- pose,
- kinematics,
- controller,
- () -> trajectory.getStates().get(trajectory.getStates().size() - 1).pose.getRotation(),
- outputModuleStates,
- requirements);
- }
-
- /**
- * Constructs a new SwerveControllerCommand that when executed will follow the provided
- * trajectory. This command will not return output voltages but rather raw module states from the
- * position controllers which need to be put into a velocity PID.
- *
- * Note: The controllers will *not* set the outputVolts to zero upon completion of the path-
- * this is left to the user, since it is not appropriate for paths with nonstationary endstates.
- *
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one of the odometry classes to
- * provide this.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param controller The HolonomicDriveController for the drivetrain.
- * @param desiredRotation The angle that the drivetrain should be facing. This is sampled at each
- * time step.
- * @param outputModuleStates The raw output module states from the position controllers.
- * @param requirements The subsystems to require.
- */
- @SuppressWarnings("this-escape")
- public SwerveControllerCommand(
- Trajectory trajectory,
- Supplier pose,
- SwerveDriveKinematics kinematics,
- HolonomicDriveController controller,
- Supplier desiredRotation,
- Consumer outputModuleStates,
- Subsystem... requirements) {
- m_trajectory = requireNonNullParam(trajectory, "trajectory", "SwerveControllerCommand");
- m_pose = requireNonNullParam(pose, "pose", "SwerveControllerCommand");
- m_kinematics = requireNonNullParam(kinematics, "kinematics", "SwerveControllerCommand");
- m_controller = requireNonNullParam(controller, "controller", "SwerveControllerCommand");
-
- m_desiredRotation =
- requireNonNullParam(desiredRotation, "desiredRotation", "SwerveControllerCommand");
-
- m_outputModuleStates =
- requireNonNullParam(outputModuleStates, "outputModuleStates", "SwerveControllerCommand");
-
- addRequirements(requirements);
- }
-
- @Override
- public void initialize() {
- m_timer.restart();
- }
-
- @Override
- public void execute() {
- double curTime = m_timer.get();
- var desiredState = m_trajectory.sample(curTime);
-
- var targetChassisSpeeds =
- m_controller.calculate(m_pose.get(), desiredState, m_desiredRotation.get());
- var targetModuleStates = m_kinematics.toSwerveModuleStates(targetChassisSpeeds);
-
- m_outputModuleStates.accept(targetModuleStates);
- }
-
- @Override
- public void end(boolean interrupted) {
- m_timer.stop();
- }
-
- @Override
- public boolean isFinished() {
- return m_timer.hasElapsed(m_trajectory.getTotalTime());
- }
-}
diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/MecanumControllerCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/MecanumControllerCommand.cpp
deleted file mode 100644
index f08bab80e9..0000000000
--- a/wpilibNewCommands/src/main/native/cpp/frc2/command/MecanumControllerCommand.cpp
+++ /dev/null
@@ -1,224 +0,0 @@
-// Copyright (c) FIRST and other WPILib contributors.
-// Open Source Software; you can modify and/or share it under the terms of
-// the WPILib BSD license file in the root directory of this project.
-
-#include "frc2/command/MecanumControllerCommand.h"
-
-#include
-#include
-
-#include
-#include
-
-using namespace frc2;
-using kv_unit = units::compound_unit>;
-
-MecanumControllerCommand::MecanumControllerCommand(
- frc::Trajectory trajectory, std::function pose,
- frc::SimpleMotorFeedforward feedforward,
- frc::MecanumDriveKinematics kinematics, frc::PIDController xController,
- frc::PIDController yController,
- frc::ProfiledPIDController thetaController,
- std::function desiredRotation,
- units::meters_per_second_t maxWheelVelocity,
- std::function currentWheelSpeeds,
- frc::PIDController frontLeftController,
- frc::PIDController rearLeftController,
- frc::PIDController frontRightController,
- frc::PIDController rearRightController,
- std::function
- output,
- Requirements requirements)
- : m_trajectory(std::move(trajectory)),
- m_pose(std::move(pose)),
- m_feedforward(feedforward),
- m_kinematics(kinematics),
- m_controller(xController, yController, thetaController),
- m_desiredRotation(std::move(desiredRotation)),
- m_maxWheelVelocity(maxWheelVelocity),
- m_frontLeftController(
- std::make_unique(frontLeftController)),
- m_rearLeftController(
- std::make_unique(rearLeftController)),
- m_frontRightController(
- std::make_unique(frontRightController)),
- m_rearRightController(
- std::make_unique(rearRightController)),
- m_currentWheelSpeeds(std::move(currentWheelSpeeds)),
- m_outputVolts(std::move(output)),
- m_usePID(true) {
- AddRequirements(requirements);
-}
-
-MecanumControllerCommand::MecanumControllerCommand(
- frc::Trajectory trajectory, std::function pose,
- frc::SimpleMotorFeedforward feedforward,
- frc::MecanumDriveKinematics kinematics, frc::PIDController xController,
- frc::PIDController yController,
- frc::ProfiledPIDController thetaController,
- units::meters_per_second_t maxWheelVelocity,
- std::function currentWheelSpeeds,
- frc::PIDController frontLeftController,
- frc::PIDController rearLeftController,
- frc::PIDController frontRightController,
- frc::PIDController rearRightController,
- std::function
- output,
- Requirements requirements)
- : m_trajectory(std::move(trajectory)),
- m_pose(std::move(pose)),
- m_feedforward(feedforward),
- m_kinematics(kinematics),
- m_controller(xController, yController, thetaController),
- m_maxWheelVelocity(maxWheelVelocity),
- m_frontLeftController(
- std::make_unique(frontLeftController)),
- m_rearLeftController(
- std::make_unique(rearLeftController)),
- m_frontRightController(
- std::make_unique(frontRightController)),
- m_rearRightController(
- std::make_unique(rearRightController)),
- m_currentWheelSpeeds(std::move(currentWheelSpeeds)),
- m_outputVolts(std::move(output)),
- m_usePID(true) {
- AddRequirements(requirements);
-}
-
-MecanumControllerCommand::MecanumControllerCommand(
- frc::Trajectory trajectory, std::function pose,
- frc::MecanumDriveKinematics kinematics, frc::PIDController xController,
- frc::PIDController yController,
- frc::ProfiledPIDController thetaController,
- std::function desiredRotation,
- units::meters_per_second_t maxWheelVelocity,
- std::function
- output,
- Requirements requirements)
- : m_trajectory(std::move(trajectory)),
- m_pose(std::move(pose)),
- m_feedforward(0_V, units::unit_t{0}),
- m_kinematics(kinematics),
- m_controller(xController, yController, thetaController),
- m_desiredRotation(std::move(desiredRotation)),
- m_maxWheelVelocity(maxWheelVelocity),
- m_outputVel(std::move(output)),
- m_usePID(false) {
- AddRequirements(requirements);
-}
-
-MecanumControllerCommand::MecanumControllerCommand(
- frc::Trajectory trajectory, std::function pose,
- frc::MecanumDriveKinematics kinematics, frc::PIDController xController,
- frc::PIDController yController,
- frc::ProfiledPIDController thetaController,
- units::meters_per_second_t maxWheelVelocity,
- std::function
- output,
- Requirements requirements)
- : m_trajectory(std::move(trajectory)),
- m_pose(std::move(pose)),
- m_feedforward(0_V, units::unit_t{0}),
- m_kinematics(kinematics),
- m_controller(xController, yController, thetaController),
- m_maxWheelVelocity(maxWheelVelocity),
- m_outputVel(std::move(output)),
- m_usePID(false) {
- AddRequirements(requirements);
-}
-
-void MecanumControllerCommand::Initialize() {
- if (m_desiredRotation == nullptr) {
- m_desiredRotation = [&] {
- return m_trajectory.States().back().pose.Rotation();
- };
- }
- m_prevTime = 0_s;
- auto initialState = m_trajectory.Sample(0_s);
-
- auto initialXVelocity =
- initialState.velocity * initialState.pose.Rotation().Cos();
- auto initialYVelocity =
- initialState.velocity * initialState.pose.Rotation().Sin();
-
- m_prevSpeeds = m_kinematics.ToWheelSpeeds(
- frc::ChassisSpeeds{initialXVelocity, initialYVelocity, 0_rad_per_s});
-
- m_timer.Restart();
- if (m_usePID) {
- m_frontLeftController->Reset();
- m_rearLeftController->Reset();
- m_frontRightController->Reset();
- m_rearRightController->Reset();
- }
-}
-
-void MecanumControllerCommand::Execute() {
- auto curTime = m_timer.Get();
-
- auto m_desiredState = m_trajectory.Sample(curTime);
-
- auto targetChassisSpeeds =
- m_controller.Calculate(m_pose(), m_desiredState, m_desiredRotation());
- auto targetWheelSpeeds = m_kinematics.ToWheelSpeeds(targetChassisSpeeds);
-
- targetWheelSpeeds = targetWheelSpeeds.Desaturate(m_maxWheelVelocity);
-
- auto frontLeftSpeedSetpoint = targetWheelSpeeds.frontLeft;
- auto rearLeftSpeedSetpoint = targetWheelSpeeds.rearLeft;
- auto frontRightSpeedSetpoint = targetWheelSpeeds.frontRight;
- auto rearRightSpeedSetpoint = targetWheelSpeeds.rearRight;
-
- if (m_usePID) {
- auto frontLeftFeedforward =
- m_feedforward.Calculate(m_prevSpeeds.frontLeft, frontLeftSpeedSetpoint);
-
- auto rearLeftFeedforward =
- m_feedforward.Calculate(m_prevSpeeds.rearLeft, rearLeftSpeedSetpoint);
-
- auto frontRightFeedforward = m_feedforward.Calculate(
- m_prevSpeeds.frontRight, frontRightSpeedSetpoint);
-
- auto rearRightFeedforward =
- m_feedforward.Calculate(m_prevSpeeds.rearRight, rearRightSpeedSetpoint);
-
- auto frontLeftOutput = units::volt_t{m_frontLeftController->Calculate(
- m_currentWheelSpeeds().frontLeft.value(),
- frontLeftSpeedSetpoint.value())} +
- frontLeftFeedforward;
- auto rearLeftOutput = units::volt_t{m_rearLeftController->Calculate(
- m_currentWheelSpeeds().rearLeft.value(),
- rearLeftSpeedSetpoint.value())} +
- rearLeftFeedforward;
- auto frontRightOutput = units::volt_t{m_frontRightController->Calculate(
- m_currentWheelSpeeds().frontRight.value(),
- frontRightSpeedSetpoint.value())} +
- frontRightFeedforward;
- auto rearRightOutput = units::volt_t{m_rearRightController->Calculate(
- m_currentWheelSpeeds().rearRight.value(),
- rearRightSpeedSetpoint.value())} +
- rearRightFeedforward;
-
- m_outputVolts(frontLeftOutput, rearLeftOutput, frontRightOutput,
- rearRightOutput);
- } else {
- m_outputVel(frontLeftSpeedSetpoint, rearLeftSpeedSetpoint,
- frontRightSpeedSetpoint, rearRightSpeedSetpoint);
-
- m_prevTime = curTime;
- m_prevSpeeds = targetWheelSpeeds;
- }
-}
-
-void MecanumControllerCommand::End(bool interrupted) {
- m_timer.Stop();
-}
-
-bool MecanumControllerCommand::IsFinished() {
- return m_timer.HasElapsed(m_trajectory.TotalTime());
-}
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/MecanumControllerCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/MecanumControllerCommand.h
deleted file mode 100644
index c305054d1a..0000000000
--- a/wpilibNewCommands/src/main/native/include/frc2/command/MecanumControllerCommand.h
+++ /dev/null
@@ -1,269 +0,0 @@
-// Copyright (c) FIRST and other WPILib contributors.
-// Open Source Software; you can modify and/or share it under the terms of
-// the WPILib BSD license file in the root directory of this project.
-
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "frc2/command/Command.h"
-#include "frc2/command/CommandHelper.h"
-#include "frc2/command/Requirements.h"
-
-#pragma once
-
-namespace frc2 {
-/**
- * A command that uses two PID controllers (PIDController) and a profiled PID
- * controller (ProfiledPIDController) to follow a trajectory (Trajectory) with a
- * mecanum drive.
- *
- * The command handles trajectory-following,
- * Velocity PID calculations, and feedforwards internally. This
- * is intended to be a more-or-less "complete solution" that can be used by
- * teams without a great deal of controls expertise.
- *
- *
Advanced teams seeking more flexibility (for example, those who wish to
- * use the onboard PID functionality of a "smart" motor controller) may use the
- * secondary constructor that omits the PID and feedforward functionality,
- * returning only the raw wheel speeds from the PID controllers.
- *
- *
The robot angle controller does not follow the angle given by
- * the trajectory but rather goes to the angle given in the final state of the
- * trajectory.
- *
- * This class is provided by the NewCommands VendorDep
- */
-class MecanumControllerCommand
- : public CommandHelper {
- public:
- /**
- * Constructs a new MecanumControllerCommand that when executed will follow
- * the provided trajectory. PID control and feedforward are handled
- * internally. Outputs are scaled from -12 to 12 as a voltage output to the
- * motor.
- *
- * Note: The controllers will *not* set the outputVolts to zero upon
- * completion of the path this is left to the user, since it is not
- * appropriate for paths with nonstationary endstates.
- *
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose,
- * provided by the odometry class.
- * @param feedforward The feedforward to use for the drivetrain.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller
- * for the robot's x position.
- * @param yController The Trajectory Tracker PID controller
- * for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller
- * for angle for the robot.
- * @param desiredRotation The angle that the robot should be facing.
- * This is sampled at each time step.
- * @param maxWheelVelocity The maximum velocity of a drivetrain wheel.
- * @param frontLeftController The front left wheel velocity PID.
- * @param rearLeftController The rear left wheel velocity PID.
- * @param frontRightController The front right wheel velocity PID.
- * @param rearRightController The rear right wheel velocity PID.
- * @param currentWheelSpeeds A MecanumDriveWheelSpeeds object containing
- * the current wheel speeds.
- * @param output The output of the velocity PIDs.
- * @param requirements The subsystems to require.
- */
- MecanumControllerCommand(
- frc::Trajectory trajectory, std::function pose,
- frc::SimpleMotorFeedforward feedforward,
- frc::MecanumDriveKinematics kinematics, frc::PIDController xController,
- frc::PIDController yController,
- frc::ProfiledPIDController thetaController,
- std::function desiredRotation,
- units::meters_per_second_t maxWheelVelocity,
- std::function currentWheelSpeeds,
- frc::PIDController frontLeftController,
- frc::PIDController rearLeftController,
- frc::PIDController frontRightController,
- frc::PIDController rearRightController,
- std::function
- output,
- Requirements requirements = {});
-
- /**
- * Constructs a new MecanumControllerCommand that when executed will follow
- * the provided trajectory. PID control and feedforward are handled
- * internally. Outputs are scaled from -12 to 12 as a voltage output to the
- * motor.
- *
- * Note: The controllers will *not* set the outputVolts to zero upon
- * completion of the path this is left to the user, since it is not
- * appropriate for paths with nonstationary endstates.
- *
- *
Note 2: The final rotation of the robot will be set to the rotation of
- * the final pose in the trajectory. The robot will not follow the rotations
- * from the poses at each timestep. If alternate rotation behavior is desired,
- * the other constructor with a supplier for rotation should be used.
- *
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose,
- * provided by the odometry class.
- * @param feedforward The feedforward to use for the drivetrain.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller
- * for the robot's x position.
- * @param yController The Trajectory Tracker PID controller
- * for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller
- * for angle for the robot.
- * @param maxWheelVelocity The maximum velocity of a drivetrain wheel.
- * @param frontLeftController The front left wheel velocity PID.
- * @param rearLeftController The rear left wheel velocity PID.
- * @param frontRightController The front right wheel velocity PID.
- * @param rearRightController The rear right wheel velocity PID.
- * @param currentWheelSpeeds A MecanumDriveWheelSpeeds object containing
- * the current wheel speeds.
- * @param output The output of the velocity PIDs.
- * @param requirements The subsystems to require.
- */
- MecanumControllerCommand(
- frc::Trajectory trajectory, std::function pose,
- frc::SimpleMotorFeedforward feedforward,
- frc::MecanumDriveKinematics kinematics, frc::PIDController xController,
- frc::PIDController yController,
- frc::ProfiledPIDController thetaController,
- units::meters_per_second_t maxWheelVelocity,
- std::function currentWheelSpeeds,
- frc::PIDController frontLeftController,
- frc::PIDController rearLeftController,
- frc::PIDController frontRightController,
- frc::PIDController rearRightController,
- std::function
- output,
- Requirements requirements = {});
-
- /**
- * Constructs a new MecanumControllerCommand that when executed will follow
- * the provided trajectory. The user should implement a velocity PID on the
- * desired output wheel velocities.
- *
- * Note: The controllers will *not* set the outputVolts to zero upon
- * completion of the path - this is left to the user, since it is not
- * appropriate for paths with nonstationary end-states.
- *
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one
- * of the odometry classes to provide this.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller
- * for the robot's x position.
- * @param yController The Trajectory Tracker PID controller
- * for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller
- * for angle for the robot.
- * @param desiredRotation The angle that the robot should be facing.
- * This is sampled at each time step.
- * @param maxWheelVelocity The maximum velocity of a drivetrain wheel.
- * @param output The output of the position PIDs.
- * @param requirements The subsystems to require.
- */
- MecanumControllerCommand(
- frc::Trajectory trajectory, std::function pose,
- frc::MecanumDriveKinematics kinematics, frc::PIDController xController,
- frc::PIDController yController,
- frc::ProfiledPIDController thetaController,
- std::function desiredRotation,
- units::meters_per_second_t maxWheelVelocity,
- std::function
- output,
- Requirements requirements);
-
- /**
- * Constructs a new MecanumControllerCommand that when executed will follow
- * the provided trajectory. The user should implement a velocity PID on the
- * desired output wheel velocities.
- *
- * Note: The controllers will *not* set the outputVolts to zero upon
- * completion of the path - this is left to the user, since it is not
- * appropriate for paths with nonstationary end-states.
- *
- *
Note 2: The final rotation of the robot will be set to the rotation of
- * the final pose in the trajectory. The robot will not follow the rotations
- * from the poses at each timestep. If alternate rotation behavior is desired,
- * the other constructor with a supplier for rotation should be used.
- *
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose - use one
- * of the odometry classes to provide this.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller
- * for the robot's x position.
- * @param yController The Trajectory Tracker PID controller
- * for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller
- * for angle for the robot.
- * @param maxWheelVelocity The maximum velocity of a drivetrain wheel.
- * @param output The output of the position PIDs.
- * @param requirements The subsystems to require.
- */
- MecanumControllerCommand(
- frc::Trajectory trajectory, std::function pose,
- frc::MecanumDriveKinematics kinematics, frc::PIDController xController,
- frc::PIDController yController,
- frc::ProfiledPIDController thetaController,
- units::meters_per_second_t maxWheelVelocity,
- std::function
- output,
- Requirements requirements = {});
-
- void Initialize() override;
-
- void Execute() override;
-
- void End(bool interrupted) override;
-
- bool IsFinished() override;
-
- private:
- frc::Trajectory m_trajectory;
- std::function m_pose;
- frc::SimpleMotorFeedforward m_feedforward;
- frc::MecanumDriveKinematics m_kinematics;
- frc::HolonomicDriveController m_controller;
- std::function m_desiredRotation;
- const units::meters_per_second_t m_maxWheelVelocity;
- std::unique_ptr m_frontLeftController;
- std::unique_ptr m_rearLeftController;
- std::unique_ptr m_frontRightController;
- std::unique_ptr m_rearRightController;
- std::function m_currentWheelSpeeds;
- std::function
- m_outputVel;
- std::function
- m_outputVolts;
-
- bool m_usePID;
- frc::Timer m_timer;
- frc::MecanumDriveWheelSpeeds m_prevSpeeds;
- units::second_t m_prevTime;
-};
-} // namespace frc2
diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.h
deleted file mode 100644
index 75205e9928..0000000000
--- a/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.h
+++ /dev/null
@@ -1,270 +0,0 @@
-// Copyright (c) FIRST and other WPILib contributors.
-// Open Source Software; you can modify and/or share it under the terms of
-// the WPILib BSD license file in the root directory of this project.
-
-#include
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "frc2/command/Command.h"
-#include "frc2/command/CommandHelper.h"
-#include "frc2/command/Requirements.h"
-
-#pragma once
-
-namespace frc2 {
-
-/**
- * A command that uses two PID controllers (PIDController) and a profiled PID
- * controller (ProfiledPIDController) to follow a trajectory (Trajectory) with a
- * swerve drive.
- *
- * The command handles trajectory-following, Velocity PID calculations, and
- * feedforwards internally. This is intended to be a more-or-less "complete
- * solution" that can be used by teams without a great deal of controls
- * expertise.
- *
- *
Advanced teams seeking more flexibility (for example, those who wish to
- * use the onboard PID functionality of a "smart" motor controller) may use the
- * secondary constructor that omits the PID and feedforward functionality,
- * returning only the raw module states from the position PID controllers.
- *
- *
The robot angle controller does not follow the angle given by
- * the trajectory but rather goes to the angle given in the final state of the
- * trajectory.
- *
- * This class is provided by the NewCommands VendorDep
- */
-template
-class SwerveControllerCommand
- : public CommandHelper> {
- using voltsecondspermeter =
- units::compound_unit>;
- using voltsecondssquaredpermeter =
- units::compound_unit,
- units::inverse>;
-
- public:
- /**
- * Constructs a new SwerveControllerCommand that when executed will follow the
- * provided trajectory. This command will not return output voltages but
- * rather raw module states from the position controllers which need to be put
- * into a velocity PID.
- *
- * Note: The controllers will *not* set the outputVolts to zero upon
- * completion of the path- this is left to the user, since it is not
- * appropriate for paths with nonstationary endstates.
- *
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose,
- * provided by the odometry class.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller
- * for the robot's x position.
- * @param yController The Trajectory Tracker PID controller
- * for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller
- * for angle for the robot.
- * @param desiredRotation The angle that the drivetrain should be
- * facing. This is sampled at each time step.
- * @param output The raw output module states from the
- * position controllers.
- * @param requirements The subsystems to require.
- */
- SwerveControllerCommand(
- frc::Trajectory trajectory, std::function pose,
- frc::SwerveDriveKinematics kinematics,
- frc::PIDController xController, frc::PIDController yController,
- frc::ProfiledPIDController thetaController,
- std::function desiredRotation,
- std::function)>
- output,
- Requirements requirements = {})
- : m_trajectory(std::move(trajectory)),
- m_pose(std::move(pose)),
- m_kinematics(kinematics),
- m_controller(xController, yController, thetaController),
- m_desiredRotation(std::move(desiredRotation)),
- m_outputStates(output) {
- this->AddRequirements(requirements);
- }
-
- /**
- * Constructs a new SwerveControllerCommand that when executed will follow the
- * provided trajectory. This command will not return output voltages but
- * rather raw module states from the position controllers which need to be put
- * into a velocity PID.
- *
- * Note: The controllers will *not* set the outputVolts to zero upon
- * completion of the path- this is left to the user, since it is not
- * appropriate for paths with nonstationary endstates.
- *
- *
Note 2: The final rotation of the robot will be set to the rotation of
- * the final pose in the trajectory. The robot will not follow the rotations
- * from the poses at each timestep. If alternate rotation behavior is desired,
- * the other constructor with a supplier for rotation should be used.
- *
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose,
- * provided by the odometry class.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param xController The Trajectory Tracker PID controller
- * for the robot's x position.
- * @param yController The Trajectory Tracker PID controller
- * for the robot's y position.
- * @param thetaController The Trajectory Tracker PID controller
- * for angle for the robot.
- * @param output The raw output module states from the
- * position controllers.
- * @param requirements The subsystems to require.
- */
- SwerveControllerCommand(
- frc::Trajectory trajectory, std::function pose,
- frc::SwerveDriveKinematics kinematics,
- frc::PIDController xController, frc::PIDController yController,
- frc::ProfiledPIDController thetaController,
- std::function)>
- output,
- Requirements requirements = {})
- : m_trajectory(std::move(trajectory)),
- m_pose(std::move(pose)),
- m_kinematics(kinematics),
- m_controller(xController, yController, thetaController),
- m_outputStates(output) {
- this->AddRequirements(requirements);
- }
-
- /**
- * Constructs a new SwerveControllerCommand that when executed will follow the
- * provided trajectory. This command will not return output voltages but
- * rather raw module states from the position controllers which need to be put
- * into a velocity PID.
- *
- * Note: The controllers will *not* set the outputVolts to zero upon
- * completion of the path- this is left to the user, since it is not
- * appropriate for paths with nonstationary endstates.
- *
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose,
- * provided by the odometry class.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param controller The HolonomicDriveController for the drivetrain.
- * @param desiredRotation The angle that the drivetrain should be
- * facing. This is sampled at each time step.
- * @param output The raw output module states from the
- * position controllers.
- * @param requirements The subsystems to require.
- */
- SwerveControllerCommand(
- frc::Trajectory trajectory, std::function pose,
- frc::SwerveDriveKinematics kinematics,
- frc::HolonomicDriveController controller,
- std::function desiredRotation,
- std::function)>
- output,
- Requirements requirements = {})
- : m_trajectory(std::move(trajectory)),
- m_pose(std::move(pose)),
- m_kinematics(kinematics),
- m_controller(std::move(controller)),
- m_desiredRotation(std::move(desiredRotation)),
- m_outputStates(output) {
- this->AddRequirements(requirements);
- }
-
- /**
- * Constructs a new SwerveControllerCommand that when executed will follow the
- * provided trajectory. This command will not return output voltages but
- * rather raw module states from the position controllers which need to be put
- * into a velocity PID.
- *
- * Note: The controllers will *not* set the outputVolts to zero upon
- * completion of the path- this is left to the user, since it is not
- * appropriate for paths with nonstationary endstates.
- *
- *
Note 2: The final rotation of the robot will be set to the rotation of
- * the final pose in the trajectory. The robot will not follow the rotations
- * from the poses at each timestep. If alternate rotation behavior is desired,
- * the other constructor with a supplier for rotation should be used.
- *
- * @param trajectory The trajectory to follow.
- * @param pose A function that supplies the robot pose,
- * provided by the odometry class.
- * @param kinematics The kinematics for the robot drivetrain.
- * @param controller The HolonomicDriveController for the drivetrain.
- * @param output The raw output module states from the
- * position controllers.
- * @param requirements The subsystems to require.
- */
- SwerveControllerCommand(
- frc::Trajectory trajectory, std::function pose,
- frc::SwerveDriveKinematics kinematics,
- frc::HolonomicDriveController controller,
- std::function)>
- output,
- Requirements requirements = {})
- : m_trajectory(std::move(trajectory)),
- m_pose(std::move(pose)),
- m_kinematics(kinematics),
- m_controller(std::move(controller)),
- m_outputStates(output) {
- this->AddRequirements(requirements);
- }
-
- void Initialize() override {
- if (m_desiredRotation == nullptr) {
- m_desiredRotation = [&] {
- return m_trajectory.States().back().pose.Rotation();
- };
- }
- m_timer.Restart();
- }
-
- void Execute() override {
- auto curTime = m_timer.Get();
- auto m_desiredState = m_trajectory.Sample(curTime);
-
- auto targetChassisSpeeds =
- m_controller.Calculate(m_pose(), m_desiredState, m_desiredRotation());
- auto targetModuleStates =
- m_kinematics.ToSwerveModuleStates(targetChassisSpeeds);
-
- m_outputStates(targetModuleStates);
- }
-
- void End(bool interrupted) override { m_timer.Stop(); }
-
- bool IsFinished() override {
- return m_timer.HasElapsed(m_trajectory.TotalTime());
- }
-
- private:
- frc::Trajectory m_trajectory;
- std::function m_pose;
- frc::SwerveDriveKinematics m_kinematics;
- frc::HolonomicDriveController m_controller;
- std::function)>
- m_outputStates;
-
- std::function m_desiredRotation;
-
- frc::Timer m_timer;
- units::second_t m_prevTime;
- frc::Rotation2d m_finalRotation;
-};
-
-} // namespace frc2
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommandTest.java
deleted file mode 100644
index 5f5f3731f5..0000000000
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommandTest.java
+++ /dev/null
@@ -1,142 +0,0 @@
-// Copyright (c) FIRST and other WPILib contributors.
-// Open Source Software; you can modify and/or share it under the terms of
-// the WPILib BSD license file in the root directory of this project.
-
-package edu.wpi.first.wpilibj2.command;
-
-import static org.junit.jupiter.api.Assertions.assertAll;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import edu.wpi.first.hal.HAL;
-import edu.wpi.first.math.controller.PIDController;
-import edu.wpi.first.math.controller.ProfiledPIDController;
-import edu.wpi.first.math.geometry.Pose2d;
-import edu.wpi.first.math.geometry.Rotation2d;
-import edu.wpi.first.math.geometry.Translation2d;
-import edu.wpi.first.math.kinematics.MecanumDriveKinematics;
-import edu.wpi.first.math.kinematics.MecanumDriveOdometry;
-import edu.wpi.first.math.kinematics.MecanumDriveWheelPositions;
-import edu.wpi.first.math.kinematics.MecanumDriveWheelSpeeds;
-import edu.wpi.first.math.trajectory.TrajectoryConfig;
-import edu.wpi.first.math.trajectory.TrajectoryGenerator;
-import edu.wpi.first.math.trajectory.TrapezoidProfile;
-import edu.wpi.first.wpilibj.Timer;
-import edu.wpi.first.wpilibj.simulation.SimHooks;
-import java.util.ArrayList;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.parallel.ResourceLock;
-
-class MecanumControllerCommandTest {
- @BeforeEach
- void setupAll() {
- HAL.initialize(500, 0);
- SimHooks.pauseTiming();
- }
-
- @AfterEach
- void cleanupAll() {
- SimHooks.resumeTiming();
- }
-
- private final Timer m_timer = new Timer();
- private Rotation2d m_angle = Rotation2d.kZero;
-
- private double m_frontLeftSpeed;
- private double m_frontLeftDistance;
- private double m_rearLeftSpeed;
- private double m_rearLeftDistance;
- private double m_frontRightSpeed;
- private double m_frontRightDistance;
- private double m_rearRightSpeed;
- private double m_rearRightDistance;
-
- private final ProfiledPIDController m_rotController =
- new ProfiledPIDController(1, 0, 0, new TrapezoidProfile.Constraints(3 * Math.PI, Math.PI));
-
- private static final double kxTolerance = 1 / 12.0;
- private static final double kyTolerance = 1 / 12.0;
- private static final double kAngularTolerance = 1 / 12.0;
-
- private static final double kWheelBase = 0.5;
- private static final double kTrackwidth = 0.5;
-
- private final MecanumDriveKinematics m_kinematics =
- new MecanumDriveKinematics(
- new Translation2d(kWheelBase / 2, kTrackwidth / 2),
- new Translation2d(kWheelBase / 2, -kTrackwidth / 2),
- new Translation2d(-kWheelBase / 2, kTrackwidth / 2),
- new Translation2d(-kWheelBase / 2, -kTrackwidth / 2));
-
- private final MecanumDriveOdometry m_odometry =
- new MecanumDriveOdometry(
- m_kinematics, Rotation2d.kZero, new MecanumDriveWheelPositions(), Pose2d.kZero);
-
- public void setWheelSpeeds(MecanumDriveWheelSpeeds wheelSpeeds) {
- this.m_frontLeftSpeed = wheelSpeeds.frontLeft;
- this.m_rearLeftSpeed = wheelSpeeds.rearLeft;
- this.m_frontRightSpeed = wheelSpeeds.frontRight;
- this.m_rearRightSpeed = wheelSpeeds.rearRight;
- }
-
- public MecanumDriveWheelPositions getCurrentWheelDistances() {
- return new MecanumDriveWheelPositions(
- m_frontLeftDistance, m_frontRightDistance, m_rearLeftDistance, m_rearRightDistance);
- }
-
- public Pose2d getRobotPose() {
- m_odometry.update(m_angle, getCurrentWheelDistances());
- return m_odometry.getPose();
- }
-
- @Test
- @ResourceLock("timing")
- void testReachesReference() {
- final var subsystem = new Subsystem() {};
-
- final var waypoints = new ArrayList();
- waypoints.add(Pose2d.kZero);
- waypoints.add(new Pose2d(1, 5, new Rotation2d(3)));
- var config = new TrajectoryConfig(8.8, 0.1);
- final var trajectory = TrajectoryGenerator.generateTrajectory(waypoints, config);
-
- final var endState = trajectory.sample(trajectory.getTotalTime());
-
- final var command =
- new MecanumControllerCommand(
- trajectory,
- this::getRobotPose,
- m_kinematics,
- new PIDController(0.6, 0, 0),
- new PIDController(0.6, 0, 0),
- m_rotController,
- 8.8,
- this::setWheelSpeeds,
- subsystem);
-
- m_timer.restart();
-
- command.initialize();
- while (!command.isFinished()) {
- command.execute();
- m_angle = trajectory.sample(m_timer.get()).pose.getRotation();
- m_frontLeftDistance += m_frontLeftSpeed * 0.005;
- m_rearLeftDistance += m_rearLeftSpeed * 0.005;
- m_frontRightDistance += m_frontRightSpeed * 0.005;
- m_rearRightDistance += m_rearRightSpeed * 0.005;
- SimHooks.stepTiming(0.005);
- }
- m_timer.stop();
- command.end(true);
-
- assertAll(
- () -> assertEquals(endState.pose.getX(), getRobotPose().getX(), kxTolerance),
- () -> assertEquals(endState.pose.getY(), getRobotPose().getY(), kyTolerance),
- () ->
- assertEquals(
- endState.pose.getRotation().getRadians(),
- getRobotPose().getRotation().getRadians(),
- kAngularTolerance));
- }
-}
diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommandTest.java
deleted file mode 100644
index 2d91497f34..0000000000
--- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommandTest.java
+++ /dev/null
@@ -1,142 +0,0 @@
-// Copyright (c) FIRST and other WPILib contributors.
-// Open Source Software; you can modify and/or share it under the terms of
-// the WPILib BSD license file in the root directory of this project.
-
-package edu.wpi.first.wpilibj2.command;
-
-import static org.junit.jupiter.api.Assertions.assertAll;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import edu.wpi.first.hal.HAL;
-import edu.wpi.first.math.controller.PIDController;
-import edu.wpi.first.math.controller.ProfiledPIDController;
-import edu.wpi.first.math.geometry.Pose2d;
-import edu.wpi.first.math.geometry.Rotation2d;
-import edu.wpi.first.math.geometry.Translation2d;
-import edu.wpi.first.math.kinematics.SwerveDriveKinematics;
-import edu.wpi.first.math.kinematics.SwerveDriveOdometry;
-import edu.wpi.first.math.kinematics.SwerveModulePosition;
-import edu.wpi.first.math.kinematics.SwerveModuleState;
-import edu.wpi.first.math.trajectory.TrajectoryConfig;
-import edu.wpi.first.math.trajectory.TrajectoryGenerator;
-import edu.wpi.first.math.trajectory.TrapezoidProfile;
-import edu.wpi.first.wpilibj.Timer;
-import edu.wpi.first.wpilibj.simulation.SimHooks;
-import java.util.ArrayList;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.parallel.ResourceLock;
-
-class SwerveControllerCommandTest {
- @BeforeEach
- void setup() {
- HAL.initialize(500, 0);
- SimHooks.pauseTiming();
- }
-
- @AfterEach
- void cleanup() {
- SimHooks.resumeTiming();
- }
-
- private final Timer m_timer = new Timer();
- private Rotation2d m_angle = Rotation2d.kZero;
-
- private SwerveModuleState[] m_moduleStates =
- new SwerveModuleState[] {
- new SwerveModuleState(0, Rotation2d.kZero),
- new SwerveModuleState(0, Rotation2d.kZero),
- new SwerveModuleState(0, Rotation2d.kZero),
- new SwerveModuleState(0, Rotation2d.kZero)
- };
-
- private final SwerveModulePosition[] m_modulePositions =
- new SwerveModulePosition[] {
- new SwerveModulePosition(0, Rotation2d.kZero),
- new SwerveModulePosition(0, Rotation2d.kZero),
- new SwerveModulePosition(0, Rotation2d.kZero),
- new SwerveModulePosition(0, Rotation2d.kZero)
- };
-
- private final ProfiledPIDController m_rotController =
- new ProfiledPIDController(1, 0, 0, new TrapezoidProfile.Constraints(3 * Math.PI, Math.PI));
-
- private static final double kxTolerance = 1 / 12.0;
- private static final double kyTolerance = 1 / 12.0;
- private static final double kAngularTolerance = 1 / 12.0;
-
- private static final double kWheelBase = 0.5;
- private static final double kTrackwidth = 0.5;
-
- private final SwerveDriveKinematics m_kinematics =
- new SwerveDriveKinematics(
- new Translation2d(kWheelBase / 2, kTrackwidth / 2),
- new Translation2d(kWheelBase / 2, -kTrackwidth / 2),
- new Translation2d(-kWheelBase / 2, kTrackwidth / 2),
- new Translation2d(-kWheelBase / 2, -kTrackwidth / 2));
-
- private final SwerveDriveOdometry m_odometry =
- new SwerveDriveOdometry(m_kinematics, Rotation2d.kZero, m_modulePositions, Pose2d.kZero);
-
- @SuppressWarnings("PMD.ArrayIsStoredDirectly")
- public void setModuleStates(SwerveModuleState[] moduleStates) {
- this.m_moduleStates = moduleStates;
- }
-
- public Pose2d getRobotPose() {
- m_odometry.update(m_angle, m_modulePositions);
- return m_odometry.getPose();
- }
-
- @Test
- @ResourceLock("timing")
- void testReachesReference() {
- final var subsystem = new Subsystem() {};
-
- final var waypoints = new ArrayList();
- waypoints.add(Pose2d.kZero);
- waypoints.add(new Pose2d(1, 5, new Rotation2d(3)));
- var config = new TrajectoryConfig(8.8, 0.1);
- final var trajectory = TrajectoryGenerator.generateTrajectory(waypoints, config);
-
- final var endState = trajectory.sample(trajectory.getTotalTime());
-
- final var command =
- new SwerveControllerCommand(
- trajectory,
- this::getRobotPose,
- m_kinematics,
- new PIDController(0.6, 0, 0),
- new PIDController(0.6, 0, 0),
- m_rotController,
- this::setModuleStates,
- subsystem);
-
- m_timer.restart();
-
- command.initialize();
- while (!command.isFinished()) {
- command.execute();
- m_angle = trajectory.sample(m_timer.get()).pose.getRotation();
-
- for (int i = 0; i < m_modulePositions.length; i++) {
- m_modulePositions[i].distance += m_moduleStates[i].speed * 0.005;
- m_modulePositions[i].angle = m_moduleStates[i].angle;
- }
-
- SimHooks.stepTiming(0.005);
- }
- m_timer.stop();
- command.end(true);
-
- assertAll(
- () -> assertEquals(endState.pose.getX(), getRobotPose().getX(), kxTolerance),
- () -> assertEquals(endState.pose.getY(), getRobotPose().getY(), kyTolerance),
- () ->
- assertEquals(
- endState.pose.getRotation().getRadians(),
- getRobotPose().getRotation().getRadians(),
- kAngularTolerance));
- }
-}
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/MecanumControllerCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/MecanumControllerCommandTest.cpp
deleted file mode 100644
index 04af56a682..0000000000
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/MecanumControllerCommandTest.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-// Copyright (c) FIRST and other WPILib contributors.
-// Open Source Software; you can modify and/or share it under the terms of
-// the WPILib BSD license file in the root directory of this project.
-
-#include
-#include
-
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "CommandTestBase.h"
-
-#define EXPECT_NEAR_UNITS(val1, val2, eps) \
- EXPECT_LE(units::math::abs(val1 - val2), eps)
-
-class MecanumControllerCommandTest : public ::testing::Test {
- using radians_per_second_squared_t =
- units::compound_unit>>;
-
- protected:
- frc::Timer m_timer;
- frc::Rotation2d m_angle{0_rad};
-
- units::meters_per_second_t m_frontLeftSpeed = 0.0_mps;
- units::meter_t m_frontLeftDistance = 0.0_m;
- units::meters_per_second_t m_rearLeftSpeed = 0.0_mps;
- units::meter_t m_rearLeftDistance = 0.0_m;
- units::meters_per_second_t m_frontRightSpeed = 0.0_mps;
- units::meter_t m_frontRightDistance = 0.0_m;
- units::meters_per_second_t m_rearRightSpeed = 0.0_mps;
- units::meter_t m_rearRightDistance = 0.0_m;
-
- frc::ProfiledPIDController m_rotController{
- 1, 0, 0,
- frc::TrapezoidProfile::Constraints{
- 9_rad_per_s, units::unit_t(3)}};
-
- static constexpr units::meter_t kxTolerance{1 / 12.0};
- static constexpr units::meter_t kyTolerance{1 / 12.0};
- static constexpr units::radian_t kAngularTolerance{1 / 12.0};
-
- static constexpr units::meter_t kWheelBase{0.5};
- static constexpr units::meter_t kTrackwidth{0.5};
-
- frc::MecanumDriveKinematics m_kinematics{
- frc::Translation2d{kWheelBase / 2, kTrackwidth / 2},
- frc::Translation2d{kWheelBase / 2, -kTrackwidth / 2},
- frc::Translation2d{-kWheelBase / 2, kTrackwidth / 2},
- frc::Translation2d{-kWheelBase / 2, -kTrackwidth / 2}};
-
- frc::MecanumDriveOdometry m_odometry{m_kinematics, 0_rad,
- getCurrentWheelDistances(),
- frc::Pose2d{0_m, 0_m, 0_rad}};
-
- void SetUp() override { frc::sim::PauseTiming(); }
-
- void TearDown() override { frc::sim::ResumeTiming(); }
-
- frc::MecanumDriveWheelSpeeds getCurrentWheelSpeeds() {
- return frc::MecanumDriveWheelSpeeds{m_frontLeftSpeed, m_frontRightSpeed,
- m_rearLeftSpeed, m_rearRightSpeed};
- }
-
- frc::MecanumDriveWheelPositions getCurrentWheelDistances() {
- return frc::MecanumDriveWheelPositions{
- m_frontLeftDistance,
- m_rearLeftDistance,
- m_frontRightDistance,
- m_rearRightDistance,
- };
- }
-
- frc::Pose2d getRobotPose() {
- m_odometry.Update(m_angle, getCurrentWheelDistances());
- return m_odometry.GetPose();
- }
-};
-
-TEST_F(MecanumControllerCommandTest, ReachesReference) {
- frc2::TestSubsystem subsystem;
-
- auto waypoints =
- std::vector{frc::Pose2d{0_m, 0_m, 0_rad}, frc::Pose2d{1_m, 5_m, 3_rad}};
- auto trajectory = frc::TrajectoryGenerator::GenerateTrajectory(
- waypoints, {8.8_mps, 0.1_mps_sq});
-
- auto endState = trajectory.Sample(trajectory.TotalTime());
-
- auto command = frc2::MecanumControllerCommand(
- trajectory, [&]() { return getRobotPose(); }, m_kinematics,
-
- frc::PIDController(0.6, 0, 0), frc::PIDController(0.6, 0, 0),
- m_rotController, 8.8_mps,
- [&](units::meters_per_second_t frontLeft,
- units::meters_per_second_t rearLeft,
- units::meters_per_second_t frontRight,
- units::meters_per_second_t rearRight) {
- m_frontLeftSpeed = frontLeft;
- m_rearLeftSpeed = rearLeft;
- m_frontRightSpeed = frontRight;
- m_rearRightSpeed = rearRight;
- },
- {&subsystem});
-
- m_timer.Restart();
-
- command.Initialize();
- while (!command.IsFinished()) {
- command.Execute();
- m_angle = trajectory.Sample(m_timer.Get()).pose.Rotation();
- m_frontLeftDistance += m_frontLeftSpeed * 5_ms;
- m_rearLeftDistance += m_rearLeftSpeed * 5_ms;
- m_frontRightDistance += m_frontRightSpeed * 5_ms;
- m_rearRightDistance += m_rearRightSpeed * 5_ms;
- frc::sim::StepTiming(5_ms);
- }
- m_timer.Stop();
- command.End(false);
-
- EXPECT_NEAR_UNITS(endState.pose.X(), getRobotPose().X(), kxTolerance);
- EXPECT_NEAR_UNITS(endState.pose.Y(), getRobotPose().Y(), kyTolerance);
- EXPECT_NEAR_UNITS(endState.pose.Rotation().Radians(),
- getRobotPose().Rotation().Radians(), kAngularTolerance);
-}
diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/SwerveControllerCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/SwerveControllerCommandTest.cpp
deleted file mode 100644
index 82036514e4..0000000000
--- a/wpilibNewCommands/src/test/native/cpp/frc2/command/SwerveControllerCommandTest.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright (c) FIRST and other WPILib contributors.
-// Open Source Software; you can modify and/or share it under the terms of
-// the WPILib BSD license file in the root directory of this project.
-
-#include
-#include
-
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "CommandTestBase.h"
-
-#define EXPECT_NEAR_UNITS(val1, val2, eps) \
- EXPECT_LE(units::math::abs(val1 - val2), eps)
-
-class SwerveControllerCommandTest : public ::testing::Test {
- using radians_per_second_squared_t =
- units::compound_unit>>;
-
- protected:
- frc::Timer m_timer;
- frc::Rotation2d m_angle{0_rad};
-
- wpi::array m_moduleStates{
- frc::SwerveModuleState{}, frc::SwerveModuleState{},
- frc::SwerveModuleState{}, frc::SwerveModuleState{}};
-
- wpi::array m_modulePositions{
- frc::SwerveModulePosition{}, frc::SwerveModulePosition{},
- frc::SwerveModulePosition{}, frc::SwerveModulePosition{}};
-
- frc::ProfiledPIDController m_rotController{
- 1, 0, 0,
- frc::TrapezoidProfile::Constraints{
- 9_rad_per_s, units::unit_t(3)}};
-
- static constexpr units::meter_t kxTolerance{1 / 12.0};
- static constexpr units::meter_t kyTolerance{1 / 12.0};
- static constexpr units::radian_t kAngularTolerance{1 / 12.0};
-
- static constexpr units::meter_t kWheelBase{0.5};
- static constexpr units::meter_t kTrackwidth{0.5};
-
- frc::SwerveDriveKinematics<4> m_kinematics{
- frc::Translation2d{kWheelBase / 2, kTrackwidth / 2},
- frc::Translation2d{kWheelBase / 2, -kTrackwidth / 2},
- frc::Translation2d{-kWheelBase / 2, kTrackwidth / 2},
- frc::Translation2d{-kWheelBase / 2, -kTrackwidth / 2}};
-
- frc::SwerveDriveOdometry<4> m_odometry{m_kinematics, 0_rad, m_modulePositions,
- frc::Pose2d{0_m, 0_m, 0_rad}};
-
- void SetUp() override { frc::sim::PauseTiming(); }
-
- void TearDown() override { frc::sim::ResumeTiming(); }
-
- frc::Pose2d getRobotPose() {
- m_odometry.Update(m_angle, m_modulePositions);
- return m_odometry.GetPose();
- }
-};
-
-TEST_F(SwerveControllerCommandTest, ReachesReference) {
- frc2::TestSubsystem subsystem;
-
- auto waypoints =
- std::vector{frc::Pose2d{0_m, 0_m, 0_rad}, frc::Pose2d{1_m, 5_m, 3_rad}};
- auto trajectory = frc::TrajectoryGenerator::GenerateTrajectory(
- waypoints, {8.8_mps, 0.1_mps_sq});
-
- auto endState = trajectory.Sample(trajectory.TotalTime());
-
- auto command = frc2::SwerveControllerCommand<4>(
- trajectory, [&]() { return getRobotPose(); }, m_kinematics,
-
- frc::PIDController(0.6, 0, 0), frc::PIDController(0.6, 0, 0),
- m_rotController,
- [&](auto moduleStates) { m_moduleStates = moduleStates; }, {&subsystem});
-
- m_timer.Restart();
-
- command.Initialize();
- while (!command.IsFinished()) {
- command.Execute();
- m_angle = trajectory.Sample(m_timer.Get()).pose.Rotation();
-
- for (size_t i = 0; i < m_modulePositions.size(); i++) {
- m_modulePositions[i].distance += m_moduleStates[i].speed * 5_ms;
- m_modulePositions[i].angle = m_moduleStates[i].angle;
- }
-
- frc::sim::StepTiming(5_ms);
- }
- m_timer.Stop();
- command.End(false);
-
- EXPECT_NEAR_UNITS(endState.pose.X(), getRobotPose().X(), kxTolerance);
- EXPECT_NEAR_UNITS(endState.pose.Y(), getRobotPose().Y(), kyTolerance);
- EXPECT_NEAR_UNITS(endState.pose.Rotation().Radians(),
- getRobotPose().Rotation().Radians(), kAngularTolerance);
-}
diff --git a/wpilibcExamples/example_projects.bzl b/wpilibcExamples/example_projects.bzl
index 62f18905fe..76c832a726 100644
--- a/wpilibcExamples/example_projects.bzl
+++ b/wpilibcExamples/example_projects.bzl
@@ -30,7 +30,6 @@ EXAMPLE_FOLDERS = [
"I2CCommunication",
"IntermediateVision",
"MecanumBot",
- "MecanumControllerCommand",
"MecanumDrive",
"MecanumDrivePoseEstimator",
"Mechanism2d",
@@ -47,7 +46,6 @@ EXAMPLE_FOLDERS = [
"StateSpaceFlywheel",
"StateSpaceFlywheelSysId",
"SwerveBot",
- "SwerveControllerCommand",
"SwerveDrivePoseEstimator",
"SysIdRoutine",
"TankDrive",
@@ -99,8 +97,6 @@ TESTS_FOLDERS = [
"DigitalCommunication",
"ElevatorSimulation",
"I2CCommunication",
- "MecanumControllerCommand",
"PotentiometerPID",
- "SwerveControllerCommand",
"UnitTest",
]
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Constants.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Constants.cpp
deleted file mode 100644
index 9fd38043e1..0000000000
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Constants.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright (c) FIRST and other WPILib contributors.
-// Open Source Software; you can modify and/or share it under the terms of
-// the WPILib BSD license file in the root directory of this project.
-
-#include "Constants.h"
-
-namespace DriveConstants {
-
-const frc::MecanumDriveKinematics kDriveKinematics{
- frc::Translation2d{kWheelBase / 2, kTrackwidth / 2},
- frc::Translation2d{kWheelBase / 2, -kTrackwidth / 2},
- frc::Translation2d{-kWheelBase / 2, kTrackwidth / 2},
- frc::Translation2d{-kWheelBase / 2, -kTrackwidth / 2}};
-
-} // namespace DriveConstants
-
-namespace AutoConstants {
-
-const frc::TrapezoidProfile::Constraints
- kThetaControllerConstraints{kMaxAngularSpeed, kMaxAngularAcceleration};
-
-} // namespace AutoConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Robot.cpp
deleted file mode 100644
index 18be09af70..0000000000
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/Robot.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright (c) FIRST and other WPILib contributors.
-// Open Source Software; you can modify and/or share it under the terms of
-// the WPILib BSD license file in the root directory of this project.
-
-#include "Robot.h"
-
-#include
-#include
-
-Robot::Robot() {}
-
-/**
- * This function is called every 20 ms, no matter the mode. Use
- * this for items like diagnostics that you want to run during disabled,
- * autonomous, teleoperated and test.
- *
- * This runs after the mode specific periodic functions, but before
- * LiveWindow and SmartDashboard integrated updating.
- */
-void Robot::RobotPeriodic() {
- frc2::CommandScheduler::GetInstance().Run();
-}
-
-/**
- * This function is called once each time the robot enters Disabled mode. You
- * can use it to reset any subsystem information you want to clear when the
- * robot is disabled.
- */
-void Robot::DisabledInit() {}
-
-void Robot::DisabledPeriodic() {}
-
-/**
- * This autonomous runs the autonomous command selected by your {@link
- * RobotContainer} class.
- */
-void Robot::AutonomousInit() {
- m_autonomousCommand = m_container.GetAutonomousCommand();
-
- if (m_autonomousCommand) {
- frc2::CommandScheduler::GetInstance().Schedule(m_autonomousCommand.value());
- }
-}
-
-void Robot::AutonomousPeriodic() {}
-
-void Robot::TeleopInit() {
- // This makes sure that the autonomous stops running when
- // teleop starts running. If you want the autonomous to
- // continue until interrupted by another command, remove
- // this line or comment it out.
- if (m_autonomousCommand) {
- m_autonomousCommand->Cancel();
- m_autonomousCommand.reset();
- }
-}
-
-/**
- * This function is called periodically during operator control.
- */
-void Robot::TeleopPeriodic() {}
-
-/**
- * This function is called periodically during test mode.
- */
-void Robot::TestPeriodic() {}
-
-#ifndef RUNNING_FRC_TESTS
-int main() {
- return frc::StartRobot();
-}
-#endif
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp
deleted file mode 100644
index 427da55401..0000000000
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-// Copyright (c) FIRST and other WPILib contributors.
-// Open Source Software; you can modify and/or share it under the terms of
-// the WPILib BSD license file in the root directory of this project.
-
-#include "RobotContainer.h"
-
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "Constants.h"
-
-using namespace DriveConstants;
-
-RobotContainer::RobotContainer() {
- // Initialize all of your commands and subsystems here
-
- // Configure the button bindings
- ConfigureButtonBindings();
-
- // Set up default drive command
- m_drive.SetDefaultCommand(frc2::RunCommand(
- [this] {
- m_drive.Drive(-m_driverController.GetLeftY(),
- -m_driverController.GetRightX(),
- -m_driverController.GetLeftX(), false);
- },
- {&m_drive}));
-}
-
-void RobotContainer::ConfigureButtonBindings() {
- // Configure your button bindings here
-
- // While holding the shoulder button, drive at half speed
- frc2::JoystickButton(&m_driverController,
- frc::XboxController::Button::kRightBumper)
- .OnTrue(&m_driveHalfSpeed)
- .OnFalse(&m_driveFullSpeed);
-}
-
-frc2::CommandPtr RobotContainer::GetAutonomousCommand() {
- // Set up config for trajectory
- frc::TrajectoryConfig config(AutoConstants::kMaxSpeed,
- AutoConstants::kMaxAcceleration);
- // Add kinematics to ensure max speed is actually obeyed
- config.SetKinematics(DriveConstants::kDriveKinematics);
-
- // An example trajectory to follow. All units in meters.
- auto exampleTrajectory = frc::TrajectoryGenerator::GenerateTrajectory(
- // Start at the origin facing the +X direction
- frc::Pose2d{0_m, 0_m, 0_deg},
- // Pass through these two interior waypoints, making an 's' curve path
- {frc::Translation2d{1_m, 1_m}, frc::Translation2d{2_m, -1_m}},
- // End 3 meters straight ahead of where we started, facing forward
- frc::Pose2d{3_m, 0_m, 0_deg},
- // Pass the config
- config);
-
- frc2::CommandPtr mecanumControllerCommand =
- frc2::MecanumControllerCommand(
- exampleTrajectory, [this]() { return m_drive.GetPose(); },
-
- frc::SimpleMotorFeedforward(ks, kv, ka),
- DriveConstants::kDriveKinematics,
-
- frc::PIDController{AutoConstants::kPXController, 0, 0},
- frc::PIDController{AutoConstants::kPYController, 0, 0},
- frc::ProfiledPIDController(
- AutoConstants::kPThetaController, 0, 0,
- AutoConstants::kThetaControllerConstraints),
-
- AutoConstants::kMaxSpeed,
-
- [this]() {
- return frc::MecanumDriveWheelSpeeds{
- units::meters_per_second_t{
- m_drive.GetFrontLeftEncoder().GetRate()},
- units::meters_per_second_t{
- m_drive.GetFrontRightEncoder().GetRate()},
- units::meters_per_second_t{
- m_drive.GetRearLeftEncoder().GetRate()},
- units::meters_per_second_t{
- m_drive.GetRearRightEncoder().GetRate()}};
- },
-
- frc::PIDController{DriveConstants::kPFrontLeftVel, 0, 0},
- frc::PIDController{DriveConstants::kPRearLeftVel, 0, 0},
- frc::PIDController{DriveConstants::kPFrontRightVel, 0, 0},
- frc::PIDController{DriveConstants::kPRearRightVel, 0, 0},
-
- [this](units::volt_t frontLeft, units::volt_t rearLeft,
- units::volt_t frontRight, units::volt_t rearRight) {
- m_drive.SetMotorControllersVolts(frontLeft, rearLeft, frontRight,
- rearRight);
- },
-
- {&m_drive})
- .ToPtr();
-
- // Reset odometry to the initial pose of the trajectory, run path following
- // command, then stop at the end.
- return frc2::cmd::Sequence(
- frc2::InstantCommand(
- [this, initialPose = exampleTrajectory.InitialPose()]() {
- m_drive.ResetOdometry(initialPose);
- },
- {})
- .ToPtr(),
- std::move(mecanumControllerCommand),
- frc2::InstantCommand([this]() { m_drive.Drive(0, 0, 0, false); }, {})
- .ToPtr());
-}
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp
deleted file mode 100644
index 8a55821e71..0000000000
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright (c) FIRST and other WPILib contributors.
-// Open Source Software; you can modify and/or share it under the terms of
-// the WPILib BSD license file in the root directory of this project.
-
-#include "subsystems/DriveSubsystem.h"
-
-#include
-#include
-#include
-
-#include "Constants.h"
-
-using namespace DriveConstants;
-
-DriveSubsystem::DriveSubsystem()
- : m_frontLeft{kFrontLeftMotorPort},
- m_rearLeft{kRearLeftMotorPort},
- m_frontRight{kFrontRightMotorPort},
- m_rearRight{kRearRightMotorPort},
-
- m_frontLeftEncoder{kFrontLeftEncoderPorts[0], kFrontLeftEncoderPorts[1],
- kFrontLeftEncoderReversed},
- m_rearLeftEncoder{kRearLeftEncoderPorts[0], kRearLeftEncoderPorts[1],
- kRearLeftEncoderReversed},
- m_frontRightEncoder{kFrontRightEncoderPorts[0],
- kFrontRightEncoderPorts[1],
- kFrontRightEncoderReversed},
- m_rearRightEncoder{kRearRightEncoderPorts[0], kRearRightEncoderPorts[1],
- kRearRightEncoderReversed},
-
- m_odometry{kDriveKinematics, m_gyro.GetRotation2d(),
- getCurrentWheelDistances(), frc::Pose2d{}} {
- wpi::SendableRegistry::AddChild(&m_drive, &m_frontLeft);
- wpi::SendableRegistry::AddChild(&m_drive, &m_rearLeft);
- wpi::SendableRegistry::AddChild(&m_drive, &m_frontRight);
- wpi::SendableRegistry::AddChild(&m_drive, &m_rearRight);
-
- // Set the distance per pulse for the encoders
- m_frontLeftEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
- m_rearLeftEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
- m_frontRightEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
- m_rearRightEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
- // We need to invert one side of the drivetrain so that positive voltages
- // result in both sides moving forward. Depending on how your robot's
- // gearbox is constructed, you might have to invert the left side instead.
- m_frontRight.SetInverted(true);
- m_rearRight.SetInverted(true);
-}
-
-void DriveSubsystem::Periodic() {
- // Implementation of subsystem periodic method goes here.
- m_odometry.Update(m_gyro.GetRotation2d(), getCurrentWheelDistances());
-}
-
-void DriveSubsystem::Drive(double xSpeed, double ySpeed, double rot,
- bool fieldRelative) {
- if (fieldRelative) {
- m_drive.DriveCartesian(xSpeed, ySpeed, rot, m_gyro.GetRotation2d());
- } else {
- m_drive.DriveCartesian(xSpeed, ySpeed, rot);
- }
-}
-
-void DriveSubsystem::SetMotorControllersVolts(units::volt_t frontLeftPower,
- units::volt_t rearLeftPower,
- units::volt_t frontRightPower,
- units::volt_t rearRightPower) {
- m_frontLeft.SetVoltage(frontLeftPower);
- m_rearLeft.SetVoltage(rearLeftPower);
- m_frontRight.SetVoltage(frontRightPower);
- m_rearRight.SetVoltage(rearRightPower);
-}
-
-void DriveSubsystem::ResetEncoders() {
- m_frontLeftEncoder.Reset();
- m_rearLeftEncoder.Reset();
- m_frontRightEncoder.Reset();
- m_rearRightEncoder.Reset();
-}
-
-frc::Encoder& DriveSubsystem::GetFrontLeftEncoder() {
- return m_frontLeftEncoder;
-}
-
-frc::Encoder& DriveSubsystem::GetRearLeftEncoder() {
- return m_rearLeftEncoder;
-}
-
-frc::Encoder& DriveSubsystem::GetFrontRightEncoder() {
- return m_frontRightEncoder;
-}
-
-frc::Encoder& DriveSubsystem::GetRearRightEncoder() {
- return m_rearRightEncoder;
-}
-
-frc::MecanumDriveWheelSpeeds DriveSubsystem::getCurrentWheelSpeeds() {
- return (frc::MecanumDriveWheelSpeeds{
- units::meters_per_second_t{m_frontLeftEncoder.GetRate()},
- units::meters_per_second_t{m_rearLeftEncoder.GetRate()},
- units::meters_per_second_t{m_frontRightEncoder.GetRate()},
- units::meters_per_second_t{m_rearRightEncoder.GetRate()}});
-}
-
-frc::MecanumDriveWheelPositions DriveSubsystem::getCurrentWheelDistances() {
- return (frc::MecanumDriveWheelPositions{
- units::meter_t{m_frontLeftEncoder.GetDistance()},
- units::meter_t{m_rearLeftEncoder.GetDistance()},
- units::meter_t{m_frontRightEncoder.GetDistance()},
- units::meter_t{m_rearRightEncoder.GetDistance()}});
-}
-
-void DriveSubsystem::SetMaxOutput(double maxOutput) {
- m_drive.SetMaxOutput(maxOutput);
-}
-
-units::degree_t DriveSubsystem::GetHeading() const {
- return m_gyro.GetRotation2d().Degrees();
-}
-
-void DriveSubsystem::ZeroHeading() {
- m_gyro.Reset();
-}
-
-double DriveSubsystem::GetTurnRate() {
- return -m_gyro.GetRate();
-}
-
-frc::Pose2d DriveSubsystem::GetPose() {
- return m_odometry.GetPose();
-}
-
-void DriveSubsystem::ResetOdometry(frc::Pose2d pose) {
- m_odometry.ResetPosition(m_gyro.GetRotation2d(), getCurrentWheelDistances(),
- pose);
-}
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Constants.h
deleted file mode 100644
index 098dfa2028..0000000000
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Constants.h
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright (c) FIRST and other WPILib contributors.
-// Open Source Software; you can modify and/or share it under the terms of
-// the WPILib BSD license file in the root directory of this project.
-
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#pragma once
-
-/**
- * The Constants header provides a convenient place for teams to hold robot-wide
- * numerical or bool constants. This should not be used for any other purpose.
- *
- * It is generally a good idea to place constants into subsystem- or
- * command-specific namespaces within this header, which can then be used where
- * they are needed.
- */
-
-namespace DriveConstants {
-inline constexpr int kFrontLeftMotorPort = 0;
-inline constexpr int kRearLeftMotorPort = 1;
-inline constexpr int kFrontRightMotorPort = 2;
-inline constexpr int kRearRightMotorPort = 3;
-
-inline constexpr int kFrontLeftEncoderPorts[]{0, 1};
-inline constexpr int kRearLeftEncoderPorts[]{2, 3};
-inline constexpr int kFrontRightEncoderPorts[]{4, 5};
-inline constexpr int kRearRightEncoderPorts[]{6, 7};
-
-inline constexpr bool kFrontLeftEncoderReversed = false;
-inline constexpr bool kRearLeftEncoderReversed = true;
-inline constexpr bool kFrontRightEncoderReversed = false;
-inline constexpr bool kRearRightEncoderReversed = true;
-
-inline constexpr auto kTrackwidth =
- 0.5_m; // Distance between centers of right and left wheels on robot
-inline constexpr auto kWheelBase =
- 0.7_m; // Distance between centers of front and back wheels on robot
-extern const frc::MecanumDriveKinematics kDriveKinematics;
-
-inline constexpr int kEncoderCPR = 1024;
-inline constexpr auto kWheelDiameter = 0.15_m;
-inline constexpr double kEncoderDistancePerPulse =
- // Assumes the encoders are directly mounted on the wheel shafts
- (kWheelDiameter.value() * std::numbers::pi) /
- static_cast(kEncoderCPR);
-
-// These are example values only - DO NOT USE THESE FOR YOUR OWN ROBOT!
-// These characterization values MUST be determined either experimentally or
-// theoretically for *your* robot's drive. The SysId tool provides a convenient
-// method for obtaining these values for your robot.
-inline constexpr auto ks = 1_V;
-inline constexpr auto kv = 0.8 * 1_V * 1_s / 1_m;
-inline constexpr auto ka = 0.15 * 1_V * 1_s * 1_s / 1_m;
-
-// Example value only - as above, this must be tuned for your drive!
-inline constexpr double kPFrontLeftVel = 0.5;
-inline constexpr double kPRearLeftVel = 0.5;
-inline constexpr double kPFrontRightVel = 0.5;
-inline constexpr double kPRearRightVel = 0.5;
-} // namespace DriveConstants
-
-namespace AutoConstants {
-inline constexpr auto kMaxSpeed = 3_mps;
-inline constexpr auto kMaxAcceleration = 3_mps_sq;
-inline constexpr auto kMaxAngularSpeed = 3_rad_per_s;
-inline constexpr auto kMaxAngularAcceleration = 3_rad_per_s_sq;
-
-inline constexpr double kPXController = 0.5;
-inline constexpr double kPYController = 0.5;
-inline constexpr double kPThetaController = 0.5;
-
-extern const frc::TrapezoidProfile::Constraints
- kThetaControllerConstraints;
-
-} // namespace AutoConstants
-
-namespace OIConstants {
-inline constexpr int kDriverControllerPort = 0;
-} // namespace OIConstants
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Robot.h b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Robot.h
deleted file mode 100644
index 2405694447..0000000000
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/Robot.h
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (c) FIRST and other WPILib contributors.
-// Open Source Software; you can modify and/or share it under the terms of
-// the WPILib BSD license file in the root directory of this project.
-
-#pragma once
-
-#include
-
-#include
-#include
-
-#include "RobotContainer.h"
-
-class Robot : public frc::TimedRobot {
- public:
- Robot();
- void RobotPeriodic() override;
- void DisabledInit() override;
- void DisabledPeriodic() override;
- void AutonomousInit() override;
- void AutonomousPeriodic() override;
- void TeleopInit() override;
- void TeleopPeriodic() override;
- void TestPeriodic() override;
-
- private:
- // Have it null by default so that if testing teleop it
- // doesn't have undefined behavior and potentially crash.
- std::optional m_autonomousCommand;
-
- RobotContainer m_container;
-};
diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/RobotContainer.h
deleted file mode 100644
index 2437852294..0000000000
--- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/RobotContainer.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (c) FIRST and other WPILib contributors.
-// Open Source Software; you can modify and/or share it under the terms of
-// the WPILib BSD license file in the root directory of this project.
-
-#pragma once
-
-#include