From 0b113ad9ce93447bee4ea0bc8dde44fd4c6d09f6 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Sun, 2 Sep 2018 14:18:12 -0700 Subject: [PATCH] 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. --- .../src/main/native/cpp/commands/Command.cpp | 17 +++--- .../native/cpp/commands/InstantCommand.cpp | 2 + .../main/native/cpp/commands/PIDCommand.cpp | 19 ++++--- .../main/native/cpp/commands/TimedCommand.cpp | 8 +-- .../native/include/frc/commands/Command.h | 26 ++++----- .../include/frc/commands/InstantCommand.h | 13 ++++- .../native/include/frc/commands/PIDCommand.h | 13 ++--- .../include/frc/commands/TimedCommand.h | 14 ++--- .../wpi/first/wpilibj/command/Command.java | 32 +++++------ .../first/wpilibj/command/InstantCommand.java | 14 ++--- .../wpi/first/wpilibj/command/PIDCommand.java | 56 +++++++++---------- .../first/wpilibj/command/TimedCommand.java | 18 +++--- 12 files changed, 119 insertions(+), 113 deletions(-) diff --git a/wpilibc/src/main/native/cpp/commands/Command.cpp b/wpilibc/src/main/native/cpp/commands/Command.cpp index 06e67b2ab0..ad7824a1b1 100644 --- a/wpilibc/src/main/native/cpp/commands/Command.cpp +++ b/wpilibc/src/main/native/cpp/commands/Command.cpp @@ -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 { diff --git a/wpilibc/src/main/native/cpp/commands/InstantCommand.cpp b/wpilibc/src/main/native/cpp/commands/InstantCommand.cpp index 3ee3c3ce07..cd07315998 100644 --- a/wpilibc/src/main/native/cpp/commands/InstantCommand.cpp +++ b/wpilibc/src/main/native/cpp/commands/InstantCommand.cpp @@ -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) {} diff --git a/wpilibc/src/main/native/cpp/commands/PIDCommand.cpp b/wpilibc/src/main/native/cpp/commands/PIDCommand.cpp index 1cd9114dc0..875d8fe28b 100644 --- a/wpilibc/src/main/native/cpp/commands/PIDCommand.cpp +++ b/wpilibc/src/main/native/cpp/commands/PIDCommand.cpp @@ -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(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(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(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(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(p, i, d, this, this); } PIDCommand::PIDCommand(double p, double i, double d, double period, - Subsystem& requirement) { + Subsystem& subsystem) { m_controller = std::make_shared(p, i, d, this, this, period); } diff --git a/wpilibc/src/main/native/cpp/commands/TimedCommand.cpp b/wpilibc/src/main/native/cpp/commands/TimedCommand.cpp index a8fc06be51..122751a3d3 100644 --- a/wpilibc/src/main/native/cpp/commands/TimedCommand.cpp +++ b/wpilibc/src/main/native/cpp/commands/TimedCommand.cpp @@ -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(); } diff --git a/wpilibc/src/main/native/include/frc/commands/Command.h b/wpilibc/src/main/native/include/frc/commands/Command.h index 1a74fea83a..ba509384a2 100644 --- a/wpilibc/src/main/native/include/frc/commands/Command.h +++ b/wpilibc/src/main/native/include/frc/commands/Command.h @@ -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; diff --git a/wpilibc/src/main/native/include/frc/commands/InstantCommand.h b/wpilibc/src/main/native/include/frc/commands/InstantCommand.h index 4a73c7580d..fc8f0581a9 100644 --- a/wpilibc/src/main/native/include/frc/commands/InstantCommand.h +++ b/wpilibc/src/main/native/include/frc/commands/InstantCommand.h @@ -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; diff --git a/wpilibc/src/main/native/include/frc/commands/PIDCommand.h b/wpilibc/src/main/native/include/frc/commands/PIDCommand.h index f607a1b3a6..b4709a80c6 100644 --- a/wpilibc/src/main/native/include/frc/commands/PIDCommand.h +++ b/wpilibc/src/main/native/include/frc/commands/PIDCommand.h @@ -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); diff --git a/wpilibc/src/main/native/include/frc/commands/TimedCommand.h b/wpilibc/src/main/native/include/frc/commands/TimedCommand.h index 30f3e3cc13..8bddf9272d 100644 --- a/wpilibc/src/main/native/include/frc/commands/TimedCommand.h +++ b/wpilibc/src/main/native/include/frc/commands/TimedCommand.h @@ -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; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Command.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Command.java index 4906312994..0033f58353 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Command.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Command.java @@ -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); } /** diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/InstantCommand.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/InstantCommand.java index 7dc6c9bcf7..98bd9e2e70 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/InstantCommand.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/InstantCommand.java @@ -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 diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/PIDCommand.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/PIDCommand.java index c9763e6600..3d7fd984ed 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/PIDCommand.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/PIDCommand.java @@ -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); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/TimedCommand.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/TimedCommand.java index 89bb06dbcf..6c9193b2d1 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/TimedCommand.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/TimedCommand.java @@ -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); } /**