mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-04 03:11:43 +00:00
[build] Apply spotless for java formatting (#1768)
Update checkstyle config to be compatible with spotless. Co-authored-by: Austin Shalit <austinshalit@gmail.com>
This commit is contained in:
@@ -9,9 +9,7 @@ import edu.wpi.first.networktables.NetworkTablesJNI;
|
||||
import edu.wpi.first.wpiutil.RuntimeDetector;
|
||||
|
||||
public final class DevMain {
|
||||
/**
|
||||
* Main entry point.
|
||||
*/
|
||||
/** Main entry point. */
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
System.out.println(RuntimeDetector.getPlatformPath());
|
||||
@@ -19,6 +17,5 @@ public final class DevMain {
|
||||
System.out.println(HALUtil.getHALRuntimeType());
|
||||
}
|
||||
|
||||
private DevMain() {
|
||||
}
|
||||
private DevMain() {}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public abstract class Button extends Trigger {
|
||||
/**
|
||||
* Constantly starts the given command while the button is held.
|
||||
*
|
||||
* {@link Command#start()} will be called repeatedly while the button is held, and will be
|
||||
* <p>{@link Command#start()} will be called repeatedly while the button is held, and will be
|
||||
* canceled when the button is released.
|
||||
*
|
||||
* @param command the command to start
|
||||
|
||||
@@ -12,9 +12,7 @@ public class InternalButton extends Button {
|
||||
private boolean m_pressed;
|
||||
private boolean m_inverted;
|
||||
|
||||
/**
|
||||
* Creates an InternalButton that is not inverted.
|
||||
*/
|
||||
/** Creates an InternalButton that is not inverted. */
|
||||
public InternalButton() {
|
||||
this(false);
|
||||
}
|
||||
@@ -23,7 +21,7 @@ public class InternalButton extends Button {
|
||||
* Creates an InternalButton which is inverted depending on the input.
|
||||
*
|
||||
* @param inverted if false, then this button is pressed when set to true, otherwise it is pressed
|
||||
* when set to false.
|
||||
* when set to false.
|
||||
*/
|
||||
public InternalButton(boolean inverted) {
|
||||
m_pressed = m_inverted = inverted;
|
||||
|
||||
@@ -6,9 +6,7 @@ package edu.wpi.first.wpilibj.buttons;
|
||||
|
||||
import edu.wpi.first.wpilibj.GenericHID;
|
||||
|
||||
/**
|
||||
* A {@link Button} that gets its state from a {@link GenericHID}.
|
||||
*/
|
||||
/** A {@link Button} that gets its state from a {@link GenericHID}. */
|
||||
public class JoystickButton extends Button {
|
||||
private final GenericHID m_joystick;
|
||||
private final int m_buttonNumber;
|
||||
@@ -16,8 +14,7 @@ public class JoystickButton extends Button {
|
||||
/**
|
||||
* Create a joystick button for triggering commands.
|
||||
*
|
||||
* @param joystick The GenericHID object that has the button (e.g. Joystick, KinectStick,
|
||||
* etc)
|
||||
* @param joystick The GenericHID object that has the button (e.g. Joystick, KinectStick, etc)
|
||||
* @param buttonNumber The button number (see {@link GenericHID#getRawButton(int) }
|
||||
*/
|
||||
public JoystickButton(GenericHID joystick, int buttonNumber) {
|
||||
|
||||
@@ -8,9 +8,7 @@ import edu.wpi.first.networktables.NetworkTable;
|
||||
import edu.wpi.first.networktables.NetworkTableEntry;
|
||||
import edu.wpi.first.networktables.NetworkTableInstance;
|
||||
|
||||
/**
|
||||
* A {@link Button} that uses a {@link NetworkTable} boolean field.
|
||||
*/
|
||||
/** A {@link Button} that uses a {@link NetworkTable} boolean field. */
|
||||
public class NetworkButton extends Button {
|
||||
private final NetworkTableEntry m_entry;
|
||||
|
||||
|
||||
@@ -6,9 +6,7 @@ package edu.wpi.first.wpilibj.buttons;
|
||||
|
||||
import edu.wpi.first.wpilibj.GenericHID;
|
||||
|
||||
/**
|
||||
* A {@link Button} that gets its state from a POV on a {@link GenericHID}.
|
||||
*/
|
||||
/** A {@link Button} that gets its state from a POV on a {@link GenericHID}. */
|
||||
public class POVButton extends Button {
|
||||
private final GenericHID m_joystick;
|
||||
private final int m_angle;
|
||||
@@ -28,8 +26,7 @@ public class POVButton extends Button {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a POV button for triggering commands.
|
||||
* By default, acts on POV 0
|
||||
* Creates a POV button for triggering commands. By default, acts on POV 0
|
||||
*
|
||||
* @param joystick The GenericHID object that has the POV
|
||||
* @param angle The desired angle (e.g. 90, 270)
|
||||
|
||||
@@ -12,8 +12,8 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
/**
|
||||
* This class provides an easy way to link commands to inputs.
|
||||
*
|
||||
* <p>It is very easy to link a button to a command. For instance, you could link the trigger
|
||||
* button of a joystick to a "score" command.
|
||||
* <p>It is very easy to link a button to a command. For instance, you could link the trigger button
|
||||
* of a joystick to a "score" command.
|
||||
*
|
||||
* <p>It is encouraged that teams write a subclass of Trigger if they want to have something unusual
|
||||
* (for instance, if they want to react to the user holding a button while the robot is reading a
|
||||
@@ -66,7 +66,7 @@ public abstract class Trigger implements Sendable {
|
||||
/**
|
||||
* Constantly starts the given command while the button is held.
|
||||
*
|
||||
* {@link Command#start()} will be called repeatedly while the trigger is active, and will be
|
||||
* <p>{@link Command#start()} will be called repeatedly while the trigger is active, and will be
|
||||
* canceled when the trigger becomes inactive.
|
||||
*
|
||||
* @param command the command to start
|
||||
|
||||
@@ -4,13 +4,12 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
import edu.wpi.first.wpilibj.RobotState;
|
||||
import edu.wpi.first.wpilibj.Sendable;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* The Command class is at the very core of the entire command framework. Every command can be
|
||||
@@ -19,16 +18,16 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
|
||||
* execute()} until the {@link Command#isFinished() isFinished()} returns true. Once it does, {@link
|
||||
* Command#end() end()} will be called.
|
||||
*
|
||||
* <p>However, if at any point while it is running {@link Command#cancel() cancel()} is called,
|
||||
* then the command will be stopped and {@link Command#interrupted() interrupted()} will be called.
|
||||
* <p>However, if at any point while it is running {@link Command#cancel() cancel()} is called, then
|
||||
* the command will be stopped and {@link Command#interrupted() interrupted()} will be called.
|
||||
*
|
||||
* <p>If a command uses a {@link Subsystem}, then it should specify that it does so by calling the
|
||||
* {@link Command#requires(Subsystem) requires(...)} method in its constructor. Note that a Command
|
||||
* may have multiple requirements, and {@link Command#requires(Subsystem) requires(...)} should be
|
||||
* called for each one.
|
||||
*
|
||||
* <p>If a command is running and a new command with shared requirements is started, then one of
|
||||
* two things will happen. If the active command is interruptible, then {@link Command#cancel()
|
||||
* <p>If a command is running and a new command with shared requirements is started, then one of two
|
||||
* things will happen. If the active command is interruptible, then {@link Command#cancel()
|
||||
* cancel()} will be called and the command will be removed to make way for the new one. If the
|
||||
* active command is not interruptible, the other one will not even be started, and the active one
|
||||
* will continue functioning.
|
||||
@@ -38,64 +37,40 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
|
||||
* @see IllegalUseOfCommandException
|
||||
*/
|
||||
public abstract class Command implements Sendable, AutoCloseable {
|
||||
/**
|
||||
* The time since this command was initialized.
|
||||
*/
|
||||
/** The time since this command was initialized. */
|
||||
private double m_startTime = -1;
|
||||
|
||||
/**
|
||||
* The time (in seconds) before this command "times out" (or -1 if no timeout).
|
||||
*/
|
||||
/** The time (in seconds) before this command "times out" (or -1 if no timeout). */
|
||||
private double m_timeout = -1;
|
||||
|
||||
/**
|
||||
* Whether or not this command has been initialized.
|
||||
*/
|
||||
/** Whether or not this command has been initialized. */
|
||||
private boolean m_initialized;
|
||||
|
||||
/**
|
||||
* The required subsystems.
|
||||
*/
|
||||
/** The required subsystems. */
|
||||
private final Set m_requirements = new Set();
|
||||
|
||||
/**
|
||||
* Whether or not it is running.
|
||||
*/
|
||||
/** Whether or not it is running. */
|
||||
private boolean m_running;
|
||||
|
||||
/**
|
||||
* Whether or not it is interruptible.
|
||||
*/
|
||||
/** Whether or not it is interruptible. */
|
||||
private boolean m_interruptible = true;
|
||||
|
||||
/**
|
||||
* Whether or not it has been canceled.
|
||||
*/
|
||||
/** Whether or not it has been canceled. */
|
||||
private boolean m_canceled;
|
||||
|
||||
/**
|
||||
* Whether or not it has been locked.
|
||||
*/
|
||||
/** Whether or not it has been locked. */
|
||||
private boolean m_locked;
|
||||
|
||||
/**
|
||||
* Whether this command should run when the robot is disabled.
|
||||
*/
|
||||
/** Whether this command should run when the robot is disabled. */
|
||||
private boolean m_runWhenDisabled;
|
||||
|
||||
/**
|
||||
* Whether or not this command has completed running.
|
||||
*/
|
||||
/** Whether or not this command has completed running. */
|
||||
private boolean m_completed;
|
||||
|
||||
/**
|
||||
* The {@link CommandGroup} this is in.
|
||||
*/
|
||||
/** The {@link CommandGroup} this is in. */
|
||||
private CommandGroup m_parent;
|
||||
|
||||
/**
|
||||
* Creates a new command. The name of this command will be set to its class name.
|
||||
*/
|
||||
/** Creates a new command. The name of this command will be set to its class name. */
|
||||
public Command() {
|
||||
String name = getClass().getName();
|
||||
SendableRegistry.add(this, name.substring(name.lastIndexOf('.') + 1));
|
||||
@@ -146,7 +121,7 @@ public abstract class Command implements Sendable, AutoCloseable {
|
||||
/**
|
||||
* Creates a new command with the given name.
|
||||
*
|
||||
* @param name the name for this command
|
||||
* @param name the name for this command
|
||||
* @param subsystem the subsystem that this command requires
|
||||
* @throws IllegalArgumentException if name is null
|
||||
*/
|
||||
@@ -159,7 +134,7 @@ public abstract class Command implements Sendable, AutoCloseable {
|
||||
* 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 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()
|
||||
@@ -172,7 +147,7 @@ public abstract class Command implements Sendable, AutoCloseable {
|
||||
/**
|
||||
* Creates a new command with the given name and timeout.
|
||||
*
|
||||
* @param name the name of the command
|
||||
* @param name the name of the command
|
||||
* @param timeout the time (in seconds) before this command "times out"
|
||||
* @throws IllegalArgumentException if given a negative timeout or name was null.
|
||||
* @see Command#isTimedOut() isTimedOut()
|
||||
@@ -188,8 +163,8 @@ public abstract class Command implements Sendable, AutoCloseable {
|
||||
/**
|
||||
* 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 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.
|
||||
@@ -236,9 +211,9 @@ public abstract class Command implements Sendable, AutoCloseable {
|
||||
* <p>Note that the recommended way to call this method is in the constructor.
|
||||
*
|
||||
* @param subsystem the {@link Subsystem} required
|
||||
* @throws IllegalArgumentException if subsystem is null
|
||||
* @throws IllegalArgumentException if subsystem is null
|
||||
* @throws IllegalUseOfCommandException if this command has started before or if it has been given
|
||||
* to a {@link CommandGroup}
|
||||
* to a {@link CommandGroup}
|
||||
* @see Subsystem
|
||||
*/
|
||||
protected synchronized void requires(Subsystem subsystem) {
|
||||
@@ -293,30 +268,20 @@ public abstract class Command implements Sendable, AutoCloseable {
|
||||
return !isFinished();
|
||||
}
|
||||
|
||||
/**
|
||||
* The initialize method is called the first time this Command is run after being started.
|
||||
*/
|
||||
/** The initialize method is called the first time this Command is run after being started. */
|
||||
protected void initialize() {}
|
||||
|
||||
/**
|
||||
* A shadow method called before {@link Command#initialize() initialize()}.
|
||||
*/
|
||||
/** A shadow method called before {@link Command#initialize() initialize()}. */
|
||||
@SuppressWarnings("MethodName")
|
||||
void _initialize() {
|
||||
}
|
||||
void _initialize() {}
|
||||
|
||||
/**
|
||||
* The execute method is called repeatedly until this Command either finishes or is canceled.
|
||||
*/
|
||||
/** The execute method is called repeatedly until this Command either finishes or is canceled. */
|
||||
@SuppressWarnings("MethodName")
|
||||
protected void execute() {}
|
||||
|
||||
/**
|
||||
* A shadow method called before {@link Command#execute() execute()}.
|
||||
*/
|
||||
/** A shadow method called before {@link Command#execute() execute()}. */
|
||||
@SuppressWarnings("MethodName")
|
||||
void _execute() {
|
||||
}
|
||||
void _execute() {}
|
||||
|
||||
/**
|
||||
* Returns whether this command is finished. If it is, then the command will be removed and {@link
|
||||
@@ -326,9 +291,8 @@ public abstract class Command implements Sendable, AutoCloseable {
|
||||
* method for time-sensitive commands.
|
||||
*
|
||||
* <p>Returning false will result in the command never ending automatically. It may still be
|
||||
* canceled manually or interrupted by another command. Returning true will result in the
|
||||
* command executing once and finishing immediately. We recommend using {@link InstantCommand}
|
||||
* for this.
|
||||
* canceled manually or interrupted by another command. Returning true will result in the command
|
||||
* executing once and finishing immediately. We recommend using {@link InstantCommand} for this.
|
||||
*
|
||||
* @return whether this command is finished.
|
||||
* @see Command#isTimedOut() isTimedOut()
|
||||
@@ -341,12 +305,9 @@ public abstract class Command implements Sendable, AutoCloseable {
|
||||
*/
|
||||
protected void end() {}
|
||||
|
||||
/**
|
||||
* A shadow method called after {@link Command#end() end()}.
|
||||
*/
|
||||
/** A shadow method called after {@link Command#end() end()}. */
|
||||
@SuppressWarnings("MethodName")
|
||||
void _end() {
|
||||
}
|
||||
void _end() {}
|
||||
|
||||
/**
|
||||
* Called when the command ends because somebody called {@link Command#cancel() cancel()} or
|
||||
@@ -362,9 +323,7 @@ public abstract class Command implements Sendable, AutoCloseable {
|
||||
end();
|
||||
}
|
||||
|
||||
/**
|
||||
* A shadow method called after {@link Command#interrupted() interrupted()}.
|
||||
*/
|
||||
/** A shadow method called after {@link Command#interrupted() interrupted()}. */
|
||||
@SuppressWarnings("MethodName")
|
||||
void _interrupted() {}
|
||||
|
||||
@@ -392,15 +351,13 @@ public abstract class Command implements Sendable, AutoCloseable {
|
||||
* Subsystems}) of this command.
|
||||
*
|
||||
* @return the requirements (as an {@link Enumeration Enumeration} of {@link Subsystem
|
||||
* Subsystems}) of this command
|
||||
* Subsystems}) of this command
|
||||
*/
|
||||
synchronized Enumeration getRequirements() {
|
||||
return m_requirements.getElements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents further changes from being made.
|
||||
*/
|
||||
/** Prevents further changes from being made. */
|
||||
synchronized void lockChanges() {
|
||||
m_locked = true;
|
||||
}
|
||||
@@ -412,8 +369,8 @@ public abstract class Command implements Sendable, AutoCloseable {
|
||||
*/
|
||||
synchronized void validate(String message) {
|
||||
if (m_locked) {
|
||||
throw new IllegalUseOfCommandException(message
|
||||
+ " after being started or being added to a command group");
|
||||
throw new IllegalUseOfCommandException(
|
||||
message + " after being started or being added to a command group");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -442,18 +399,18 @@ public abstract class Command implements Sendable, AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears list of subsystem requirements. This is only used by
|
||||
* {@link ConditionalCommand} so canceling the chosen command works properly
|
||||
* in {@link CommandGroup}.
|
||||
* Clears list of subsystem requirements. This is only used by {@link ConditionalCommand} so
|
||||
* canceling the chosen command works properly in {@link CommandGroup}.
|
||||
*/
|
||||
protected void clearRequirements() {
|
||||
m_requirements.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts up the command. Gets the command ready to start. <p> Note that the command will
|
||||
* eventually start, however it will not necessarily do so immediately, and may in fact be
|
||||
* canceled before initialize is even called. </p>
|
||||
* Starts up the command. Gets the command ready to start.
|
||||
*
|
||||
* <p>Note that the command will eventually start, however it will not necessarily do so
|
||||
* immediately, and may in fact be canceled before initialize is even called.
|
||||
*
|
||||
* @throws IllegalUseOfCommandException if the command is a part of a CommandGroup
|
||||
*/
|
||||
@@ -492,18 +449,21 @@ public abstract class Command implements Sendable, AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* This will cancel the current command. <p> This will cancel the current command eventually. It
|
||||
* can be called multiple times. And it can be called when the command is not running. If the
|
||||
* command is running though, then the command will be marked as canceled and eventually removed.
|
||||
* </p> <p> A command can not be canceled if it is a part of a command group, you must cancel the
|
||||
* command group instead. </p>
|
||||
* This will cancel the current command.
|
||||
*
|
||||
* <p>This will cancel the current command eventually. It can be called multiple times. And it can
|
||||
* be called when the command is not running. If the command is running though, then the command
|
||||
* will be marked as canceled and eventually removed.
|
||||
*
|
||||
* <p>A command can not be canceled if it is a part of a command group, you must cancel the
|
||||
* command group instead.
|
||||
*
|
||||
* @throws IllegalUseOfCommandException if this command is a part of a command group
|
||||
*/
|
||||
public synchronized void cancel() {
|
||||
if (m_parent != null) {
|
||||
throw new IllegalUseOfCommandException("Can not manually cancel a command in a command "
|
||||
+ "group");
|
||||
throw new IllegalUseOfCommandException(
|
||||
"Can not manually cancel a command in a command " + "group");
|
||||
}
|
||||
_cancel();
|
||||
}
|
||||
@@ -650,17 +610,20 @@ public abstract class Command implements Sendable, AutoCloseable {
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
builder.setSmartDashboardType("Command");
|
||||
builder.addStringProperty(".name", this::getName, null);
|
||||
builder.addBooleanProperty("running", this::isRunning, value -> {
|
||||
if (value) {
|
||||
if (!isRunning()) {
|
||||
start();
|
||||
}
|
||||
} else {
|
||||
if (isRunning()) {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.addBooleanProperty(
|
||||
"running",
|
||||
this::isRunning,
|
||||
value -> {
|
||||
if (value) {
|
||||
if (!isRunning()) {
|
||||
start();
|
||||
}
|
||||
} else {
|
||||
if (isRunning()) {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.addBooleanProperty(".isParented", this::isParented, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,55 +4,48 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* A {@link CommandGroup} is a list of commands which are executed in sequence.
|
||||
*
|
||||
* <p> Commands in a {@link CommandGroup} are added using the {@link
|
||||
* <p>Commands in a {@link CommandGroup} are added using the {@link
|
||||
* CommandGroup#addSequential(Command) addSequential(...)} method and are called sequentially.
|
||||
* {@link CommandGroup CommandGroups} are themselves {@link Command commands} and can be given to
|
||||
* other {@link CommandGroup CommandGroups}. </p>
|
||||
* other {@link CommandGroup CommandGroups}.
|
||||
*
|
||||
* <p> {@link CommandGroup CommandGroups} will carry all of the requirements of their {@link Command
|
||||
* <p>{@link CommandGroup CommandGroups} will carry all of the requirements of their {@link Command
|
||||
* subcommands}. Additional requirements can be specified by calling {@link
|
||||
* CommandGroup#requires(Subsystem) requires(...)} normally in the constructor. </P>
|
||||
* CommandGroup#requires(Subsystem) requires(...)} normally in the constructor.
|
||||
*
|
||||
* <p> CommandGroups can also execute commands in parallel, simply by adding them using {@link
|
||||
* CommandGroup#addParallel(Command) addParallel(...)}. </p>
|
||||
* <p>CommandGroups can also execute commands in parallel, simply by adding them using {@link
|
||||
* CommandGroup#addParallel(Command) addParallel(...)}.
|
||||
*
|
||||
* @see Command
|
||||
* @see Subsystem
|
||||
* @see IllegalUseOfCommandException
|
||||
*/
|
||||
public class CommandGroup extends Command {
|
||||
/**
|
||||
* The commands in this group (stored in entries).
|
||||
*/
|
||||
/** The commands in this group (stored in entries). */
|
||||
@SuppressWarnings({"PMD.LooseCoupling", "PMD.UseArrayListInsteadOfVector"})
|
||||
private final Vector<Entry> m_commands = new Vector<>();
|
||||
/*
|
||||
* Intentionally package private
|
||||
*/
|
||||
/**
|
||||
* The active children in this group (stored in entries).
|
||||
*/
|
||||
/** The active children in this group (stored in entries). */
|
||||
@SuppressWarnings({"PMD.LooseCoupling", "PMD.UseArrayListInsteadOfVector"})
|
||||
final Vector<Entry> m_children = new Vector<>();
|
||||
/**
|
||||
* The current command, -1 signifies that none have been run.
|
||||
*/
|
||||
/** The current command, -1 signifies that none have been run. */
|
||||
private int m_currentCommandIndex = -1;
|
||||
|
||||
/**
|
||||
* Creates a new {@link CommandGroup CommandGroup}. The name of this command will be set to its
|
||||
* class name.
|
||||
*/
|
||||
public CommandGroup() {
|
||||
}
|
||||
public CommandGroup() {}
|
||||
|
||||
/**
|
||||
* Creates a new {@link CommandGroup CommandGroup} with the given name.
|
||||
@@ -68,16 +61,16 @@ public class CommandGroup extends Command {
|
||||
* Adds a new {@link Command Command} to the group. The {@link Command Command} will be started
|
||||
* after all the previously added {@link Command Commands}.
|
||||
*
|
||||
* <p> Note that any requirements the given {@link Command Command} has will be added to the
|
||||
* group. For this reason, a {@link Command Command's} requirements can not be changed after being
|
||||
* added to a group. </p>
|
||||
* <p>Note that any requirements the given {@link Command Command} has will be added to the group.
|
||||
* For this reason, a {@link Command Command's} requirements can not be changed after being added
|
||||
* to a group.
|
||||
*
|
||||
* <p> It is recommended that this method be called in the constructor. </p>
|
||||
* <p>It is recommended that this method be called in the constructor.
|
||||
*
|
||||
* @param command The {@link Command Command} to be added
|
||||
* @throws IllegalUseOfCommandException if the group has been started before or been given to
|
||||
* another group
|
||||
* @throws IllegalArgumentException if command is null
|
||||
* another group
|
||||
* @throws IllegalArgumentException if command is null
|
||||
*/
|
||||
public final synchronized void addSequential(Command command) {
|
||||
validate("Can not add new command to command group");
|
||||
@@ -97,22 +90,22 @@ public class CommandGroup extends Command {
|
||||
* Adds a new {@link Command Command} to the group with a given timeout. The {@link Command
|
||||
* Command} will be started after all the previously added commands.
|
||||
*
|
||||
* <p> Once the {@link Command Command} is started, it will be run until it finishes or the time
|
||||
* <p>Once the {@link Command Command} is started, it will be run until it finishes or the time
|
||||
* expires, whichever is sooner. Note that the given {@link Command Command} will have no
|
||||
* knowledge that it is on a timer. </p>
|
||||
* knowledge that it is on a timer.
|
||||
*
|
||||
* <p> Note that any requirements the given {@link Command Command} has will be added to the
|
||||
* group. For this reason, a {@link Command Command's} requirements can not be changed after being
|
||||
* added to a group. </p>
|
||||
* <p>Note that any requirements the given {@link Command Command} has will be added to the group.
|
||||
* For this reason, a {@link Command Command's} requirements can not be changed after being added
|
||||
* to a group.
|
||||
*
|
||||
* <p> It is recommended that this method be called in the constructor. </p>
|
||||
* <p>It is recommended that this method be called in the constructor.
|
||||
*
|
||||
* @param command The {@link Command Command} to be added
|
||||
* @param timeout The timeout (in seconds)
|
||||
* @throws IllegalUseOfCommandException if the group has been started before or been given to
|
||||
* another group or if the {@link Command Command} has been
|
||||
* started before or been given to another group
|
||||
* @throws IllegalArgumentException if command is null or timeout is negative
|
||||
* another group or if the {@link Command Command} has been started before or been given to
|
||||
* another group
|
||||
* @throws IllegalArgumentException if command is null or timeout is negative
|
||||
*/
|
||||
public final synchronized void addSequential(Command command, double timeout) {
|
||||
validate("Can not add new command to command group");
|
||||
@@ -135,22 +128,22 @@ public class CommandGroup extends Command {
|
||||
* Adds a new child {@link Command} to the group. The {@link Command} will be started after all
|
||||
* the previously added {@link Command Commands}.
|
||||
*
|
||||
* <p> Instead of waiting for the child to finish, a {@link CommandGroup} will have it run at the
|
||||
* <p>Instead of waiting for the child to finish, a {@link CommandGroup} will have it run at the
|
||||
* same time as the subsequent {@link Command Commands}. The child will run until either it
|
||||
* finishes, a new child with conflicting requirements is started, or the main sequence runs a
|
||||
* {@link Command} with conflicting requirements. In the latter two cases, the child will be
|
||||
* canceled even if it says it can't be interrupted. </p>
|
||||
* canceled even if it says it can't be interrupted.
|
||||
*
|
||||
* <p> Note that any requirements the given {@link Command Command} has will be added to the
|
||||
* group. For this reason, a {@link Command Command's} requirements can not be changed after being
|
||||
* added to a group. </p>
|
||||
* <p>Note that any requirements the given {@link Command Command} has will be added to the group.
|
||||
* For this reason, a {@link Command Command's} requirements can not be changed after being added
|
||||
* to a group.
|
||||
*
|
||||
* <p> It is recommended that this method be called in the constructor. </p>
|
||||
* <p>It is recommended that this method be called in the constructor.
|
||||
*
|
||||
* @param command The command to be added
|
||||
* @throws IllegalUseOfCommandException if the group has been started before or been given to
|
||||
* another command group
|
||||
* @throws IllegalArgumentException if command is null
|
||||
* another command group
|
||||
* @throws IllegalArgumentException if command is null
|
||||
*/
|
||||
public final synchronized void addParallel(Command command) {
|
||||
requireNonNull(command, "Provided command was null");
|
||||
@@ -168,27 +161,27 @@ public class CommandGroup extends Command {
|
||||
* Adds a new child {@link Command} to the group with the given timeout. The {@link Command} will
|
||||
* be started after all the previously added {@link Command Commands}.
|
||||
*
|
||||
* <p> Once the {@link Command Command} is started, it will run until it finishes, is interrupted,
|
||||
* <p>Once the {@link Command Command} is started, it will run until it finishes, is interrupted,
|
||||
* or the time expires, whichever is sooner. Note that the given {@link Command Command} will have
|
||||
* no knowledge that it is on a timer. </p>
|
||||
* no knowledge that it is on a timer.
|
||||
*
|
||||
* <p> Instead of waiting for the child to finish, a {@link CommandGroup} will have it run at the
|
||||
* <p>Instead of waiting for the child to finish, a {@link CommandGroup} will have it run at the
|
||||
* same time as the subsequent {@link Command Commands}. The child will run until either it
|
||||
* finishes, the timeout expires, a new child with conflicting requirements is started, or the
|
||||
* main sequence runs a {@link Command} with conflicting requirements. In the latter two cases,
|
||||
* the child will be canceled even if it says it can't be interrupted. </p>
|
||||
* the child will be canceled even if it says it can't be interrupted.
|
||||
*
|
||||
* <p> Note that any requirements the given {@link Command Command} has will be added to the
|
||||
* group. For this reason, a {@link Command Command's} requirements can not be changed after being
|
||||
* added to a group. </p>
|
||||
* <p>Note that any requirements the given {@link Command Command} has will be added to the group.
|
||||
* For this reason, a {@link Command Command's} requirements can not be changed after being added
|
||||
* to a group.
|
||||
*
|
||||
* <p> It is recommended that this method be called in the constructor. </p>
|
||||
* <p>It is recommended that this method be called in the constructor.
|
||||
*
|
||||
* @param command The command to be added
|
||||
* @param timeout The timeout (in seconds)
|
||||
* @throws IllegalUseOfCommandException if the group has been started before or been given to
|
||||
* another command group
|
||||
* @throws IllegalArgumentException if command is null
|
||||
* another command group
|
||||
* @throws IllegalArgumentException if command is null
|
||||
*/
|
||||
public final synchronized void addParallel(Command command, double timeout) {
|
||||
requireNonNull(command, "Provided command was null");
|
||||
@@ -309,8 +302,8 @@ public class CommandGroup extends Command {
|
||||
* Returns true if all the {@link Command Commands} in this group have been started and have
|
||||
* finished.
|
||||
*
|
||||
* <p> Teams may override this method, although they should probably reference super.isFinished()
|
||||
* if they do. </p>
|
||||
* <p>Teams may override this method, although they should probably reference super.isFinished()
|
||||
* if they do.
|
||||
*
|
||||
* @return whether this {@link CommandGroup} is finished
|
||||
*/
|
||||
@@ -321,23 +314,19 @@ public class CommandGroup extends Command {
|
||||
|
||||
// Can be overwritten by teams
|
||||
@Override
|
||||
protected void initialize() {
|
||||
}
|
||||
protected void initialize() {}
|
||||
|
||||
// Can be overwritten by teams
|
||||
@Override
|
||||
protected void execute() {
|
||||
}
|
||||
protected void execute() {}
|
||||
|
||||
// Can be overwritten by teams
|
||||
@Override
|
||||
protected void end() {
|
||||
}
|
||||
protected void end() {}
|
||||
|
||||
// Can be overwritten by teams
|
||||
@Override
|
||||
protected void interrupted() {
|
||||
}
|
||||
protected void interrupted() {}
|
||||
|
||||
/**
|
||||
* Returns whether or not this group is interruptible. A command group will be uninterruptible if
|
||||
|
||||
@@ -9,44 +9,30 @@ import java.util.Enumeration;
|
||||
/**
|
||||
* A {@link ConditionalCommand} is a {@link Command} that starts one of two commands.
|
||||
*
|
||||
* <p>
|
||||
* A {@link ConditionalCommand} uses m_condition to determine whether it should run m_onTrue or
|
||||
* <p>A {@link ConditionalCommand} uses m_condition to determine whether it should run m_onTrue or
|
||||
* m_onFalse.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* A {@link ConditionalCommand} adds the proper {@link Command} to the {@link Scheduler} during
|
||||
* <p>A {@link ConditionalCommand} adds the proper {@link Command} to the {@link Scheduler} during
|
||||
* {@link ConditionalCommand#initialize()} and then {@link ConditionalCommand#isFinished()} will
|
||||
* return true once that {@link Command} has finished executing.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* If no {@link Command} is specified for m_onFalse, the occurrence of that condition will be a
|
||||
* <p>If no {@link Command} is specified for m_onFalse, the occurrence of that condition will be a
|
||||
* no-op.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* A ConditionalCommand will require the superset of subsystems of the onTrue
|
||||
* and onFalse commands.
|
||||
* </p>
|
||||
* <p>A ConditionalCommand will require the superset of subsystems of the onTrue and onFalse
|
||||
* commands.
|
||||
*
|
||||
* @see Command
|
||||
* @see Scheduler
|
||||
*/
|
||||
public abstract class ConditionalCommand extends Command {
|
||||
/**
|
||||
* The Command to execute if {@link ConditionalCommand#condition()} returns true.
|
||||
*/
|
||||
/** The Command to execute if {@link ConditionalCommand#condition()} returns true. */
|
||||
private Command m_onTrue;
|
||||
|
||||
/**
|
||||
* The Command to execute if {@link ConditionalCommand#condition()} returns false.
|
||||
*/
|
||||
/** The Command to execute if {@link ConditionalCommand#condition()} returns false. */
|
||||
private Command m_onFalse;
|
||||
|
||||
/**
|
||||
* Stores command chosen by condition.
|
||||
*/
|
||||
/** Stores command chosen by condition. */
|
||||
private Command m_chosenCommand;
|
||||
|
||||
private void requireAll() {
|
||||
@@ -125,9 +111,7 @@ public abstract class ConditionalCommand extends Command {
|
||||
*/
|
||||
protected abstract boolean condition();
|
||||
|
||||
/**
|
||||
* Calls {@link ConditionalCommand#condition()} and runs the proper command.
|
||||
*/
|
||||
/** Calls {@link ConditionalCommand#condition()} and runs the proper command. */
|
||||
@Override
|
||||
protected void _initialize() {
|
||||
if (condition()) {
|
||||
|
||||
@@ -8,20 +8,16 @@ package edu.wpi.first.wpilibj.command;
|
||||
* This exception will be thrown if a command is used illegally. There are several ways for this to
|
||||
* happen.
|
||||
*
|
||||
* <p> Basically, a command becomes "locked" after it is first started or added to a command group.
|
||||
* </p>
|
||||
* <p>Basically, a command becomes "locked" after it is first started or added to a command group.
|
||||
*
|
||||
* <p> This exception should be thrown if (after a command has been locked) its requirements change,
|
||||
* <p>This exception should be thrown if (after a command has been locked) its requirements change,
|
||||
* it is put into multiple command groups, it is started from outside its command group, or it adds
|
||||
* a new child. </p>
|
||||
* a new child.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class IllegalUseOfCommandException extends RuntimeException {
|
||||
/**
|
||||
* Instantiates an {@link IllegalUseOfCommandException}.
|
||||
*/
|
||||
public IllegalUseOfCommandException() {
|
||||
}
|
||||
/** Instantiates an {@link IllegalUseOfCommandException}. */
|
||||
public IllegalUseOfCommandException() {}
|
||||
|
||||
/**
|
||||
* Instantiates an {@link IllegalUseOfCommandException} with the given message.
|
||||
|
||||
@@ -7,14 +7,13 @@ package edu.wpi.first.wpilibj.command;
|
||||
/**
|
||||
* This command will execute once, then finish immediately afterward.
|
||||
*
|
||||
* <p>Subclassing {@link InstantCommand} is shorthand for returning true from
|
||||
* {@link Command isFinished}.
|
||||
* <p>Subclassing {@link InstantCommand} is shorthand for returning true from {@link Command
|
||||
* isFinished}.
|
||||
*/
|
||||
public class InstantCommand extends Command {
|
||||
private Runnable m_func;
|
||||
|
||||
public InstantCommand() {
|
||||
}
|
||||
public InstantCommand() {}
|
||||
|
||||
/**
|
||||
* Creates a new {@link InstantCommand InstantCommand} with the given name.
|
||||
@@ -37,7 +36,7 @@ public class InstantCommand extends Command {
|
||||
/**
|
||||
* Creates a new {@link InstantCommand InstantCommand} with the given name and requirement.
|
||||
*
|
||||
* @param name the name for this command
|
||||
* @param name the name for this command
|
||||
* @param subsystem the subsystem this command requires
|
||||
*/
|
||||
public InstantCommand(String name, Subsystem subsystem) {
|
||||
@@ -68,7 +67,7 @@ public class InstantCommand extends Command {
|
||||
* Creates a new {@link InstantCommand InstantCommand}.
|
||||
*
|
||||
* @param requirement the subsystem this command requires
|
||||
* @param func the function to run when {@link Command#initialize() initialize()} is run
|
||||
* @param func the function to run when {@link Command#initialize() initialize()} is run
|
||||
*/
|
||||
public InstantCommand(Subsystem requirement, Runnable func) {
|
||||
super(requirement);
|
||||
@@ -78,9 +77,9 @@ public class InstantCommand extends Command {
|
||||
/**
|
||||
* Creates a new {@link InstantCommand InstantCommand}.
|
||||
*
|
||||
* @param name the name for this command
|
||||
* @param name the name for this command
|
||||
* @param requirement the subsystem this command requires
|
||||
* @param func the function to run when {@link Command#initialize() initialize()} is run
|
||||
* @param func the function to run when {@link Command#initialize() initialize()} is run
|
||||
*/
|
||||
public InstantCommand(String name, Subsystem requirement, Runnable func) {
|
||||
super(name, requirement);
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
/**
|
||||
* An element that is in a LinkedList.
|
||||
*/
|
||||
/** An element that is in a LinkedList. */
|
||||
class LinkedListElement {
|
||||
private LinkedListElement m_next;
|
||||
private LinkedListElement m_previous;
|
||||
|
||||
@@ -13,45 +13,39 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
/**
|
||||
* This class defines a {@link Command} which interacts heavily with a PID loop.
|
||||
*
|
||||
* <p> It provides some convenience methods to run an internal {@link PIDController} . It will also
|
||||
* <p>It provides some convenience methods to run an internal {@link PIDController} . It will also
|
||||
* start and stop said {@link PIDController} when the {@link PIDCommand} is first initialized and
|
||||
* ended/interrupted. </p>
|
||||
* ended/interrupted.
|
||||
*/
|
||||
public abstract class PIDCommand extends Command {
|
||||
/**
|
||||
* The internal {@link PIDController}.
|
||||
*/
|
||||
/** The internal {@link PIDController}. */
|
||||
private final PIDController m_controller;
|
||||
/**
|
||||
* An output which calls {@link PIDCommand#usePIDOutput(double)}.
|
||||
*/
|
||||
/** An output which calls {@link PIDCommand#usePIDOutput(double)}. */
|
||||
private final PIDOutput m_output = this::usePIDOutput;
|
||||
/**
|
||||
* A source which calls {@link PIDCommand#returnPIDInput()}.
|
||||
*/
|
||||
private final PIDSource m_source = new PIDSource() {
|
||||
@Override
|
||||
public void setPIDSourceType(PIDSourceType pidSource) {
|
||||
}
|
||||
/** A source which calls {@link PIDCommand#returnPIDInput()}. */
|
||||
private final PIDSource m_source =
|
||||
new PIDSource() {
|
||||
@Override
|
||||
public void setPIDSourceType(PIDSourceType pidSource) {}
|
||||
|
||||
@Override
|
||||
public PIDSourceType getPIDSourceType() {
|
||||
return PIDSourceType.kDisplacement;
|
||||
}
|
||||
@Override
|
||||
public PIDSourceType getPIDSourceType() {
|
||||
return PIDSourceType.kDisplacement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double pidGet() {
|
||||
return returnPIDInput();
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public double pidGet() {
|
||||
return returnPIDInput();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 p the proportional value
|
||||
* @param i the integral value
|
||||
* @param d the derivative value
|
||||
*/
|
||||
public PIDCommand(String name, double p, double i, double d) {
|
||||
super(name);
|
||||
@@ -62,10 +56,10 @@ 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 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
|
||||
*/
|
||||
public PIDCommand(String name, double p, double i, double d, double period) {
|
||||
@@ -90,9 +84,9 @@ 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 p the proportional value
|
||||
* @param i the integral value
|
||||
* @param d the derivative value
|
||||
* @param period the time (in seconds) between calculations
|
||||
*/
|
||||
public PIDCommand(double p, double i, double d, double period) {
|
||||
@@ -102,10 +96,10 @@ 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 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
|
||||
*/
|
||||
public PIDCommand(String name, double p, double i, double d, Subsystem subsystem) {
|
||||
@@ -117,15 +111,14 @@ 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 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
|
||||
*/
|
||||
public PIDCommand(String name, double p, double i, double d, double period,
|
||||
Subsystem subsystem) {
|
||||
public PIDCommand(String name, double p, double i, double d, double period, Subsystem subsystem) {
|
||||
super(name, subsystem);
|
||||
m_controller = new PIDController(p, i, d, m_source, m_output, period);
|
||||
}
|
||||
@@ -134,9 +127,9 @@ 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 p the proportional value
|
||||
* @param i the integral value
|
||||
* @param d the derivative value
|
||||
* @param subsystem the subsystem that this command requires
|
||||
*/
|
||||
public PIDCommand(double p, double i, double d, Subsystem subsystem) {
|
||||
@@ -149,10 +142,10 @@ 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 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
|
||||
*/
|
||||
public PIDCommand(double p, double i, double d, double period, Subsystem subsystem) {
|
||||
@@ -253,8 +246,8 @@ public abstract class PIDCommand extends Command {
|
||||
|
||||
/**
|
||||
* Uses the value that the pid loop calculated. The calculated value is the "output" parameter.
|
||||
* This method is a good time to set motor values, maybe something along the lines of
|
||||
* <code>driveline.tankDrive(output, -output)</code>
|
||||
* This method is a good time to set motor values, maybe something along the lines of <code>
|
||||
* driveline.tankDrive(output, -output)</code>
|
||||
*
|
||||
* <p>All subclasses of {@link PIDCommand} must override this method.
|
||||
*
|
||||
|
||||
@@ -14,46 +14,39 @@ import edu.wpi.first.wpilibj.PIDSourceType;
|
||||
* {@link PIDController} almost constantly (for instance, an elevator which attempts to stay at a
|
||||
* constant height).
|
||||
*
|
||||
* <p>It provides some convenience methods to run an internal {@link PIDController} . It also
|
||||
* allows access to the internal {@link PIDController} in order to give total control to the
|
||||
* programmer.
|
||||
* <p>It provides some convenience methods to run an internal {@link PIDController} . It also allows
|
||||
* access to the internal {@link PIDController} in order to give total control to the programmer.
|
||||
*/
|
||||
public abstract class PIDSubsystem extends Subsystem {
|
||||
/**
|
||||
* The internal {@link PIDController}.
|
||||
*/
|
||||
/** The internal {@link PIDController}. */
|
||||
private final PIDController m_controller;
|
||||
/**
|
||||
* An output which calls {@link PIDCommand#usePIDOutput(double)}.
|
||||
*/
|
||||
/** An output which calls {@link PIDCommand#usePIDOutput(double)}. */
|
||||
private final PIDOutput m_output = this::usePIDOutput;
|
||||
|
||||
/**
|
||||
* A source which calls {@link PIDCommand#returnPIDInput()}.
|
||||
*/
|
||||
private final PIDSource m_source = new PIDSource() {
|
||||
@Override
|
||||
public void setPIDSourceType(PIDSourceType pidSource) {
|
||||
}
|
||||
/** A source which calls {@link PIDCommand#returnPIDInput()}. */
|
||||
private final PIDSource m_source =
|
||||
new PIDSource() {
|
||||
@Override
|
||||
public void setPIDSourceType(PIDSourceType pidSource) {}
|
||||
|
||||
@Override
|
||||
public PIDSourceType getPIDSourceType() {
|
||||
return PIDSourceType.kDisplacement;
|
||||
}
|
||||
@Override
|
||||
public PIDSourceType getPIDSourceType() {
|
||||
return PIDSourceType.kDisplacement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double pidGet() {
|
||||
return returnPIDInput();
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public double pidGet() {
|
||||
return returnPIDInput();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Instantiates a {@link PIDSubsystem} that will use the given p, i and d values.
|
||||
*
|
||||
* @param name the name
|
||||
* @param p the proportional value
|
||||
* @param i the integral value
|
||||
* @param d the derivative value
|
||||
* @param p the proportional value
|
||||
* @param i the integral value
|
||||
* @param d the derivative value
|
||||
*/
|
||||
public PIDSubsystem(String name, double p, double i, double d) {
|
||||
super(name);
|
||||
@@ -65,10 +58,10 @@ public abstract class PIDSubsystem extends Subsystem {
|
||||
* Instantiates a {@link PIDSubsystem} that will use the given p, i, d, and f values.
|
||||
*
|
||||
* @param name the name
|
||||
* @param p the proportional value
|
||||
* @param i the integral value
|
||||
* @param d the derivative value
|
||||
* @param f the feed forward value
|
||||
* @param p the proportional value
|
||||
* @param i the integral value
|
||||
* @param d the derivative value
|
||||
* @param f the feed forward value
|
||||
*/
|
||||
public PIDSubsystem(String name, double p, double i, double d, double f) {
|
||||
super(name);
|
||||
@@ -80,11 +73,11 @@ public abstract class PIDSubsystem extends Subsystem {
|
||||
* Instantiates a {@link PIDSubsystem} that will use the given p, i, d, and f 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 f the feed forward value
|
||||
* @param name the name
|
||||
* @param p the proportional value
|
||||
* @param i the integral value
|
||||
* @param d the derivative value
|
||||
* @param f the feed forward value
|
||||
* @param period the time (in seconds) between calculations
|
||||
*/
|
||||
public PIDSubsystem(String name, double p, double i, double d, double f, double period) {
|
||||
@@ -111,10 +104,10 @@ public abstract class PIDSubsystem extends Subsystem {
|
||||
* 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 f the feed forward coefficient
|
||||
* @param p the proportional value
|
||||
* @param i the integral value
|
||||
* @param d the derivative value
|
||||
* @param f the feed forward coefficient
|
||||
* @param period the time (in seconds) between calculations
|
||||
*/
|
||||
public PIDSubsystem(double p, double i, double d, double f, double period) {
|
||||
@@ -127,9 +120,9 @@ public abstract class PIDSubsystem extends Subsystem {
|
||||
* 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 p the proportional value
|
||||
* @param i the integral value
|
||||
* @param d the derivative value
|
||||
* @param period the time (in seconds) between calculations
|
||||
*/
|
||||
public PIDSubsystem(double p, double i, double d, double period) {
|
||||
@@ -147,7 +140,6 @@ public abstract class PIDSubsystem extends Subsystem {
|
||||
return m_controller;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the given value to the setpoint. If {@link PIDSubsystem#setInputRange(double, double)
|
||||
* setInputRange(...)} was used, then the bounds will still be honored by this method.
|
||||
@@ -240,8 +232,8 @@ public abstract class PIDSubsystem extends Subsystem {
|
||||
/**
|
||||
* Returns the input for the pid loop.
|
||||
*
|
||||
* <p>It returns the input for the pid loop, so if this Subsystem was based off of a gyro, then
|
||||
* it should return the angle of the gyro.
|
||||
* <p>It returns the input for the pid loop, so if this Subsystem was based off of a gyro, then it
|
||||
* should return the angle of the gyro.
|
||||
*
|
||||
* <p>All subclasses of {@link PIDSubsystem} must override this method.
|
||||
*
|
||||
@@ -251,8 +243,8 @@ public abstract class PIDSubsystem extends Subsystem {
|
||||
|
||||
/**
|
||||
* Uses the value that the pid loop calculated. The calculated value is the "output" parameter.
|
||||
* This method is a good time to set motor values, maybe something along the lines of
|
||||
* <code>driveline.tankDrive(output, -output)</code>.
|
||||
* This method is a good time to set motor values, maybe something along the lines of <code>
|
||||
* driveline.tankDrive(output, -output)</code>.
|
||||
*
|
||||
* <p>All subclasses of {@link PIDSubsystem} must override this method.
|
||||
*
|
||||
@@ -260,16 +252,12 @@ public abstract class PIDSubsystem extends Subsystem {
|
||||
*/
|
||||
protected abstract void usePIDOutput(double output);
|
||||
|
||||
/**
|
||||
* Enables the internal {@link PIDController}.
|
||||
*/
|
||||
/** Enables the internal {@link PIDController}. */
|
||||
public void enable() {
|
||||
m_controller.enable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the internal {@link PIDController}.
|
||||
*/
|
||||
/** Disables the internal {@link PIDController}. */
|
||||
public void disable() {
|
||||
m_controller.disable();
|
||||
}
|
||||
|
||||
@@ -10,9 +10,7 @@ package edu.wpi.first.wpilibj.command;
|
||||
* it reaches a certain point.
|
||||
*/
|
||||
public class PrintCommand extends InstantCommand {
|
||||
/**
|
||||
* The message to print out.
|
||||
*/
|
||||
/** The message to print out. */
|
||||
private final String m_message;
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,10 +4,6 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
|
||||
import edu.wpi.first.hal.FRCNetComm.tInstances;
|
||||
import edu.wpi.first.hal.FRCNetComm.tResourceType;
|
||||
import edu.wpi.first.hal.HAL;
|
||||
@@ -17,23 +13,24 @@ import edu.wpi.first.wpilibj.buttons.Trigger.ButtonScheduler;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* The {@link Scheduler} is a singleton which holds the top-level running commands. It is in charge
|
||||
* of both calling the command's {@link Command#run() run()} method and to make sure that there are
|
||||
* no two commands with conflicting requirements running.
|
||||
*
|
||||
* <p> It is fine if teams wish to take control of the {@link Scheduler} themselves, all that needs
|
||||
* <p>It is fine if teams wish to take control of the {@link Scheduler} themselves, all that needs
|
||||
* to be done is to call {@link Scheduler#getInstance() Scheduler.getInstance()}.{@link
|
||||
* Scheduler#run() run()} often to have {@link Command Commands} function correctly. However, this
|
||||
* is already done for you if you use the CommandBased Robot template. </p>
|
||||
* is already done for you if you use the CommandBased Robot template.
|
||||
*
|
||||
* @see Command
|
||||
*/
|
||||
public final class Scheduler implements Sendable, AutoCloseable {
|
||||
/**
|
||||
* The Singleton Instance.
|
||||
*/
|
||||
/** The Singleton Instance. */
|
||||
private static Scheduler instance;
|
||||
|
||||
/**
|
||||
@@ -48,34 +45,20 @@ public final class Scheduler implements Sendable, AutoCloseable {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* A hashtable of active {@link Command Commands} to their {@link LinkedListElement}.
|
||||
*/
|
||||
/** A hashtable of active {@link Command Commands} to their {@link LinkedListElement}. */
|
||||
@SuppressWarnings("PMD.LooseCoupling")
|
||||
private final Hashtable<Command, LinkedListElement> m_commandTable = new Hashtable<>();
|
||||
/**
|
||||
* The {@link Set} of all {@link Subsystem Subsystems}.
|
||||
*/
|
||||
/** The {@link Set} of all {@link Subsystem Subsystems}. */
|
||||
private final Set m_subsystems = new Set();
|
||||
/**
|
||||
* The first {@link Command} in the list.
|
||||
*/
|
||||
/** The first {@link Command} in the list. */
|
||||
private LinkedListElement m_firstCommand;
|
||||
/**
|
||||
* The last {@link Command} in the list.
|
||||
*/
|
||||
/** The last {@link Command} in the list. */
|
||||
private LinkedListElement m_lastCommand;
|
||||
/**
|
||||
* Whether or not we are currently adding a command.
|
||||
*/
|
||||
/** Whether or not we are currently adding a command. */
|
||||
private boolean m_adding;
|
||||
/**
|
||||
* Whether or not we are currently disabled.
|
||||
*/
|
||||
/** Whether or not we are currently disabled. */
|
||||
private boolean m_disabled;
|
||||
/**
|
||||
* A list of all {@link Command Commands} which need to be added.
|
||||
*/
|
||||
/** A list of all {@link Command Commands} which need to be added. */
|
||||
@SuppressWarnings({"PMD.LooseCoupling", "PMD.UseArrayListInsteadOfVector"})
|
||||
private final Vector<Command> m_additions = new Vector<>();
|
||||
/**
|
||||
@@ -84,21 +67,22 @@ public final class Scheduler implements Sendable, AutoCloseable {
|
||||
*/
|
||||
@SuppressWarnings("PMD.LooseCoupling")
|
||||
private Vector<ButtonScheduler> m_buttons;
|
||||
|
||||
private boolean m_runningCommandsChanged;
|
||||
|
||||
/**
|
||||
* Instantiates a {@link Scheduler}.
|
||||
*/
|
||||
/** Instantiates a {@link Scheduler}. */
|
||||
private Scheduler() {
|
||||
HAL.report(tResourceType.kResourceType_Command, tInstances.kCommand_Scheduler);
|
||||
SendableRegistry.addLW(this, "Scheduler");
|
||||
LiveWindow.setEnabledListener(() -> {
|
||||
disable();
|
||||
removeAll();
|
||||
});
|
||||
LiveWindow.setDisabledListener(() -> {
|
||||
enable();
|
||||
});
|
||||
LiveWindow.setEnabledListener(
|
||||
() -> {
|
||||
disable();
|
||||
removeAll();
|
||||
});
|
||||
LiveWindow.setDisabledListener(
|
||||
() -> {
|
||||
enable();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,8 +97,8 @@ public final class Scheduler implements Sendable, AutoCloseable {
|
||||
* but will instead wait for the proper time in the {@link Scheduler#run()} loop before doing so.
|
||||
* The command returns immediately and does nothing if given null.
|
||||
*
|
||||
* <p> Adding a {@link Command} to the {@link Scheduler} involves the {@link Scheduler} removing
|
||||
* any {@link Command} which has shared requirements. </p>
|
||||
* <p>Adding a {@link Command} to the {@link Scheduler} involves the {@link Scheduler} removing
|
||||
* any {@link Command} which has shared requirements.
|
||||
*
|
||||
* @param command the command to add
|
||||
*/
|
||||
@@ -202,8 +186,13 @@ public final class Scheduler implements Sendable, AutoCloseable {
|
||||
* Runs a single iteration of the loop. This method should be called often in order to have a
|
||||
* functioning {@link Command} system. The loop has five stages:
|
||||
*
|
||||
* <ol> <li>Poll the Buttons</li> <li>Execute/Remove the Commands</li> <li>Send values to
|
||||
* SmartDashboard</li> <li>Add Commands</li> <li>Add Defaults</li> </ol>
|
||||
* <ol>
|
||||
* <li>Poll the Buttons
|
||||
* <li>Execute/Remove the Commands
|
||||
* <li>Send values to SmartDashboard
|
||||
* <li>Add Commands
|
||||
* <li>Add Defaults
|
||||
* </ol>
|
||||
*/
|
||||
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
|
||||
public void run() {
|
||||
@@ -295,9 +284,7 @@ public final class Scheduler implements Sendable, AutoCloseable {
|
||||
command.removed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all commands.
|
||||
*/
|
||||
/** Removes all commands. */
|
||||
public void removeAll() {
|
||||
// TODO: Confirm that this works with "uninteruptible" commands
|
||||
while (m_firstCommand != null) {
|
||||
@@ -305,16 +292,12 @@ public final class Scheduler implements Sendable, AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the command scheduler.
|
||||
*/
|
||||
/** Disable the command scheduler. */
|
||||
public void disable() {
|
||||
m_disabled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the command scheduler.
|
||||
*/
|
||||
/** Enable the command scheduler. */
|
||||
public void enable() {
|
||||
m_disabled = false;
|
||||
}
|
||||
@@ -325,39 +308,40 @@ public final class Scheduler implements Sendable, AutoCloseable {
|
||||
final NetworkTableEntry namesEntry = builder.getEntry("Names");
|
||||
final NetworkTableEntry idsEntry = builder.getEntry("Ids");
|
||||
final NetworkTableEntry cancelEntry = builder.getEntry("Cancel");
|
||||
builder.setUpdateTable(() -> {
|
||||
if (namesEntry != null && idsEntry != null && cancelEntry != null) {
|
||||
// Get the commands to cancel
|
||||
double[] toCancel = cancelEntry.getDoubleArray(new double[0]);
|
||||
if (toCancel.length > 0) {
|
||||
for (LinkedListElement e = m_firstCommand; e != null; e = e.getNext()) {
|
||||
for (double d : toCancel) {
|
||||
if (e.getData().hashCode() == d) {
|
||||
e.getData().cancel();
|
||||
builder.setUpdateTable(
|
||||
() -> {
|
||||
if (namesEntry != null && idsEntry != null && cancelEntry != null) {
|
||||
// Get the commands to cancel
|
||||
double[] toCancel = cancelEntry.getDoubleArray(new double[0]);
|
||||
if (toCancel.length > 0) {
|
||||
for (LinkedListElement e = m_firstCommand; e != null; e = e.getNext()) {
|
||||
for (double d : toCancel) {
|
||||
if (e.getData().hashCode() == d) {
|
||||
e.getData().cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
cancelEntry.setDoubleArray(new double[0]);
|
||||
}
|
||||
|
||||
if (m_runningCommandsChanged) {
|
||||
// Set the the running commands
|
||||
int number = 0;
|
||||
for (LinkedListElement e = m_firstCommand; e != null; e = e.getNext()) {
|
||||
number++;
|
||||
}
|
||||
String[] commands = new String[number];
|
||||
double[] ids = new double[number];
|
||||
number = 0;
|
||||
for (LinkedListElement e = m_firstCommand; e != null; e = e.getNext()) {
|
||||
commands[number] = e.getData().getName();
|
||||
ids[number] = e.getData().hashCode();
|
||||
number++;
|
||||
}
|
||||
namesEntry.setStringArray(commands);
|
||||
idsEntry.setDoubleArray(ids);
|
||||
}
|
||||
}
|
||||
cancelEntry.setDoubleArray(new double[0]);
|
||||
}
|
||||
|
||||
if (m_runningCommandsChanged) {
|
||||
// Set the the running commands
|
||||
int number = 0;
|
||||
for (LinkedListElement e = m_firstCommand; e != null; e = e.getNext()) {
|
||||
number++;
|
||||
}
|
||||
String[] commands = new String[number];
|
||||
double[] ids = new double[number];
|
||||
number = 0;
|
||||
for (LinkedListElement e = m_firstCommand; e != null; e = e.getNext()) {
|
||||
commands[number] = e.getData().getName();
|
||||
ids[number] = e.getData().hashCode();
|
||||
number++;
|
||||
}
|
||||
namesEntry.setStringArray(commands);
|
||||
idsEntry.setDoubleArray(ids);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,11 @@ import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
/**
|
||||
* A set.
|
||||
*/
|
||||
/** A set. */
|
||||
class Set {
|
||||
private Vector m_set = new Vector();
|
||||
|
||||
public Set() {
|
||||
}
|
||||
public Set() {}
|
||||
|
||||
public void add(Object o) {
|
||||
if (m_set.contains(o)) {
|
||||
@@ -32,7 +29,7 @@ class Set {
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
m_set.clear();
|
||||
m_set.clear();
|
||||
}
|
||||
|
||||
public boolean contains(Object o) {
|
||||
|
||||
@@ -9,9 +9,7 @@ package edu.wpi.first.wpilibj.command;
|
||||
* when it is initialized and will finish immediately.
|
||||
*/
|
||||
public class StartCommand extends InstantCommand {
|
||||
/**
|
||||
* The command to fork.
|
||||
*/
|
||||
/** The command to fork. */
|
||||
private final Command m_commandToFork;
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,40 +4,34 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import edu.wpi.first.wpilibj.Sendable;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* This class defines a major component of the robot.
|
||||
*
|
||||
* <p> A good example of a subsystem is the driveline, or a claw if the robot has one. </p>
|
||||
* <p>A good example of a subsystem is the driveline, or a claw if the robot has one.
|
||||
*
|
||||
* <p> All motors should be a part of a subsystem. For instance, all the wheel motors should be a
|
||||
* part of some kind of "Driveline" subsystem. </p>
|
||||
* <p>All motors should be a part of a subsystem. For instance, all the wheel motors should be a
|
||||
* part of some kind of "Driveline" subsystem.
|
||||
*
|
||||
* <p> Subsystems are used within the command system as requirements for {@link Command}. Only one
|
||||
* <p>Subsystems are used within the command system as requirements for {@link Command}. Only one
|
||||
* command which requires a subsystem can run at a time. Also, subsystems can have default commands
|
||||
* which are started if there is no command running which requires this subsystem. </p>
|
||||
* which are started if there is no command running which requires this subsystem.
|
||||
*
|
||||
* @see Command
|
||||
*/
|
||||
public abstract class Subsystem implements Sendable, AutoCloseable {
|
||||
/**
|
||||
* Whether or not getDefaultCommand() was called.
|
||||
*/
|
||||
/** Whether or not getDefaultCommand() was called. */
|
||||
private boolean m_initializedDefaultCommand;
|
||||
/**
|
||||
* The current command.
|
||||
*/
|
||||
/** The current command. */
|
||||
private Command m_currentCommand;
|
||||
|
||||
private boolean m_currentCommandChanged;
|
||||
|
||||
/**
|
||||
* The default command.
|
||||
*/
|
||||
/** The default command. */
|
||||
private Command m_defaultCommand;
|
||||
|
||||
/**
|
||||
@@ -50,9 +44,7 @@ public abstract class Subsystem implements Sendable, AutoCloseable {
|
||||
Scheduler.getInstance().registerSubsystem(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a subsystem. This will set the name to the name of the class.
|
||||
*/
|
||||
/** Creates a subsystem. This will set the name to the name of the class. */
|
||||
public Subsystem() {
|
||||
String name = getClass().getName();
|
||||
name = name.substring(name.lastIndexOf('.') + 1);
|
||||
@@ -73,9 +65,7 @@ public abstract class Subsystem implements Sendable, AutoCloseable {
|
||||
*/
|
||||
protected abstract void initDefaultCommand();
|
||||
|
||||
/**
|
||||
* When the run method of the scheduler is called this method will be called.
|
||||
*/
|
||||
/** When the run method of the scheduler is called this method will be called. */
|
||||
public void periodic() {
|
||||
// Override me!
|
||||
}
|
||||
@@ -84,8 +74,8 @@ public abstract class Subsystem implements Sendable, AutoCloseable {
|
||||
* Sets the default command. If this is not called or is called with null, then there will be no
|
||||
* default command for the subsystem.
|
||||
*
|
||||
* <p> <b>WARNING:</b> This should <b>NOT</b> be called in a constructor if the subsystem is a
|
||||
* singleton. </p>
|
||||
* <p><b>WARNING:</b> This should <b>NOT</b> be called in a constructor if the subsystem is a
|
||||
* singleton.
|
||||
*
|
||||
* @param command the default command (or null if there should be none)
|
||||
* @throws IllegalUseOfCommandException if the command does not require the subsystem
|
||||
@@ -173,8 +163,7 @@ public abstract class Subsystem implements Sendable, AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Associate a {@link Sendable} with this Subsystem.
|
||||
* Also update the child's name.
|
||||
* Associate a {@link Sendable} with this Subsystem. Also update the child's name.
|
||||
*
|
||||
* @param name name to give child
|
||||
* @param child sendable
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
/**
|
||||
* A {@link TimedCommand} will wait for a timeout before finishing.
|
||||
* {@link TimedCommand} is used to execute a command for a given amount of time.
|
||||
* A {@link TimedCommand} will wait for a timeout before finishing. {@link TimedCommand} is used to
|
||||
* execute a command for a given amount of time.
|
||||
*/
|
||||
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,8 +31,8 @@ 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 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 subsystem) {
|
||||
@@ -42,16 +42,14 @@ public class TimedCommand extends Command {
|
||||
/**
|
||||
* Instantiates a TimedCommand with the given timeout.
|
||||
*
|
||||
* @param timeout the time the command takes to run (seconds)
|
||||
* @param timeout the time the command takes to run (seconds)
|
||||
* @param subsystem the subsystem that this command requires
|
||||
*/
|
||||
public TimedCommand(double timeout, Subsystem subsystem) {
|
||||
super(timeout, subsystem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends command when timed out.
|
||||
*/
|
||||
/** Ends command when timed out. */
|
||||
@Override
|
||||
protected boolean isFinished() {
|
||||
return isTimedOut();
|
||||
|
||||
@@ -23,7 +23,7 @@ public class WaitCommand extends TimedCommand {
|
||||
/**
|
||||
* Instantiates a {@link WaitCommand} with the given 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 WaitCommand(String name, double timeout) {
|
||||
|
||||
@@ -9,8 +9,8 @@ package edu.wpi.first.wpilibj.command;
|
||||
* If it is not a part of a {@link CommandGroup}, then it will finish immediately. If it is itself
|
||||
* an active child, then the {@link CommandGroup} will never end.
|
||||
*
|
||||
* <p>This class is useful for the situation where you want to allow anything running in parallel
|
||||
* to finish, before continuing in the main {@link CommandGroup} sequence.
|
||||
* <p>This class is useful for the situation where you want to allow anything running in parallel to
|
||||
* finish, before continuing in the main {@link CommandGroup} sequence.
|
||||
*/
|
||||
public class WaitForChildren extends Command {
|
||||
@Override
|
||||
|
||||
@@ -18,9 +18,7 @@ public class WaitUntilCommand extends Command {
|
||||
m_time = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we've reached the actual finish time.
|
||||
*/
|
||||
/** Check if we've reached the actual finish time. */
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return Timer.getMatchTime() >= m_time;
|
||||
|
||||
@@ -4,13 +4,12 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.hal.HAL;
|
||||
import edu.wpi.first.wpilibj.simulation.DriverStationSim;
|
||||
import org.junit.jupiter.api.extension.BeforeAllCallback;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
|
||||
|
||||
import edu.wpi.first.hal.HAL;
|
||||
import edu.wpi.first.wpilibj.simulation.DriverStationSim;
|
||||
|
||||
public final class MockHardwareExtension implements BeforeAllCallback {
|
||||
private static ExtensionContext getRoot(ExtensionContext context) {
|
||||
return context.getParent().map(MockHardwareExtension::getRoot).orElse(context);
|
||||
@@ -18,10 +17,15 @@ public final class MockHardwareExtension implements BeforeAllCallback {
|
||||
|
||||
@Override
|
||||
public void beforeAll(ExtensionContext context) {
|
||||
getRoot(context).getStore(Namespace.GLOBAL).getOrComputeIfAbsent("HAL Initialized", key -> {
|
||||
initializeHardware();
|
||||
return true;
|
||||
}, Boolean.class);
|
||||
getRoot(context)
|
||||
.getStore(Namespace.GLOBAL)
|
||||
.getOrComputeIfAbsent(
|
||||
"HAL Initialized",
|
||||
key -> {
|
||||
initializeHardware();
|
||||
return true;
|
||||
},
|
||||
Boolean.class);
|
||||
}
|
||||
|
||||
private void initializeHardware() {
|
||||
@@ -31,7 +35,5 @@ public final class MockHardwareExtension implements BeforeAllCallback {
|
||||
dsSim.setAutonomous(false);
|
||||
dsSim.setEnabled(true);
|
||||
dsSim.setTest(true);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,13 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* The basic test for all {@link Command} tests.
|
||||
*/
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
/** The basic test for all {@link Command} tests. */
|
||||
public abstract class AbstractCommandTest {
|
||||
@BeforeEach
|
||||
void commandSetup() {
|
||||
@@ -35,16 +33,14 @@ public abstract class AbstractCommandTest {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void assertCommandState(MockCommand command, int initialize, int execute,
|
||||
int isFinished, int end, int interrupted) {
|
||||
protected void assertCommandState(
|
||||
MockCommand command, int initialize, int execute, int isFinished, int end, int interrupted) {
|
||||
assertAll(
|
||||
() -> assertEquals(initialize, command.getInitializeCount()),
|
||||
() -> assertEquals(execute, command.getExecuteCount()),
|
||||
() -> assertEquals(isFinished, command.getIsFinishedCount()),
|
||||
() -> assertEquals(end, command.getEndCount()),
|
||||
() -> assertEquals(interrupted, command.getInterruptedCount())
|
||||
);
|
||||
() -> assertEquals(interrupted, command.getInterruptedCount()));
|
||||
}
|
||||
|
||||
protected void sleep(int time) {
|
||||
|
||||
@@ -4,12 +4,10 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import edu.wpi.first.wpilibj.buttons.InternalButton;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import edu.wpi.first.wpilibj.buttons.InternalButton;
|
||||
|
||||
|
||||
/**
|
||||
* Test that covers the {@link edu.wpi.first.wpilibj.buttons.Button} with the {@link Command}
|
||||
* library.
|
||||
@@ -24,9 +22,7 @@ class ButtonTest extends AbstractCommandTest {
|
||||
m_button2 = new InternalButton();
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple Button Test.
|
||||
*/
|
||||
/** Simple Button Test. */
|
||||
@Test
|
||||
void buttonTest() {
|
||||
final MockCommand command1 = new MockCommand();
|
||||
@@ -109,5 +105,4 @@ class ButtonTest extends AbstractCommandTest {
|
||||
assertCommandState(command3, 1, 4, 4, 0, 1);
|
||||
assertCommandState(command4, 1, 3, 3, 0, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,13 +6,9 @@ package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Ported from the old CrioTest Classes.
|
||||
*/
|
||||
/** Ported from the old CrioTest Classes. */
|
||||
class CommandParallelGroupTest extends AbstractCommandTest {
|
||||
/**
|
||||
* Simple Parallel Command Group With 2 commands one command terminates first.
|
||||
*/
|
||||
/** Simple Parallel Command Group With 2 commands one command terminates first. */
|
||||
@Test
|
||||
void parallelCommandGroupWithTwoCommandsTest() {
|
||||
final MockCommand command1 = new MockCommand();
|
||||
@@ -49,5 +45,4 @@ class CommandParallelGroupTest extends AbstractCommandTest {
|
||||
assertCommandState(command2, 1, 5, 5, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,9 +6,7 @@ package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Ported from the old CrioTest Classes.
|
||||
*/
|
||||
/** Ported from the old CrioTest Classes. */
|
||||
class CommandScheduleTest extends AbstractCommandTest {
|
||||
/**
|
||||
* Simple scheduling of a command and making sure the command is run and successfully terminates.
|
||||
@@ -32,9 +30,7 @@ class CommandScheduleTest extends AbstractCommandTest {
|
||||
assertCommandState(command, 1, 3, 3, 1, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple scheduling of a command and making sure the command is run and cancels correctly.
|
||||
*/
|
||||
/** Simple scheduling of a command and making sure the command is run and cancels correctly. */
|
||||
@Test
|
||||
void runAndCancelTest() {
|
||||
final MockCommand command = new MockCommand();
|
||||
|
||||
@@ -5,12 +5,9 @@
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Ported from the old CrioTest Classes.
|
||||
*/
|
||||
/** Ported from the old CrioTest Classes. */
|
||||
class CommandSequentialGroupTest extends AbstractCommandTest {
|
||||
private static final Logger logger = Logger.getLogger(CommandSequentialGroupTest.class.getName());
|
||||
|
||||
@@ -36,7 +33,6 @@ class CommandSequentialGroupTest extends AbstractCommandTest {
|
||||
commandGroup.addSequential(command2, 2.0);
|
||||
commandGroup.addSequential(command3);
|
||||
|
||||
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
@@ -87,5 +83,4 @@ class CommandSequentialGroupTest extends AbstractCommandTest {
|
||||
assertCommandState(command3, 1, 3, 3, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,13 +6,9 @@ package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Ported from the old CrioTest Classes.
|
||||
*/
|
||||
/** Ported from the old CrioTest Classes. */
|
||||
class CommandSupersedeTest extends AbstractCommandTest {
|
||||
/**
|
||||
* Testing one command superseding another because of dependencies.
|
||||
*/
|
||||
/** Testing one command superseding another because of dependencies. */
|
||||
@Test
|
||||
void oneCommandSupersedingAnotherBecauseOfDependenciesTest() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
@@ -64,11 +60,12 @@ class CommandSupersedeTest extends AbstractCommandTest {
|
||||
void commandFailingSupersedingBecauseFirstCanNotBeInterruptedTest() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
|
||||
final MockCommand command1 = new MockCommand(subsystem) {
|
||||
{
|
||||
setInterruptible(false);
|
||||
}
|
||||
};
|
||||
final MockCommand command1 =
|
||||
new MockCommand(subsystem) {
|
||||
{
|
||||
setInterruptible(false);
|
||||
}
|
||||
};
|
||||
|
||||
final MockCommand command2 = new MockCommand(subsystem);
|
||||
|
||||
|
||||
@@ -6,24 +6,20 @@ package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test a {@link Command} that times out.
|
||||
*/
|
||||
/** Test a {@link Command} that times out. */
|
||||
class CommandTimeoutTest extends AbstractCommandTest {
|
||||
/**
|
||||
* Command 2 second Timeout Test.
|
||||
*/
|
||||
/** Command 2 second Timeout Test. */
|
||||
@Test
|
||||
void twoSecondTimeoutTest() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
|
||||
|
||||
final MockCommand command = new MockCommand(subsystem, 2) {
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return super.isFinished() || isTimedOut();
|
||||
}
|
||||
};
|
||||
final MockCommand command =
|
||||
new MockCommand(subsystem, 2) {
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return super.isFinished() || isTimedOut();
|
||||
}
|
||||
};
|
||||
|
||||
command.start();
|
||||
assertCommandState(command, 0, 0, 0, 0, 0);
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ConditionalCommandTest extends AbstractCommandTest {
|
||||
MockConditionalCommand m_command;
|
||||
MockConditionalCommand m_commandNull;
|
||||
@@ -28,9 +28,13 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
m_commandNull = new MockConditionalCommand(m_onTrue, null);
|
||||
}
|
||||
|
||||
protected void assertConditionalCommandState(MockConditionalCommand command, int initialize,
|
||||
int execute, int isFinished, int end,
|
||||
int interrupted) {
|
||||
protected void assertConditionalCommandState(
|
||||
MockConditionalCommand command,
|
||||
int initialize,
|
||||
int execute,
|
||||
int isFinished,
|
||||
int end,
|
||||
int interrupted) {
|
||||
assertEquals(initialize, command.getInitializeCount());
|
||||
assertEquals(execute, command.getExecuteCount());
|
||||
assertEquals(isFinished, command.getIsFinishedCount());
|
||||
@@ -46,11 +50,11 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 1, 1, 1, 0, 0);
|
||||
@@ -84,11 +88,11 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init command and select m_onFalse
|
||||
Scheduler.getInstance().run(); // init command and select m_onFalse
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init m_onFalse
|
||||
Scheduler.getInstance().run(); // init m_onFalse
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 1, 1, 1, 0, 0);
|
||||
@@ -122,11 +126,11 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 1, 1, 1, 0, 0);
|
||||
@@ -161,11 +165,11 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 1, 1, 1, 0, 0);
|
||||
@@ -196,11 +200,11 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 1, 1, 1, 0, 0);
|
||||
@@ -231,11 +235,11 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 1, 1, 1, 0, 0);
|
||||
@@ -264,11 +268,11 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 1, 1, 1, 0, 0);
|
||||
@@ -300,11 +304,11 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 1, 1, 1, 0, 0);
|
||||
@@ -329,10 +333,10 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
Scheduler.getInstance().add(m_commandNull);
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_commandNull, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init command and select m_onFalse
|
||||
Scheduler.getInstance().run(); // init command and select m_onFalse
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_commandNull, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init m_onFalse
|
||||
Scheduler.getInstance().run(); // init m_onFalse
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_commandNull, 1, 1, 1, 1, 0);
|
||||
Scheduler.getInstance().run();
|
||||
|
||||
@@ -6,18 +6,13 @@ package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests the {@link Command} library.
|
||||
*/
|
||||
/** Tests the {@link Command} library. */
|
||||
public class DefaultCommandTest extends AbstractCommandTest {
|
||||
/**
|
||||
* Testing of default commands where the interrupting command ends itself.
|
||||
*/
|
||||
/** Testing of default commands where the interrupting command ends itself. */
|
||||
@Test
|
||||
void defaultCommandWhereTheInteruptingCommandEndsItselfTest() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
|
||||
|
||||
final MockCommand defaultCommand = new MockCommand(subsystem);
|
||||
|
||||
final MockCommand anotherCommand = new MockCommand(subsystem);
|
||||
@@ -58,10 +53,7 @@ public class DefaultCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(anotherCommand, 1, 3, 3, 1, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Testing of default commands where the interrupting command is canceled.
|
||||
*/
|
||||
/** Testing of default commands where the interrupting command is canceled. */
|
||||
@Test
|
||||
void defaultCommandsInterruptingCommandCanceledTest() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
@@ -104,5 +96,4 @@ public class DefaultCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(defaultCommand, 2, 5, 5, 0, 1);
|
||||
assertCommandState(anotherCommand, 1, 2, 2, 0, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -56,31 +56,22 @@ public class MockCommand extends Command {
|
||||
++m_interruptedCount;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* How many times the initialize method has been called.
|
||||
*/
|
||||
/** How many times the initialize method has been called. */
|
||||
public int getInitializeCount() {
|
||||
return m_initializeCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the initialize method has been called at least once.
|
||||
*/
|
||||
/** If the initialize method has been called at least once. */
|
||||
public boolean hasInitialized() {
|
||||
return getInitializeCount() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many time the execute method has been called.
|
||||
*/
|
||||
/** How many time the execute method has been called. */
|
||||
public int getExecuteCount() {
|
||||
return m_executeCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many times the isFinished method has been called.
|
||||
*/
|
||||
/** How many times the isFinished method has been called. */
|
||||
public int getIsFinishedCount() {
|
||||
return m_isFinishedCount;
|
||||
}
|
||||
@@ -103,37 +94,27 @@ public class MockCommand extends Command {
|
||||
m_hasFinished = hasFinished;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many times the end method has been called.
|
||||
*/
|
||||
/** How many times the end method has been called. */
|
||||
public int getEndCount() {
|
||||
return m_endCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the end method has been called at least once.
|
||||
*/
|
||||
/** If the end method has been called at least once. */
|
||||
public boolean hasEnd() {
|
||||
return getEndCount() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many times the interrupted method has been called.
|
||||
*/
|
||||
/** How many times the interrupted method has been called. */
|
||||
public int getInterruptedCount() {
|
||||
return m_interruptedCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the interrupted method has been called at least once.
|
||||
*/
|
||||
/** If the interrupted method has been called at least once. */
|
||||
public boolean hasInterrupted() {
|
||||
return getInterruptedCount() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset internal counters.
|
||||
*/
|
||||
/** Reset internal counters. */
|
||||
public void resetCounters() {
|
||||
m_initializeCount = 0;
|
||||
m_executeCount = 0;
|
||||
@@ -142,5 +123,4 @@ public class MockCommand extends Command {
|
||||
m_endCount = 0;
|
||||
m_interruptedCount = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,66 +51,47 @@ public class MockConditionalCommand extends ConditionalCommand {
|
||||
++m_interruptedCount;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* How many times the initialize method has been called.
|
||||
*/
|
||||
/** How many times the initialize method has been called. */
|
||||
public int getInitializeCount() {
|
||||
return m_initializeCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the initialize method has been called at least once.
|
||||
*/
|
||||
/** If the initialize method has been called at least once. */
|
||||
public boolean hasInitialized() {
|
||||
return getInitializeCount() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many time the execute method has been called.
|
||||
*/
|
||||
/** How many time the execute method has been called. */
|
||||
public int getExecuteCount() {
|
||||
return m_executeCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many times the isFinished method has been called.
|
||||
*/
|
||||
/** How many times the isFinished method has been called. */
|
||||
public int getIsFinishedCount() {
|
||||
return m_isFinishedCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many times the end method has been called.
|
||||
*/
|
||||
/** How many times the end method has been called. */
|
||||
public int getEndCount() {
|
||||
return m_endCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the end method has been called at least once.
|
||||
*/
|
||||
/** If the end method has been called at least once. */
|
||||
public boolean hasEnd() {
|
||||
return getEndCount() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many times the interrupted method has been called.
|
||||
*/
|
||||
/** How many times the interrupted method has been called. */
|
||||
public int getInterruptedCount() {
|
||||
return m_interruptedCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the interrupted method has been called at least once.
|
||||
*/
|
||||
/** If the interrupted method has been called at least once. */
|
||||
public boolean hasInterrupted() {
|
||||
return getInterruptedCount() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset internal counters.
|
||||
*/
|
||||
/** Reset internal counters. */
|
||||
public void resetCounters() {
|
||||
m_condition = false;
|
||||
m_initializeCount = 0;
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
/**
|
||||
* A class to simulate a simple subsystem.
|
||||
*/
|
||||
/** A class to simulate a simple subsystem. */
|
||||
public class MockSubsystem extends Subsystem {
|
||||
@Override
|
||||
protected void initDefaultCommand() {}
|
||||
|
||||
@@ -4,24 +4,22 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.shuffleboard;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import edu.wpi.first.networktables.NetworkTableEntry;
|
||||
import edu.wpi.first.networktables.NetworkTableInstance;
|
||||
import edu.wpi.first.wpilibj.Sendable;
|
||||
import edu.wpi.first.wpilibj.command.InstantCommand;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import edu.wpi.first.networktables.NetworkTableEntry;
|
||||
import edu.wpi.first.networktables.NetworkTableInstance;
|
||||
import edu.wpi.first.wpilibj.Sendable;
|
||||
import edu.wpi.first.wpilibj.command.InstantCommand;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ShuffleboardTabTest {
|
||||
private NetworkTableInstance m_ntInstance;
|
||||
private ShuffleboardTab m_tab;
|
||||
@@ -63,7 +61,6 @@ public class ShuffleboardTabTest {
|
||||
() -> assertEquals(1.0, entry.getValue().getDouble()));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testAddBoolean() {
|
||||
NetworkTableEntry entry = m_tab.add("Bool", false).getEntry();
|
||||
@@ -84,47 +81,51 @@ public class ShuffleboardTabTest {
|
||||
void testAddNamedSendableWithProperties() {
|
||||
Sendable sendable = new InstantCommand("Command");
|
||||
String widgetType = "Command Widget";
|
||||
m_tab.add(sendable)
|
||||
.withWidget(widgetType)
|
||||
.withProperties(mapOf("foo", 1234, "bar", "baz"));
|
||||
m_tab.add(sendable).withWidget(widgetType).withProperties(mapOf("foo", 1234, "bar", "baz"));
|
||||
|
||||
m_instance.update();
|
||||
String meta = "/Shuffleboard/.metadata/Tab/Command";
|
||||
|
||||
assertAll(
|
||||
() -> assertEquals(1234,
|
||||
m_ntInstance.getEntry(meta + "/Properties/foo").getDouble(-1),
|
||||
"Property 'foo' not set correctly"),
|
||||
() -> assertEquals("baz",
|
||||
m_ntInstance.getEntry(meta + "/Properties/bar").getString(null),
|
||||
"Property 'bar' not set correctly"),
|
||||
() -> assertEquals(widgetType,
|
||||
m_ntInstance.getEntry(meta + "/PreferredComponent").getString(null),
|
||||
"Preferred component not set correctly"));
|
||||
() ->
|
||||
assertEquals(
|
||||
1234,
|
||||
m_ntInstance.getEntry(meta + "/Properties/foo").getDouble(-1),
|
||||
"Property 'foo' not set correctly"),
|
||||
() ->
|
||||
assertEquals(
|
||||
"baz",
|
||||
m_ntInstance.getEntry(meta + "/Properties/bar").getString(null),
|
||||
"Property 'bar' not set correctly"),
|
||||
() ->
|
||||
assertEquals(
|
||||
widgetType,
|
||||
m_ntInstance.getEntry(meta + "/PreferredComponent").getString(null),
|
||||
"Preferred component not set correctly"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddNumberArray() {
|
||||
NetworkTableEntry entry = m_tab.add("DoubleArray", new double[]{1, 2, 3}).getEntry();
|
||||
NetworkTableEntry entry = m_tab.add("DoubleArray", new double[] {1, 2, 3}).getEntry();
|
||||
assertAll(
|
||||
() -> assertEquals("/Shuffleboard/Tab/DoubleArray", entry.getName()),
|
||||
() -> assertArrayEquals(new double[]{1, 2, 3}, entry.getValue().getDoubleArray()));
|
||||
() -> assertArrayEquals(new double[] {1, 2, 3}, entry.getValue().getDoubleArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddBooleanArray() {
|
||||
NetworkTableEntry entry = m_tab.add("BoolArray", new boolean[]{true, false}).getEntry();
|
||||
NetworkTableEntry entry = m_tab.add("BoolArray", new boolean[] {true, false}).getEntry();
|
||||
assertAll(
|
||||
() -> assertEquals("/Shuffleboard/Tab/BoolArray", entry.getName()),
|
||||
() -> assertArrayEquals(new boolean[]{true, false}, entry.getValue().getBooleanArray()));
|
||||
() -> assertArrayEquals(new boolean[] {true, false}, entry.getValue().getBooleanArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddStringArray() {
|
||||
NetworkTableEntry entry = m_tab.add("StringArray", new String[]{"foo", "bar"}).getEntry();
|
||||
NetworkTableEntry entry = m_tab.add("StringArray", new String[] {"foo", "bar"}).getEntry();
|
||||
assertAll(
|
||||
() -> assertEquals("/Shuffleboard/Tab/StringArray", entry.getName()),
|
||||
() -> assertArrayEquals(new String[]{"foo", "bar"}, entry.getValue().getStringArray()));
|
||||
() -> assertArrayEquals(new String[] {"foo", "bar"}, entry.getValue().getStringArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,9 +134,7 @@ public class ShuffleboardTabTest {
|
||||
assertThrows(IllegalArgumentException.class, () -> m_tab.add("foo", "baz"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Stub for Java 9 {@code Map.of()}.
|
||||
*/
|
||||
/** Stub for Java 9 {@code Map.of()}. */
|
||||
@SuppressWarnings({"unchecked", "PMD"})
|
||||
private static <K, V> Map<K, V> mapOf(Object... entries) {
|
||||
Map<K, V> map = new HashMap<>();
|
||||
@@ -144,5 +143,4 @@ public class ShuffleboardTabTest {
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user