mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Add dependency injection of Subsystem to Command (#1275)
This commit is contained in:
committed by
Peter Johnson
parent
6df500e726
commit
e28295fc7b
@@ -27,6 +27,10 @@ Command::Command(const wpi::Twine& name) : Command(name, -1.0) {}
|
||||
|
||||
Command::Command(double timeout) : Command("", timeout) {}
|
||||
|
||||
Command::Command(Subsystem& requirement) : Command("", -1.0) {
|
||||
Requires(&requirement);
|
||||
}
|
||||
|
||||
Command::Command(const wpi::Twine& name, double timeout) : SendableBase(false) {
|
||||
// We use -1.0 to indicate no timeout.
|
||||
if (timeout < 0.0 && timeout != -1.0)
|
||||
@@ -43,6 +47,21 @@ Command::Command(const wpi::Twine& name, double timeout) : SendableBase(false) {
|
||||
}
|
||||
}
|
||||
|
||||
Command::Command(const wpi::Twine& name, Subsystem& requirement)
|
||||
: Command(name, -1.0) {
|
||||
Requires(&requirement);
|
||||
}
|
||||
|
||||
Command::Command(double timeout, Subsystem& requirement)
|
||||
: Command("", timeout) {
|
||||
Requires(&requirement);
|
||||
}
|
||||
|
||||
Command::Command(const wpi::Twine& name, double timeout, Subsystem& requirement)
|
||||
: Command(name, timeout) {
|
||||
Requires(&requirement);
|
||||
}
|
||||
|
||||
double Command::TimeSinceInitialized() const {
|
||||
if (m_startTime < 0.0)
|
||||
return 0.0;
|
||||
|
||||
@@ -11,4 +11,7 @@ using namespace frc;
|
||||
|
||||
InstantCommand::InstantCommand(const wpi::Twine& name) : Command(name) {}
|
||||
|
||||
InstantCommand::InstantCommand(const wpi::Twine& name, Subsystem& subsystem)
|
||||
: Command(name, subsystem) {}
|
||||
|
||||
bool InstantCommand::IsFinished() { return true; }
|
||||
|
||||
@@ -41,6 +41,39 @@ PIDCommand::PIDCommand(double p, double i, double d, double period) {
|
||||
m_controller = std::make_shared<PIDController>(p, i, d, this, this, period);
|
||||
}
|
||||
|
||||
PIDCommand::PIDCommand(const wpi::Twine& name, double p, double i, double d,
|
||||
double f, double period, Subsystem& requirement)
|
||||
: Command(name, requirement) {
|
||||
m_controller = std::make_shared<PIDController>(p, i, d, this, this, period);
|
||||
}
|
||||
|
||||
PIDCommand::PIDCommand(double p, double i, double d, double f, double period,
|
||||
Subsystem& requirement) {
|
||||
m_controller =
|
||||
std::make_shared<PIDController>(p, i, d, f, this, this, period);
|
||||
}
|
||||
|
||||
PIDCommand::PIDCommand(const wpi::Twine& name, double p, double i, double d,
|
||||
Subsystem& requirement)
|
||||
: Command(name) {
|
||||
m_controller = std::make_shared<PIDController>(p, i, d, this, this);
|
||||
}
|
||||
|
||||
PIDCommand::PIDCommand(const wpi::Twine& name, double p, double i, double d,
|
||||
double period, Subsystem& requirement)
|
||||
: Command(name) {
|
||||
m_controller = std::make_shared<PIDController>(p, i, d, this, this, period);
|
||||
}
|
||||
|
||||
PIDCommand::PIDCommand(double p, double i, double d, Subsystem& requirement) {
|
||||
m_controller = std::make_shared<PIDController>(p, i, d, this, this);
|
||||
}
|
||||
|
||||
PIDCommand::PIDCommand(double p, double i, double d, double period,
|
||||
Subsystem& requirement) {
|
||||
m_controller = std::make_shared<PIDController>(p, i, d, this, this, period);
|
||||
}
|
||||
|
||||
void PIDCommand::_Initialize() { m_controller->Enable(); }
|
||||
|
||||
void PIDCommand::_End() { m_controller->Disable(); }
|
||||
|
||||
@@ -14,4 +14,11 @@ TimedCommand::TimedCommand(const wpi::Twine& name, double timeout)
|
||||
|
||||
TimedCommand::TimedCommand(double timeout) : Command(timeout) {}
|
||||
|
||||
TimedCommand::TimedCommand(const wpi::Twine& name, double timeout,
|
||||
Subsystem& requirement)
|
||||
: Command(name, timeout, requirement) {}
|
||||
|
||||
TimedCommand::TimedCommand(double timeout, Subsystem& requirement)
|
||||
: Command(timeout, requirement) {}
|
||||
|
||||
bool TimedCommand::IsFinished() { return IsTimedOut(); }
|
||||
|
||||
Reference in New Issue
Block a user