Fix some PIDCommand constructors not forwarding subsystems (#1299)

Also added missing constructor to wpilibc's InstantCommand and renamed
argument from requirement to subsystem as per
https://github.com/wpilibsuite/allwpilib/pull/1275#issuecomment-416071940.
This commit is contained in:
Tyler Veness
2018-09-02 14:18:12 -07:00
committed by Peter Johnson
parent c8482cd6d2
commit 0b113ad9ce
12 changed files with 119 additions and 113 deletions

View File

@@ -27,8 +27,8 @@ 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(Subsystem& subsystem) : Command("", -1.0) {
Requires(&subsystem);
}
Command::Command(const wpi::Twine& name, double timeout) : SendableBase(false) {
@@ -47,19 +47,18 @@ Command::Command(const wpi::Twine& name, double timeout) : SendableBase(false) {
}
}
Command::Command(const wpi::Twine& name, Subsystem& requirement)
Command::Command(const wpi::Twine& name, Subsystem& subsystem)
: Command(name, -1.0) {
Requires(&requirement);
Requires(&subsystem);
}
Command::Command(double timeout, Subsystem& requirement)
: Command("", timeout) {
Requires(&requirement);
Command::Command(double timeout, Subsystem& subsystem) : Command("", timeout) {
Requires(&subsystem);
}
Command::Command(const wpi::Twine& name, double timeout, Subsystem& requirement)
Command::Command(const wpi::Twine& name, double timeout, Subsystem& subsystem)
: Command(name, timeout) {
Requires(&requirement);
Requires(&subsystem);
}
double Command::TimeSinceInitialized() const {

View File

@@ -11,6 +11,8 @@ using namespace frc;
InstantCommand::InstantCommand(const wpi::Twine& name) : Command(name) {}
InstantCommand::InstantCommand(Subsystem& subsystem) : Command(subsystem) {}
InstantCommand::InstantCommand(const wpi::Twine& name, Subsystem& subsystem)
: Command(name, subsystem) {}

View File

@@ -42,35 +42,36 @@ PIDCommand::PIDCommand(double p, double i, double d, double period) {
}
PIDCommand::PIDCommand(const wpi::Twine& name, double p, double i, double d,
double f, double period, Subsystem& requirement)
: Command(name, requirement) {
double f, double period, Subsystem& subsystem)
: Command(name, subsystem) {
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) {
Subsystem& subsystem)
: Command(subsystem) {
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) {
Subsystem& subsystem)
: Command(name, subsystem) {
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) {
double period, Subsystem& subsystem)
: Command(name, subsystem) {
m_controller = std::make_shared<PIDController>(p, i, d, this, this, period);
}
PIDCommand::PIDCommand(double p, double i, double d, Subsystem& requirement) {
PIDCommand::PIDCommand(double p, double i, double d, Subsystem& subsystem) {
m_controller = std::make_shared<PIDController>(p, i, d, this, this);
}
PIDCommand::PIDCommand(double p, double i, double d, double period,
Subsystem& requirement) {
Subsystem& subsystem) {
m_controller = std::make_shared<PIDController>(p, i, d, this, this, period);
}

View File

@@ -15,10 +15,10 @@ 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) {}
Subsystem& subsystem)
: Command(name, timeout, subsystem) {}
TimedCommand::TimedCommand(double timeout, Subsystem& requirement)
: Command(timeout, requirement) {}
TimedCommand::TimedCommand(double timeout, Subsystem& subsystem)
: Command(timeout, subsystem) {}
bool TimedCommand::IsFinished() { return IsTimedOut(); }

View File

@@ -75,9 +75,9 @@ class Command : public ErrorBase, public SendableBase {
/**
* Creates a new command with the given timeout and a default name.
*
* @param requirement the subsystem that the command requires
* @param subsystem the subsystem that the command requires
*/
explicit Command(Subsystem& requirement);
explicit Command(Subsystem& subsystem);
/**
* Creates a new command with the given name and timeout.
@@ -91,29 +91,27 @@ class Command : public ErrorBase, public SendableBase {
/**
* Creates a new command with the given name and timeout.
*
* @param name the name of the command
* @param requirement the subsystem that the command requires
* @param name the name of the command
* @param subsystem the subsystem that the command requires
*/
Command(const wpi::Twine& name, Subsystem& requirement);
Command(const wpi::Twine& name, Subsystem& subsystem);
/**
* Creates a new command with the given name and timeout.
*
* @param timeout the time (in seconds) before this command "times out"
* @param requirement the subsystem that the command requires
* @see IsTimedOut()
* @param timeout the time (in seconds) before this command "times out"
* @param subsystem the subsystem that the command requires @see IsTimedOut()
*/
Command(double timeout, Subsystem& requirement);
Command(double timeout, Subsystem& subsystem);
/**
* Creates a new command with the given name and timeout.
*
* @param name the name of the command
* @param timeout the time (in seconds) before this command "times out"
* @param requirement the subsystem that the command requires
* @see IsTimedOut()
* @param name the name of the command
* @param timeout the time (in seconds) before this command "times out"
* @param subsystem the subsystem that the command requires @see IsTimedOut()
*/
Command(const wpi::Twine& name, double timeout, Subsystem& requirement);
Command(const wpi::Twine& name, double timeout, Subsystem& subsystem);
~Command() override = default;

View File

@@ -27,13 +27,20 @@ class InstantCommand : public Command {
*/
explicit InstantCommand(const wpi::Twine& name);
/**
* Creates a new InstantCommand with the given requirement.
*
* @param subsystem The subsystem that the command requires
*/
explicit InstantCommand(Subsystem& subsystem);
/**
* Creates a new InstantCommand with the given name.
*
* @param name The name for this command
* @param requirement The subsystem that the command requires
* @param name The name for this command
* @param subsystem The subsystem that the command requires
*/
InstantCommand(const wpi::Twine& name, Subsystem& requirement);
InstantCommand(const wpi::Twine& name, Subsystem& subsystem);
InstantCommand() = default;
virtual ~InstantCommand() = default;

View File

@@ -29,16 +29,15 @@ class PIDCommand : public Command, public PIDOutput, public PIDSource {
PIDCommand(double p, double i, double d, double period);
PIDCommand(double p, double i, double d, double f, double period);
PIDCommand(const wpi::Twine& name, double p, double i, double d,
Subsystem& requirement);
Subsystem& subsystem);
PIDCommand(const wpi::Twine& name, double p, double i, double d,
double period, Subsystem& requirement);
double period, Subsystem& subsystem);
PIDCommand(const wpi::Twine& name, double p, double i, double d, double f,
double period, Subsystem& requirement);
PIDCommand(double p, double i, double d, Subsystem& requirement);
PIDCommand(double p, double i, double d, double period,
Subsystem& requirement);
double period, Subsystem& subsystem);
PIDCommand(double p, double i, double d, Subsystem& subsystem);
PIDCommand(double p, double i, double d, double period, Subsystem& subsystem);
PIDCommand(double p, double i, double d, double f, double period,
Subsystem& requirement);
Subsystem& subsystem);
virtual ~PIDCommand() = default;
void SetSetpointRelative(double deltaSetpoint);

View File

@@ -38,19 +38,19 @@ class TimedCommand : public Command {
/**
* Creates a new TimedCommand with the given name and timeout.
*
* @param name the name of the command
* @param timeout the time (in seconds) before this command "times out"
* @param requirement the subsystem that the command requires
* @param name the name of the command
* @param timeout the time (in seconds) before this command "times out"
* @param subsystem the subsystem that the command requires
*/
TimedCommand(const wpi::Twine& name, double timeout, Subsystem& requirement);
TimedCommand(const wpi::Twine& name, double timeout, Subsystem& subsystem);
/**
* Creates a new WaitCommand with the given timeout.
*
* @param timeout the time (in seconds) before this command "times out"
* @param requirement the subsystem that the command requires
* @param timeout the time (in seconds) before this command "times out"
* @param subsystem the subsystem that the command requires
*/
TimedCommand(double timeout, Subsystem& requirement);
TimedCommand(double timeout, Subsystem& subsystem);
virtual ~TimedCommand() = default;