mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Add dependency injection of Subsystem to Command (#1275)
This commit is contained in:
committed by
Peter Johnson
parent
6df500e726
commit
e28295fc7b
@@ -135,6 +135,45 @@ public abstract class Command extends SendableBase {
|
||||
m_timeout = timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @throws IllegalArgumentException if given a negative timeout
|
||||
* @see Command#isTimedOut() isTimedOut()
|
||||
*/
|
||||
public Command(Subsystem requirement) {
|
||||
this();
|
||||
requires(requirement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new command with the given name.
|
||||
*
|
||||
* @param name the name for this command
|
||||
* @param requirement the subsystem that this command requires
|
||||
* @throws IllegalArgumentException if name is null
|
||||
*/
|
||||
public Command(String name, Subsystem requirement) {
|
||||
this(name);
|
||||
requires(requirement);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @throws IllegalArgumentException if given a negative timeout
|
||||
* @see Command#isTimedOut() isTimedOut()
|
||||
*/
|
||||
public Command(double timeout, Subsystem requirement) {
|
||||
this(timeout);
|
||||
requires(requirement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new command with the given name and timeout.
|
||||
*
|
||||
@@ -151,6 +190,21 @@ public abstract class Command extends SendableBase {
|
||||
m_timeout = timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @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) {
|
||||
this(name, timeout);
|
||||
requires(requirement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the timeout of this command.
|
||||
*
|
||||
|
||||
@@ -25,6 +25,23 @@ public class InstantCommand extends Command {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link InstantCommand InstantCommand} with the given requirement.
|
||||
* @param requirement the subsystem this command requires
|
||||
*/
|
||||
public InstantCommand(Subsystem requirement) {
|
||||
super(requirement);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public InstantCommand(String name, Subsystem requirement) {
|
||||
super(name, requirement);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isFinished() {
|
||||
return true;
|
||||
|
||||
@@ -93,7 +93,7 @@ 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.. It will also space the time between PID loop calculations to be equal
|
||||
* 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
|
||||
@@ -106,6 +106,71 @@ public abstract class PIDCommand extends Command {
|
||||
m_controller = new PIDController(p, i, d, m_source, m_output, period);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@SuppressWarnings("ParameterName")
|
||||
public PIDCommand(String name, double p, double i, double d, Subsystem requirement) {
|
||||
super(name, requirement);
|
||||
m_controller = new PIDController(p, i, d, m_source, m_output);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@SuppressWarnings("ParameterName")
|
||||
public PIDCommand(String name, double p, double i, double d, double period,
|
||||
Subsystem requirement) {
|
||||
super(name, requirement);
|
||||
m_controller = new PIDController(p, i, d, m_source, m_output, period);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@SuppressWarnings("ParameterName")
|
||||
public PIDCommand(double p, double i, double d, Subsystem requirement) {
|
||||
super(requirement);
|
||||
m_controller = new PIDController(p, i, d, m_source, m_output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a {@link PIDCommand} that will use the given p, i and d values. It will use the
|
||||
* 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
|
||||
*/
|
||||
@SuppressWarnings("ParameterName")
|
||||
public PIDCommand(double p, double i, double d, double period, Subsystem requirement) {
|
||||
super(requirement);
|
||||
m_controller = new PIDController(p, i, d, m_source, m_output, period);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link PIDController} used by this {@link PIDCommand}. Use this if you would like
|
||||
* to fine tune the pid loop.
|
||||
|
||||
@@ -15,7 +15,7 @@ public class TimedCommand extends Command {
|
||||
/**
|
||||
* Instantiates a TimedCommand with the given name and timeout.
|
||||
*
|
||||
* @param name the name of the command
|
||||
* @param name the name of the command
|
||||
* @param timeout the time the command takes to run (seconds)
|
||||
*/
|
||||
public TimedCommand(String name, double timeout) {
|
||||
@@ -31,6 +31,27 @@ public class TimedCommand extends Command {
|
||||
super(timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public TimedCommand(String name, double timeout, Subsystem requirement) {
|
||||
super(name, timeout, requirement);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public TimedCommand(double timeout, Subsystem requirement) {
|
||||
super(timeout, requirement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends command when timed out.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user