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;

View File

@@ -139,39 +139,39 @@ public abstract class Command extends SendableBase {
* Creates a new command with the given timeout and a default name. The default name is the name
* of the class.
*
* @param requirement the subsystem that this command requires
* @param subsystem the subsystem that this command requires
* @throws IllegalArgumentException if given a negative timeout
* @see Command#isTimedOut() isTimedOut()
*/
public Command(Subsystem requirement) {
public Command(Subsystem subsystem) {
this();
requires(requirement);
requires(subsystem);
}
/**
* Creates a new command with the given name.
*
* @param name the name for this command
* @param requirement the subsystem that this command requires
* @param name the name for this command
* @param subsystem the subsystem that this command requires
* @throws IllegalArgumentException if name is null
*/
public Command(String name, Subsystem requirement) {
public Command(String name, Subsystem subsystem) {
this(name);
requires(requirement);
requires(subsystem);
}
/**
* Creates a new command with the given timeout and a default name. The default name is the name
* of the class.
*
* @param timeout the time (in seconds) before this command "times out"
* @param requirement the subsystem that this command requires
* @param timeout the time (in seconds) before this command "times out"
* @param subsystem the subsystem that this command requires
* @throws IllegalArgumentException if given a negative timeout
* @see Command#isTimedOut() isTimedOut()
*/
public Command(double timeout, Subsystem requirement) {
public Command(double timeout, Subsystem subsystem) {
this(timeout);
requires(requirement);
requires(subsystem);
}
/**
@@ -193,16 +193,16 @@ public abstract class Command extends SendableBase {
/**
* 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 this 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 this command requires
* @throws IllegalArgumentException if given a negative timeout
* @throws IllegalArgumentException if given a negative timeout or name was null.
* @see Command#isTimedOut() isTimedOut()
*/
public Command(String name, double timeout, Subsystem requirement) {
public Command(String name, double timeout, Subsystem subsystem) {
this(name, timeout);
requires(requirement);
requires(subsystem);
}
/**

View File

@@ -27,19 +27,19 @@ public class InstantCommand extends Command {
/**
* Creates a new {@link InstantCommand InstantCommand} with the given requirement.
* @param requirement the subsystem this command requires
* @param subsystem the subsystem this command requires
*/
public InstantCommand(Subsystem requirement) {
super(requirement);
public InstantCommand(Subsystem subsystem) {
super(subsystem);
}
/**
* Creates a new {@link InstantCommand InstantCommand} with the given name and requirement.
* @param name the name for this command
* @param requirement the subsystem this command requires
* @param name the name for this command
* @param subsystem the subsystem this command requires
*/
public InstantCommand(String name, Subsystem requirement) {
super(name, requirement);
public InstantCommand(String name, Subsystem subsystem) {
super(name, subsystem);
}
@Override

View File

@@ -109,15 +109,15 @@ public abstract class PIDCommand extends Command {
/**
* Instantiates a {@link PIDCommand} that will use the given p, i and d values.
*
* @param name the name of the command
* @param p the proportional value
* @param i the integral value
* @param d the derivative value
* @param requirement the subsystem that this command requires
* @param name the name of the command
* @param p the proportional value
* @param i the integral value
* @param d the derivative value
* @param subsystem the subsystem that this command requires
*/
@SuppressWarnings("ParameterName")
public PIDCommand(String name, double p, double i, double d, Subsystem requirement) {
super(name, requirement);
public PIDCommand(String name, double p, double i, double d, Subsystem subsystem) {
super(name, subsystem);
m_controller = new PIDController(p, i, d, m_source, m_output);
}
@@ -125,17 +125,17 @@ public abstract class PIDCommand extends Command {
* Instantiates a {@link PIDCommand} that will use the given p, i and d values. It will also space
* the time between PID loop calculations to be equal to the given period.
*
* @param name the name
* @param p the proportional value
* @param i the integral value
* @param d the derivative value
* @param period the time (in seconds) between calculations
* @param requirement the subsystem that this command requires
* @param name the name
* @param p the proportional value
* @param i the integral value
* @param d the derivative value
* @param period the time (in seconds) between calculations
* @param subsystem the subsystem that this command requires
*/
@SuppressWarnings("ParameterName")
public PIDCommand(String name, double p, double i, double d, double period,
Subsystem requirement) {
super(name, requirement);
Subsystem subsystem) {
super(name, subsystem);
m_controller = new PIDController(p, i, d, m_source, m_output, period);
}
@@ -143,14 +143,14 @@ public abstract class PIDCommand extends Command {
* Instantiates a {@link PIDCommand} that will use the given p, i and d values. It will use the
* class name as its name.
*
* @param p the proportional value
* @param i the integral value
* @param d the derivative value
* @param requirement the subsystem that this command requires
* @param p the proportional value
* @param i the integral value
* @param d the derivative value
* @param subsystem the subsystem that this command requires
*/
@SuppressWarnings("ParameterName")
public PIDCommand(double p, double i, double d, Subsystem requirement) {
super(requirement);
public PIDCommand(double p, double i, double d, Subsystem subsystem) {
super(subsystem);
m_controller = new PIDController(p, i, d, m_source, m_output);
}
@@ -159,15 +159,15 @@ public abstract class PIDCommand extends Command {
* class name as its name. It will also space the time between PID loop calculations to be equal
* to the given period.
*
* @param p the proportional value
* @param i the integral value
* @param d the derivative value
* @param period the time (in seconds) between calculations
* @param requirement the subsystem that this command requires
* @param p the proportional value
* @param i the integral value
* @param d the derivative value
* @param period the time (in seconds) between calculations
* @param subsystem the subsystem that this command requires
*/
@SuppressWarnings("ParameterName")
public PIDCommand(double p, double i, double d, double period, Subsystem requirement) {
super(requirement);
public PIDCommand(double p, double i, double d, double period, Subsystem subsystem) {
super(subsystem);
m_controller = new PIDController(p, i, d, m_source, m_output, period);
}

View File

@@ -34,22 +34,22 @@ public class TimedCommand extends Command {
/**
* Instantiates a TimedCommand with the given name and timeout.
*
* @param name the name of the command
* @param timeout the time the command takes to run (seconds)
* @param requirement the subsystem that this command requires
* @param name the name of the command
* @param timeout the time the command takes to run (seconds)
* @param subsystem the subsystem that this command requires
*/
public TimedCommand(String name, double timeout, Subsystem requirement) {
super(name, timeout, requirement);
public TimedCommand(String name, double timeout, Subsystem subsystem) {
super(name, timeout, subsystem);
}
/**
* Instantiates a TimedCommand with the given timeout.
*
* @param timeout the time the command takes to run (seconds)
* @param requirement the subsystem that this command requires
* @param timeout the time the command takes to run (seconds)
* @param subsystem the subsystem that this command requires
*/
public TimedCommand(double timeout, Subsystem requirement) {
super(timeout, requirement);
public TimedCommand(double timeout, Subsystem subsystem) {
super(timeout, subsystem);
}
/**