[commands] Remove control commands and subsystems (#7921)

This commit is contained in:
Gold856
2025-04-26 05:06:26 +00:00
committed by GitHub
parent e2cc9e0059
commit 2f0990e9d2
18 changed files with 2 additions and 1421 deletions

View File

@@ -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 <functional>
#include <frc/controller/PIDController.h>
#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<Command, PIDCommand> {
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<double()> measurementSource,
std::function<double()> setpointSource,
std::function<void(double)> 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<double()> measurementSource, double setpoint,
std::function<void(double)> 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<double()> m_measurement;
/// Setpoint getter.
std::function<double()> m_setpoint;
/// PID controller output consumer.
std::function<void(double)> m_useOutput;
};
} // namespace frc2

View File

@@ -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 <frc/controller/PIDController.h>
#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

View File

@@ -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 <functional>
#include <utility>
#include <frc/controller/ProfiledPIDController.h>
#include <units/time.h>
#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<Distance>
*/
template <class Distance>
class ProfiledPIDCommand
: public CommandHelper<Command, ProfiledPIDCommand<Distance>> {
using Distance_t = units::unit_t<Distance>;
using Velocity =
units::compound_unit<Distance, units::inverse<units::seconds>>;
using Velocity_t = units::unit_t<Velocity>;
using State = typename frc::TrapezoidProfile<Distance>::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<Distance> controller,
std::function<Distance_t()> measurementSource,
std::function<State()> goalSource,
std::function<void(double, State)> 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<Distance> controller,
std::function<Distance_t()> measurementSource,
std::function<Distance_t()> goalSource,
std::function<void(double, State)> 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<Distance> controller,
std::function<Distance_t()> measurementSource, State goal,
std::function<void(double, State)> 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<Distance> controller,
std::function<Distance_t()> measurementSource,
Distance_t goal,
std::function<void(double, State)> 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<Distance>& GetController() { return m_controller; }
protected:
/// Profiled PID controller.
frc::ProfiledPIDController<Distance> m_controller;
/// Measurement getter.
std::function<Distance_t()> m_measurement;
/// Goal getter.
std::function<State()> m_goal;
/// Profiled PID controller output consumer.
std::function<void(double, State)> m_useOutput;
};
} // namespace frc2

View File

@@ -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 <frc/controller/ProfiledPIDController.h>
#include <units/time.h>
#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 Distance>
class [[deprecated("Use a ProfiledPIDController instead")]] ProfiledPIDSubsystem
: public SubsystemBase {
using Distance_t = units::unit_t<Distance>;
using Velocity =
units::compound_unit<Distance, units::inverse<units::seconds>>;
using Velocity_t = units::unit_t<Velocity>;
using State = typename frc::TrapezoidProfile<Distance>::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<Distance> 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<Distance>& GetController() { return m_controller; }
protected:
/// Profiled PID controller.
frc::ProfiledPIDController<Distance> 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

View File

@@ -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 <functional>
#include <frc/trajectory/TrapezoidProfile.h>
#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 Distance>
class TrapezoidProfileCommand
: public CommandHelper<Command, TrapezoidProfileCommand<Distance>> {
using Distance_t = units::unit_t<Distance>;
using Velocity =
units::compound_unit<Distance, units::inverse<units::seconds>>;
using Velocity_t = units::unit_t<Velocity>;
using State = typename frc::TrapezoidProfile<Distance>::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<Distance> profile,
std::function<void(State)> output,
std::function<State()> goal,
std::function<State()> 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<Distance> m_profile;
std::function<void(State)> m_output;
std::function<State()> m_goal;
std::function<State()> m_currentState;
};
} // namespace frc2

View File

@@ -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 <frc/trajectory/TrapezoidProfile.h>
#include <units/time.h>
#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 Distance>
class [[deprecated("Use a TrapezoidProfile instead")]] TrapezoidProfileSubsystem
: public SubsystemBase {
using Distance_t = units::unit_t<Distance>;
using Velocity =
units::compound_unit<Distance, units::inverse<units::seconds>>;
using Velocity_t = units::unit_t<Velocity>;
using State = typename frc::TrapezoidProfile<Distance>::State;
using Constraints = typename frc::TrapezoidProfile<Distance>::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<Distance> m_profile;
State m_state;
State m_goal;
units::second_t m_period;
bool m_enabled{false};
};
} // namespace frc2