diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PIDCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PIDCommand.java deleted file mode 100644 index 0a84d37c25..0000000000 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PIDCommand.java +++ /dev/null @@ -1,106 +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.PIDController; -import java.util.function.DoubleConsumer; -import java.util.function.DoubleSupplier; - -/** - * A command that controls an output with a {@link PIDController}. Runs forever by default - to add - * exit conditions and/or other behavior, subclass this class. The controller calculation and output - * are performed synchronously in the command's execute() method. - * - *

This class is provided by the NewCommands VendorDep - * - * @deprecated Use a PIDController instead - */ -@Deprecated(forRemoval = true, since = "2025") -public class PIDCommand extends Command { - /** PID controller. */ - protected final PIDController m_controller; - - /** Measurement getter. */ - protected DoubleSupplier m_measurement; - - /** Setpoint getter. */ - protected DoubleSupplier m_setpoint; - - /** PID controller output consumer. */ - protected DoubleConsumer m_useOutput; - - /** - * Creates a new PIDCommand, which controls the given output with a PIDController. - * - * @param controller the controller that controls the output. - * @param measurementSource the measurement of the process variable - * @param setpointSource the controller's setpoint - * @param useOutput the controller's output - * @param requirements the subsystems required by this command - */ - @SuppressWarnings("this-escape") - public PIDCommand( - PIDController controller, - DoubleSupplier measurementSource, - DoubleSupplier setpointSource, - DoubleConsumer useOutput, - Subsystem... requirements) { - requireNonNullParam(controller, "controller", "PIDCommand"); - requireNonNullParam(measurementSource, "measurementSource", "PIDCommand"); - requireNonNullParam(setpointSource, "setpointSource", "PIDCommand"); - requireNonNullParam(useOutput, "useOutput", "PIDCommand"); - - m_controller = controller; - m_useOutput = useOutput; - m_measurement = measurementSource; - m_setpoint = setpointSource; - addRequirements(requirements); - } - - /** - * Creates a new PIDCommand, which controls the given output with a PIDController. - * - * @param controller the controller that controls the output. - * @param measurementSource the measurement of the process variable - * @param setpoint the controller's setpoint - * @param useOutput the controller's output - * @param requirements the subsystems required by this command - */ - public PIDCommand( - PIDController controller, - DoubleSupplier measurementSource, - double setpoint, - DoubleConsumer useOutput, - Subsystem... requirements) { - this(controller, measurementSource, () -> setpoint, useOutput, requirements); - } - - @Override - public void initialize() { - m_controller.reset(); - } - - @Override - public void execute() { - m_useOutput.accept( - m_controller.calculate(m_measurement.getAsDouble(), m_setpoint.getAsDouble())); - } - - @Override - public void end(boolean interrupted) { - m_useOutput.accept(0); - } - - /** - * Returns the PIDController used by the command. - * - * @return The PIDController - */ - public PIDController getController() { - return m_controller; - } -} diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PIDSubsystem.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PIDSubsystem.java deleted file mode 100644 index 3be70d7a1f..0000000000 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/PIDSubsystem.java +++ /dev/null @@ -1,118 +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.PIDController; - -/** - * A subsystem that uses a {@link PIDController} to control an output. The controller is run - * synchronously from the subsystem's periodic() method. - * - *

This class is provided by the NewCommands VendorDep - * - * @deprecated Use a PIDController instead - */ -@Deprecated(forRemoval = true, since = "2025") -public abstract class PIDSubsystem extends SubsystemBase { - /** PID controller. */ - protected final PIDController m_controller; - - /** Whether PID controller output is enabled. */ - protected boolean m_enabled; - - /** - * Creates a new PIDSubsystem. - * - * @param controller the PIDController to use - * @param initialPosition the initial setpoint of the subsystem - */ - @SuppressWarnings("this-escape") - public PIDSubsystem(PIDController controller, double initialPosition) { - m_controller = requireNonNullParam(controller, "controller", "PIDSubsystem"); - setSetpoint(initialPosition); - addChild("PID Controller", m_controller); - } - - /** - * Creates a new PIDSubsystem. Initial setpoint is zero. - * - * @param controller the PIDController to use - */ - public PIDSubsystem(PIDController controller) { - this(controller, 0); - } - - @Override - public void periodic() { - if (m_enabled) { - useOutput(m_controller.calculate(getMeasurement()), getSetpoint()); - } - } - - /** - * Returns the PIDController. - * - * @return The controller. - */ - public PIDController getController() { - return m_controller; - } - - /** - * Sets the setpoint for the subsystem. - * - * @param setpoint the setpoint for the subsystem - */ - public final void setSetpoint(double setpoint) { - m_controller.setSetpoint(setpoint); - } - - /** - * Returns the current setpoint of the subsystem. - * - * @return The current setpoint - */ - public double getSetpoint() { - return m_controller.getSetpoint(); - } - - /** - * Uses the output from the PIDController. - * - * @param output the output of the PIDController - * @param setpoint the setpoint of the PIDController (for feedforward) - */ - protected abstract void useOutput(double output, double setpoint); - - /** - * Returns the measurement of the process variable used by the PIDController. - * - * @return the measurement of the process variable - */ - protected abstract double getMeasurement(); - - /** Enables the PID control. Resets the controller. */ - public void enable() { - m_enabled = true; - m_controller.reset(); - } - - /** Disables the PID control. Sets output to zero. */ - public void disable() { - m_enabled = false; - useOutput(0, 0); - } - - /** - * Returns whether the controller is enabled. - * - * @return Whether the controller is enabled. - */ - public boolean isEnabled() { - return m_enabled; - } -} diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDCommand.java deleted file mode 100644 index 428aabc7d1..0000000000 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDCommand.java +++ /dev/null @@ -1,159 +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.math.trajectory.TrapezoidProfile.State; -import static edu.wpi.first.util.ErrorMessages.requireNonNullParam; - -import edu.wpi.first.math.controller.ProfiledPIDController; -import java.util.function.BiConsumer; -import java.util.function.DoubleSupplier; -import java.util.function.Supplier; - -/** - * A command that controls an output with a {@link ProfiledPIDController}. Runs forever by default - - * to add exit conditions and/or other behavior, subclass this class. The controller calculation and - * output are performed synchronously in the command's execute() method. - * - *

This class is provided by the NewCommands VendorDep - * - * @deprecated Use a ProfiledPIDController instead - */ -@Deprecated(forRemoval = true, since = "2025") -public class ProfiledPIDCommand extends Command { - /** Profiled PID controller. */ - protected final ProfiledPIDController m_controller; - - /** Measurement getter. */ - protected DoubleSupplier m_measurement; - - /** Goal getter. */ - protected Supplier m_goal; - - /** Profiled PID controller output consumer. */ - protected BiConsumer m_useOutput; - - /** - * Creates a new PIDCommand, which controls the given output with a ProfiledPIDController. Goal - * velocity is specified. - * - * @param controller the controller that controls the output. - * @param measurementSource the measurement of the process variable - * @param goalSource the controller's goal - * @param useOutput the controller's output - * @param requirements the subsystems required by this command - */ - @SuppressWarnings("this-escape") - public ProfiledPIDCommand( - ProfiledPIDController controller, - DoubleSupplier measurementSource, - Supplier goalSource, - BiConsumer useOutput, - Subsystem... requirements) { - requireNonNullParam(controller, "controller", "ProfiledPIDCommand"); - requireNonNullParam(measurementSource, "measurementSource", "ProfiledPIDCommand"); - requireNonNullParam(goalSource, "goalSource", "ProfiledPIDCommand"); - requireNonNullParam(useOutput, "useOutput", "ProfiledPIDCommand"); - - m_controller = controller; - m_useOutput = useOutput; - m_measurement = measurementSource; - m_goal = goalSource; - addRequirements(requirements); - } - - /** - * Creates a new PIDCommand, which controls the given output with a ProfiledPIDController. Goal - * velocity is implicitly zero. - * - * @param controller the controller that controls the output. - * @param measurementSource the measurement of the process variable - * @param goalSource the controller's goal - * @param useOutput the controller's output - * @param requirements the subsystems required by this command - */ - @SuppressWarnings("this-escape") - public ProfiledPIDCommand( - ProfiledPIDController controller, - DoubleSupplier measurementSource, - DoubleSupplier goalSource, - BiConsumer useOutput, - Subsystem... requirements) { - requireNonNullParam(controller, "controller", "SynchronousPIDCommand"); - requireNonNullParam(measurementSource, "measurementSource", "SynchronousPIDCommand"); - requireNonNullParam(goalSource, "goalSource", "SynchronousPIDCommand"); - requireNonNullParam(useOutput, "useOutput", "SynchronousPIDCommand"); - - m_controller = controller; - m_useOutput = useOutput; - m_measurement = measurementSource; - m_goal = () -> new State(goalSource.getAsDouble(), 0); - addRequirements(requirements); - } - - /** - * Creates a new PIDCommand, which controls the given output with a ProfiledPIDController. Goal - * velocity is specified. - * - * @param controller the controller that controls the output. - * @param measurementSource the measurement of the process variable - * @param goal the controller's goal - * @param useOutput the controller's output - * @param requirements the subsystems required by this command - */ - public ProfiledPIDCommand( - ProfiledPIDController controller, - DoubleSupplier measurementSource, - State goal, - BiConsumer useOutput, - Subsystem... requirements) { - this(controller, measurementSource, () -> goal, useOutput, requirements); - } - - /** - * Creates a new PIDCommand, which controls the given output with a ProfiledPIDController. Goal - * velocity is implicitly zero. - * - * @param controller the controller that controls the output. - * @param measurementSource the measurement of the process variable - * @param goal the controller's goal - * @param useOutput the controller's output - * @param requirements the subsystems required by this command - */ - public ProfiledPIDCommand( - ProfiledPIDController controller, - DoubleSupplier measurementSource, - double goal, - BiConsumer useOutput, - Subsystem... requirements) { - this(controller, measurementSource, () -> goal, useOutput, requirements); - } - - @Override - public void initialize() { - m_controller.reset(m_measurement.getAsDouble()); - } - - @Override - public void execute() { - m_useOutput.accept( - m_controller.calculate(m_measurement.getAsDouble(), m_goal.get()), - m_controller.getSetpoint()); - } - - @Override - public void end(boolean interrupted) { - m_useOutput.accept(0.0, new State()); - } - - /** - * Returns the ProfiledPIDController used by the command. - * - * @return The ProfiledPIDController - */ - public ProfiledPIDController getController() { - return m_controller; - } -} diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDSubsystem.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDSubsystem.java deleted file mode 100644 index 7dcc694d54..0000000000 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDSubsystem.java +++ /dev/null @@ -1,119 +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.math.trajectory.TrapezoidProfile.State; -import static edu.wpi.first.util.ErrorMessages.requireNonNullParam; - -import edu.wpi.first.math.controller.ProfiledPIDController; -import edu.wpi.first.math.trajectory.TrapezoidProfile; -import edu.wpi.first.math.trajectory.TrapezoidProfile.State; - -/** - * A subsystem that uses a {@link ProfiledPIDController} to control an output. The controller is run - * synchronously from the subsystem's periodic() method. - * - *

This class is provided by the NewCommands VendorDep - * - * @deprecated Use a ProfiledPIDController instead - */ -@Deprecated(forRemoval = true, since = "2025") -public abstract class ProfiledPIDSubsystem extends SubsystemBase { - /** Profiled PID controller. */ - protected final ProfiledPIDController m_controller; - - /** Whether the profiled PID controller output is enabled. */ - protected boolean m_enabled; - - /** - * Creates a new ProfiledPIDSubsystem. - * - * @param controller the ProfiledPIDController to use - * @param initialPosition the initial goal position of the controller - */ - public ProfiledPIDSubsystem(ProfiledPIDController controller, double initialPosition) { - m_controller = requireNonNullParam(controller, "controller", "ProfiledPIDSubsystem"); - setGoal(initialPosition); - } - - /** - * Creates a new ProfiledPIDSubsystem. Initial goal position is zero. - * - * @param controller the ProfiledPIDController to use - */ - public ProfiledPIDSubsystem(ProfiledPIDController controller) { - this(controller, 0); - } - - @Override - public void periodic() { - if (m_enabled) { - useOutput(m_controller.calculate(getMeasurement()), m_controller.getSetpoint()); - } - } - - /** - * Returns the ProfiledPIDController. - * - * @return The controller. - */ - public ProfiledPIDController getController() { - return m_controller; - } - - /** - * Sets the goal state for the subsystem. - * - * @param goal The goal state for the subsystem's motion profile. - */ - public final void setGoal(TrapezoidProfile.State goal) { - m_controller.setGoal(goal); - } - - /** - * Sets the goal state for the subsystem. Goal velocity assumed to be zero. - * - * @param goal The goal position for the subsystem's motion profile. - */ - public final void setGoal(double goal) { - setGoal(new TrapezoidProfile.State(goal, 0)); - } - - /** - * Uses the output from the ProfiledPIDController. - * - * @param output the output of the ProfiledPIDController - * @param setpoint the setpoint state of the ProfiledPIDController, for feedforward - */ - protected abstract void useOutput(double output, State setpoint); - - /** - * Returns the measurement of the process variable used by the ProfiledPIDController. - * - * @return the measurement of the process variable - */ - protected abstract double getMeasurement(); - - /** Enables the PID control. Resets the controller. */ - public void enable() { - m_enabled = true; - m_controller.reset(getMeasurement()); - } - - /** Disables the PID control. Sets output to zero. */ - public void disable() { - m_enabled = false; - useOutput(0, new State()); - } - - /** - * Returns whether the controller is enabled. - * - * @return Whether the controller is enabled. - */ - public boolean isEnabled() { - return m_enabled; - } -} diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileCommand.java deleted file mode 100644 index 6c76bb41f5..0000000000 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileCommand.java +++ /dev/null @@ -1,68 +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.trajectory.TrapezoidProfile; -import edu.wpi.first.math.trajectory.TrapezoidProfile.State; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * A command that runs a {@link TrapezoidProfile}. Useful for smoothly controlling mechanism motion. - * - *

This class is provided by the NewCommands VendorDep - * - * @deprecated Use a TrapezoidProfile instead - */ -@Deprecated(since = "2025", forRemoval = true) -public class TrapezoidProfileCommand extends Command { - private final TrapezoidProfile m_profile; - private final Consumer m_output; - private final Supplier m_goal; - private final Supplier m_currentState; - - /** - * Creates a new TrapezoidProfileCommand that will execute the given {@link TrapezoidProfile}. - * Output will be piped to the provided consumer function. - * - * @param profile The motion profile to execute. - * @param output The consumer for the profile output. - * @param goal The supplier for the desired state - * @param currentState The current state - * @param requirements The subsystems required by this command. - */ - @SuppressWarnings("this-escape") - public TrapezoidProfileCommand( - TrapezoidProfile profile, - Consumer output, - Supplier goal, - Supplier currentState, - Subsystem... requirements) { - m_profile = requireNonNullParam(profile, "profile", "TrapezoidProfileCommand"); - m_output = requireNonNullParam(output, "output", "TrapezoidProfileCommand"); - m_goal = goal; - m_currentState = currentState; - addRequirements(requirements); - } - - @Override - public void initialize() {} - - @Override - @SuppressWarnings("removal") - public void execute() { - m_output.accept(m_profile.calculate(0.02, m_currentState.get(), m_goal.get())); - } - - @Override - public void end(boolean interrupted) {} - - @Override - public boolean isFinished() { - return m_profile.isFinished(0); - } -} diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileSubsystem.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileSubsystem.java deleted file mode 100644 index b3df8bc772..0000000000 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileSubsystem.java +++ /dev/null @@ -1,109 +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.trajectory.TrapezoidProfile; - -/** - * A subsystem that generates and runs trapezoidal motion profiles automatically. The user specifies - * how to use the current state of the motion profile by overriding the `useState` method. - * - *

This class is provided by the NewCommands VendorDep - * - * @deprecated Use a TrapezoidProfile instead - */ -@Deprecated(forRemoval = true, since = "2025") -public abstract class TrapezoidProfileSubsystem extends SubsystemBase { - private final double m_period; - private final TrapezoidProfile m_profile; - - private TrapezoidProfile.State m_state; - private TrapezoidProfile.State m_goal; - - private boolean m_enabled = true; - - /** - * Creates a new TrapezoidProfileSubsystem. - * - * @param constraints The constraints (maximum velocity and acceleration) for the profiles. - * @param initialPosition The initial position of the controlled mechanism when the subsystem is - * constructed. - * @param period The period of the main robot loop, in seconds. - */ - public TrapezoidProfileSubsystem( - TrapezoidProfile.Constraints constraints, double initialPosition, double period) { - requireNonNullParam(constraints, "constraints", "TrapezoidProfileSubsystem"); - m_profile = new TrapezoidProfile(constraints); - m_state = new TrapezoidProfile.State(initialPosition, 0); - setGoal(initialPosition); - m_period = period; - } - - /** - * Creates a new TrapezoidProfileSubsystem. - * - * @param constraints The constraints (maximum velocity and acceleration) for the profiles. - * @param initialPosition The initial position of the controlled mechanism when the subsystem is - * constructed. - */ - public TrapezoidProfileSubsystem( - TrapezoidProfile.Constraints constraints, double initialPosition) { - this(constraints, initialPosition, 0.02); - } - - /** - * Creates a new TrapezoidProfileSubsystem. - * - * @param constraints The constraints (maximum velocity and acceleration) for the profiles. - */ - public TrapezoidProfileSubsystem(TrapezoidProfile.Constraints constraints) { - this(constraints, 0, 0.02); - } - - @Override - public void periodic() { - m_state = m_profile.calculate(m_period, m_state, m_goal); - if (m_enabled) { - useState(m_state); - } - } - - /** - * Sets the goal state for the subsystem. - * - * @param goal The goal state for the subsystem's motion profile. - */ - public final void setGoal(TrapezoidProfile.State goal) { - m_goal = goal; - } - - /** - * Sets the goal state for the subsystem. Goal velocity assumed to be zero. - * - * @param goal The goal position for the subsystem's motion profile. - */ - public final void setGoal(double goal) { - setGoal(new TrapezoidProfile.State(goal, 0)); - } - - /** Enable the TrapezoidProfileSubsystem's output. */ - public void enable() { - m_enabled = true; - } - - /** Disable the TrapezoidProfileSubsystem's output. */ - public void disable() { - m_enabled = false; - } - - /** - * Users should override this to consume the current state of the motion profile. - * - * @param state The current state of the motion profile. - */ - protected abstract void useState(TrapezoidProfile.State state); -} diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/PIDCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/PIDCommand.cpp deleted file mode 100644 index 37778bbbb4..0000000000 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/PIDCommand.cpp +++ /dev/null @@ -1,49 +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/PIDCommand.h" - -#include - -#include - -using namespace frc2; - -PIDCommand::PIDCommand(frc::PIDController controller, - std::function measurementSource, - std::function setpointSource, - std::function useOutput, - Requirements requirements) - : m_controller{std::move(controller)}, - m_measurement{std::move(measurementSource)}, - m_setpoint{std::move(setpointSource)}, - m_useOutput{std::move(useOutput)} { - AddRequirements(requirements); -} -WPI_IGNORE_DEPRECATED - -PIDCommand::PIDCommand(frc::PIDController controller, - std::function measurementSource, - double setpoint, std::function useOutput, - Requirements requirements) - : PIDCommand( - controller, measurementSource, [setpoint] { return setpoint; }, - useOutput, requirements) {} -WPI_UNIGNORE_DEPRECATED - -void PIDCommand::Initialize() { - m_controller.Reset(); -} - -void PIDCommand::Execute() { - m_useOutput(m_controller.Calculate(m_measurement(), m_setpoint())); -} - -void PIDCommand::End(bool interrupted) { - m_useOutput(0); -} - -frc::PIDController& PIDCommand::GetController() { - return m_controller; -} diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/PIDSubsystem.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/PIDSubsystem.cpp deleted file mode 100644 index 0764cb9ad8..0000000000 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/PIDSubsystem.cpp +++ /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. - -#include "frc2/command/PIDSubsystem.h" - -#include - -using namespace frc2; - -PIDSubsystem::PIDSubsystem(frc::PIDController controller, - double initialPosition) - : m_controller{std::move(controller)} { - SetSetpoint(initialPosition); - AddChild("PID Controller", &m_controller); -} - -void PIDSubsystem::Periodic() { - if (m_enabled) { - UseOutput(m_controller.Calculate(GetMeasurement()), GetSetpoint()); - } -} - -void PIDSubsystem::SetSetpoint(double setpoint) { - m_controller.SetSetpoint(setpoint); -} - -double PIDSubsystem::GetSetpoint() const { - return m_controller.GetSetpoint(); -} - -void PIDSubsystem::Enable() { - m_controller.Reset(); - m_enabled = true; -} - -void PIDSubsystem::Disable() { - UseOutput(0, 0); - m_enabled = false; -} - -bool PIDSubsystem::IsEnabled() { - return m_enabled; -} - -frc::PIDController& PIDSubsystem::GetController() { - return m_controller; -} diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/PIDCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/PIDCommand.h deleted file mode 100644 index 015fca1342..0000000000 --- a/wpilibNewCommands/src/main/native/include/frc2/command/PIDCommand.h +++ /dev/null @@ -1,93 +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 "frc2/command/Command.h" -#include "frc2/command/CommandHelper.h" -#include "frc2/command/Requirements.h" - -namespace frc2 { -/** - * A command that controls an output with a PIDController. Runs forever by - * default - to add exit conditions and/or other behavior, subclass this class. - * The controller calculation and output are performed synchronously in the - * command's execute() method. - * - * This class is provided by the NewCommands VendorDep - * - * @see PIDController - */ -class PIDCommand : public CommandHelper { - public: - /** - * Creates a new PIDCommand, which controls the given output with a - * PIDController. - * - * @param controller the controller that controls the output. - * @param measurementSource the measurement of the process variable - * @param setpointSource the controller's reference (aka setpoint) - * @param useOutput the controller's output - * @param requirements the subsystems required by this command - * @deprecated Use a PIDController instead - */ - [[deprecated("Use a PIDController instead")]] - PIDCommand(frc::PIDController controller, - std::function measurementSource, - std::function setpointSource, - std::function useOutput, - Requirements requirements = {}); - - /** - * Creates a new PIDCommand, which controls the given output with a - * PIDController with a constant setpoint. - * - * @param controller the controller that controls the output. - * @param measurementSource the measurement of the process variable - * @param setpoint the controller's setpoint (aka setpoint) - * @param useOutput the controller's output - * @param requirements the subsystems required by this command - * @deprecated Use a PIDController instead - */ - [[deprecated("Use a PIDController instead")]] - PIDCommand(frc::PIDController controller, - std::function measurementSource, double setpoint, - std::function useOutput, - Requirements requirements = {}); - - PIDCommand(PIDCommand&& other) = default; - - PIDCommand(const PIDCommand& other) = default; - - void Initialize() override; - - void Execute() override; - - void End(bool interrupted) override; - - /** - * Returns the PIDController used by the command. - * - * @return The PIDController - */ - frc::PIDController& GetController(); - - protected: - /// PID controller. - frc::PIDController m_controller; - - /// Measurement getter. - std::function m_measurement; - - /// Setpoint getter. - std::function m_setpoint; - - /// PID controller output consumer. - std::function m_useOutput; -}; -} // namespace frc2 diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/PIDSubsystem.h b/wpilibNewCommands/src/main/native/include/frc2/command/PIDSubsystem.h deleted file mode 100644 index 64eecd7e07..0000000000 --- a/wpilibNewCommands/src/main/native/include/frc2/command/PIDSubsystem.h +++ /dev/null @@ -1,95 +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 "frc2/command/SubsystemBase.h" - -namespace frc2 { -/** - * A subsystem that uses a PIDController to control an output. The controller - * is run synchronously from the subsystem's periodic() method. - * - * This class is provided by the NewCommands VendorDep - * - * @see PIDController - * @deprecated Use a PIDController instead - */ -class [[deprecated("Use a PIDController instead")]] PIDSubsystem - : public SubsystemBase { - public: - /** - * Creates a new PIDSubsystem. - * - * @param controller the PIDController to use - * @param initialPosition the initial setpoint of the subsystem - */ - explicit PIDSubsystem(frc::PIDController controller, - double initialPosition = 0); - - void Periodic() override; - - /** - * Sets the setpoint for the subsystem. - * - * @param setpoint the setpoint for the subsystem - */ - void SetSetpoint(double setpoint); - - /** - * Gets the setpoint for the subsystem. - * - * @return the setpoint for the subsystem - */ - double GetSetpoint() const; - - /** - * Enables the PID control. Resets the controller. - */ - virtual void Enable(); - - /** - * Disables the PID control. Sets output to zero. - */ - virtual void Disable(); - - /** - * Returns whether the controller is enabled. - * - * @return Whether the controller is enabled. - */ - bool IsEnabled(); - - /** - * Returns the PIDController. - * - * @return The controller. - */ - frc::PIDController& GetController(); - - protected: - /// PID controller. - frc::PIDController m_controller; - - /// Whether PID controller output is enabled. - bool m_enabled{false}; - - /** - * Returns the measurement of the process variable used by the PIDController. - * - * @return the measurement of the process variable - */ - virtual double GetMeasurement() = 0; - - /** - * Uses the output from the PIDController. - * - * @param output the output of the PIDController - * @param setpoint the setpoint of the PIDController (for feedforward) - */ - virtual void UseOutput(double output, double setpoint) = 0; -}; -} // namespace frc2 diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDCommand.h deleted file mode 100644 index a924c4e4ed..0000000000 --- a/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDCommand.h +++ /dev/null @@ -1,163 +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 - -#include "frc2/command/Command.h" -#include "frc2/command/CommandHelper.h" -#include "frc2/command/Requirements.h" - -namespace frc2 { -/** - * A command that controls an output with a ProfiledPIDController. Runs forever - * by default - to add exit conditions and/or other behavior, subclass this - * class. The controller calculation and output are performed synchronously in - * the command's execute() method. - * - * This class is provided by the NewCommands VendorDep - * - * @see ProfiledPIDController - */ -template -class ProfiledPIDCommand - : public CommandHelper> { - using Distance_t = units::unit_t; - using Velocity = - units::compound_unit>; - using Velocity_t = units::unit_t; - using State = typename frc::TrapezoidProfile::State; - - public: - /** - * Creates a new PIDCommand, which controls the given output with a - * ProfiledPIDController. - * - * @param controller the controller that controls the output. - * @param measurementSource the measurement of the process variable - * @param goalSource the controller's goal - * @param useOutput the controller's output - * @param requirements the subsystems required by this command - * @deprecated Use a ProfiledPIDController instead - */ - [[deprecated("Use a ProfiledPIDController instead")]] - ProfiledPIDCommand(frc::ProfiledPIDController controller, - std::function measurementSource, - std::function goalSource, - std::function useOutput, - Requirements requirements = {}) - : m_controller{controller}, - m_measurement{std::move(measurementSource)}, - m_goal{std::move(goalSource)}, - m_useOutput{std::move(useOutput)} { - this->AddRequirements(requirements); - } - - /** - * Creates a new PIDCommand, which controls the given output with a - * ProfiledPIDController. - * - * @param controller the controller that controls the output. - * @param measurementSource the measurement of the process variable - * @param goalSource the controller's goal - * @param useOutput the controller's output - * @param requirements the subsystems required by this command - * @deprecated Use a ProfiledPIDController instead - */ - [[deprecated("Use a ProfiledPIDController instead")]] - ProfiledPIDCommand(frc::ProfiledPIDController controller, - std::function measurementSource, - std::function goalSource, - std::function useOutput, - Requirements requirements = {}) - : ProfiledPIDCommand( - controller, measurementSource, - [goalSource = std::move(goalSource)]() { - return State{goalSource(), Velocity_t{0}}; - }, - useOutput, requirements) {} - - /** - * Creates a new PIDCommand, which controls the given output with a - * ProfiledPIDController with a constant goal. - * - * @param controller the controller that controls the output. - * @param measurementSource the measurement of the process variable - * @param goal the controller's goal - * @param useOutput the controller's output - * @param requirements the subsystems required by this command - * @deprecated Use a ProfiledPIDController instead - */ - - [[deprecated("Use a ProfiledPIDController instead")]] - ProfiledPIDCommand(frc::ProfiledPIDController controller, - std::function measurementSource, State goal, - std::function useOutput, - Requirements requirements = {}) - : ProfiledPIDCommand( - controller, measurementSource, [goal] { return goal; }, useOutput, - requirements) {} - - /** - * Creates a new PIDCommand, which controls the given output with a - * ProfiledPIDController with a constant goal. - * - * @param controller the controller that controls the output. - * @param measurementSource the measurement of the process variable - * @param goal the controller's goal - * @param useOutput the controller's output - * @param requirements the subsystems required by this command - * @deprecated Use a ProfiledPIDController instead - */ - [[deprecated("Use a ProfiledPIDController instead")]] - ProfiledPIDCommand(frc::ProfiledPIDController controller, - std::function measurementSource, - Distance_t goal, - std::function useOutput, - Requirements requirements = {}) - : ProfiledPIDCommand( - controller, measurementSource, [goal] { return goal; }, useOutput, - requirements) {} - - ProfiledPIDCommand(ProfiledPIDCommand&& other) = default; - - ProfiledPIDCommand(const ProfiledPIDCommand& other) = default; - - void Initialize() override { m_controller.Reset(m_measurement()); } - - void Execute() override { - m_useOutput(m_controller.Calculate(m_measurement(), m_goal()), - m_controller.GetSetpoint()); - } - - void End(bool interrupted) override { - m_useOutput(0, State{Distance_t(0), Velocity_t(0)}); - } - - /** - * Returns the ProfiledPIDController used by the command. - * - * @return The ProfiledPIDController - */ - frc::ProfiledPIDController& GetController() { return m_controller; } - - protected: - /// Profiled PID controller. - frc::ProfiledPIDController m_controller; - - /// Measurement getter. - std::function m_measurement; - - /// Goal getter. - std::function m_goal; - - /// Profiled PID controller output consumer. - std::function m_useOutput; -}; -} // namespace frc2 diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDSubsystem.h b/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDSubsystem.h deleted file mode 100644 index b5786d959e..0000000000 --- a/wpilibNewCommands/src/main/native/include/frc2/command/ProfiledPIDSubsystem.h +++ /dev/null @@ -1,119 +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 "frc2/command/SubsystemBase.h" - -namespace frc2 { -/** - * A subsystem that uses a ProfiledPIDController to control an output. The - * controller is run synchronously from the subsystem's periodic() method. - * - * This class is provided by the NewCommands VendorDep - * - * @see ProfiledPIDController - * @deprecated Use a ProfiledPIDController instead - */ -template -class [[deprecated("Use a ProfiledPIDController instead")]] ProfiledPIDSubsystem - : public SubsystemBase { - using Distance_t = units::unit_t; - using Velocity = - units::compound_unit>; - using Velocity_t = units::unit_t; - using State = typename frc::TrapezoidProfile::State; - - public: - /** - * Creates a new ProfiledPIDSubsystem. - * - * @param controller the ProfiledPIDController to use - * @param initialPosition the initial goal position of the subsystem - */ - explicit ProfiledPIDSubsystem(frc::ProfiledPIDController controller, - Distance_t initialPosition = Distance_t{0}) - : m_controller{controller} { - SetGoal(initialPosition); - } - - void Periodic() override { - if (m_enabled) { - UseOutput(m_controller.Calculate(GetMeasurement()), - m_controller.GetSetpoint()); - } - } - - /** - * Sets the goal state for the subsystem. - * - * @param goal The goal state for the subsystem's motion profile. - */ - void SetGoal(State goal) { m_controller.SetGoal(goal); } - - /** - * Sets the goal state for the subsystem. Goal velocity assumed to be zero. - * - * @param goal The goal position for the subsystem's motion profile. - */ - void SetGoal(Distance_t goal) { SetGoal(State{goal, Velocity_t(0)}); } - - /** - * Enables the PID control. Resets the controller. - */ - virtual void Enable() { - m_controller.Reset(GetMeasurement()); - m_enabled = true; - } - - /** - * Disables the PID control. Sets output to zero. - */ - virtual void Disable() { - UseOutput(0, State{Distance_t(0), Velocity_t(0)}); - m_enabled = false; - } - - /** - * Returns whether the controller is enabled. - * - * @return Whether the controller is enabled. - */ - bool IsEnabled() { return m_enabled; } - - /** - * Returns the ProfiledPIDController. - * - * @return The controller. - */ - frc::ProfiledPIDController& GetController() { return m_controller; } - - protected: - /// Profiled PID controller. - frc::ProfiledPIDController m_controller; - - /// Whether the profiled PID controller output is enabled. - bool m_enabled{false}; - - /** - * Returns the measurement of the process variable used by the - * ProfiledPIDController. - * - * @return the measurement of the process variable - */ - virtual Distance_t GetMeasurement() = 0; - - /** - * Uses the output from the ProfiledPIDController. - * - * @param output the output of the ProfiledPIDController - * @param setpoint the setpoint state of the ProfiledPIDController, for - * feedforward - */ - virtual void UseOutput(double output, State setpoint) = 0; -}; -} // namespace frc2 diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileCommand.h deleted file mode 100644 index c44a8ce582..0000000000 --- a/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileCommand.h +++ /dev/null @@ -1,75 +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 "frc2/command/Command.h" -#include "frc2/command/CommandHelper.h" -#include "frc2/command/Requirements.h" - -namespace frc2 { -/** - * A command that runs a TrapezoidProfile. Useful for smoothly controlling - * mechanism motion. - * - * This class is provided by the NewCommands VendorDep - * - * @see TrapezoidProfile - */ -template -class TrapezoidProfileCommand - : public CommandHelper> { - using Distance_t = units::unit_t; - using Velocity = - units::compound_unit>; - using Velocity_t = units::unit_t; - using State = typename frc::TrapezoidProfile::State; - - public: - /** - * Creates a new TrapezoidProfileCommand that will execute the given - * TrapezoidalProfile. Output will be piped to the provided consumer function. - * - * @param profile The motion profile to execute. - * @param output The consumer for the profile output. - * @param goal The supplier for the desired state - * @param currentState The current state - * @param requirements The list of requirements. - * @deprecated Use a TrapezoidProfile instead - */ - [[deprecated("Use a TrapezoidProfile instead")]] - TrapezoidProfileCommand(frc::TrapezoidProfile profile, - std::function output, - std::function goal, - std::function currentState, - Requirements requirements = {}) - : m_profile(profile), - m_output(output), - m_goal(goal), - m_currentState(currentState) { - this->AddRequirements(requirements); - } - - void Initialize() override {} - - void Execute() override { - m_output(m_profile.Calculate(20_ms, m_currentState(), m_goal())); - } - - void End(bool interrupted) override {} - - bool IsFinished() override { return m_profile.IsFinished(0_s); } - - private: - frc::TrapezoidProfile m_profile; - std::function m_output; - std::function m_goal; - std::function m_currentState; -}; - -} // namespace frc2 diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileSubsystem.h b/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileSubsystem.h deleted file mode 100644 index 54b75254c8..0000000000 --- a/wpilibNewCommands/src/main/native/include/frc2/command/TrapezoidProfileSubsystem.h +++ /dev/null @@ -1,96 +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 "frc2/command/SubsystemBase.h" - -namespace frc2 { -/** - * A subsystem that generates and runs trapezoidal motion profiles - * automatically. The user specifies how to use the current state of the motion - * profile by overriding the `UseState` method. - * - * This class is provided by the NewCommands VendorDep - * @deprecated Use a TrapezoidProfile instead - */ -template -class [[deprecated("Use a TrapezoidProfile instead")]] TrapezoidProfileSubsystem - : public SubsystemBase { - using Distance_t = units::unit_t; - using Velocity = - units::compound_unit>; - using Velocity_t = units::unit_t; - using State = typename frc::TrapezoidProfile::State; - using Constraints = typename frc::TrapezoidProfile::Constraints; - - public: - /** - * Creates a new TrapezoidProfileSubsystem. - * - * @param constraints The constraints (maximum velocity and acceleration) - * for the profiles. - * @param initialPosition The initial position of the controller mechanism - * when the subsystem is constructed. - * @param period The period of the main robot loop, in seconds. - */ - explicit TrapezoidProfileSubsystem(Constraints constraints, - Distance_t initialPosition = Distance_t{0}, - units::second_t period = 20_ms) - : m_profile(constraints), - m_state{initialPosition, Velocity_t(0)}, - m_goal{initialPosition, Velocity_t{0}}, - m_period(period) {} - - void Periodic() override { - m_state = m_profile.Calculate(m_period, m_state, m_goal); - if (m_enabled) { - UseState(m_state); - } - } - - /** - * Sets the goal state for the subsystem. - * - * @param goal The goal state for the subsystem's motion profile. - */ - void SetGoal(State goal) { m_goal = goal; } - - /** - * Sets the goal state for the subsystem. Goal velocity assumed to be zero. - * - * @param goal The goal position for the subsystem's motion profile. - */ - void SetGoal(Distance_t goal) { m_goal = State{goal, Velocity_t(0)}; } - - protected: - /** - * Users should override this to consume the current state of the motion - * profile. - * - * @param state The current state of the motion profile. - */ - virtual void UseState(State state) = 0; - - /** - * Enable the TrapezoidProfileSubsystem's output. - */ - void Enable() { m_enabled = true; } - - /** - * Disable the TrapezoidProfileSubsystem's output. - */ - void Disable() { m_enabled = false; } - - private: - frc::TrapezoidProfile m_profile; - State m_state; - State m_goal; - units::second_t m_period; - bool m_enabled{false}; -}; -} // namespace frc2 diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/RobotContainer.h index c6f8afc703..2437852294 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/RobotContainer.h +++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/RobotContainer.h @@ -11,7 +11,6 @@ #include #include #include -#include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/RobotContainer.h index 4c7916456a..cdb993eaa8 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/RobotContainer.h +++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/RobotContainer.h @@ -11,7 +11,6 @@ #include #include #include -#include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/examples.json b/wpilibcExamples/src/main/cpp/examples/examples.json index f41a0ff278..db43c3002c 100644 --- a/wpilibcExamples/src/main/cpp/examples/examples.json +++ b/wpilibcExamples/src/main/cpp/examples/examples.json @@ -495,7 +495,7 @@ }, { "name": "DriveDistanceOffboard", - "description": "Drive a differential drivetrain a set distance using TrapezoidProfileCommand and smart motor controller PID.", + "description": "Drive a differential drivetrain a set distance using TrapezoidProfile and smart motor controller PID.", "tags": [ "Command-based", "Differential Drive", diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json index a82721dc68..57dc5fff60 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json @@ -461,7 +461,7 @@ }, { "name": "DriveDistanceOffboard", - "description": "Drive a differential drivetrain a set distance using TrapezoidProfileCommand and smart motor controller PID.", + "description": "Drive a differential drivetrain a set distance using TrapezoidProfile and smart motor controller PID.", "tags": [ "Command-based", "Differential Drive",