Command

class commands1.Command(*args, **kwargs)

Bases: wpiutil._wpiutil.Sendable

The Command class is at the very core of the entire command framework.

Every command can be started with a call to Start(). Once a command is started it will call Initialize(), and then will repeatedly call Execute() until the IsFinished() returns true. Once it does,End() will be called.

However, if at any point while it is running Cancel() is called, then the command will be stopped and Interrupted() will be called.

If a command uses a Subsystem, then it should specify that it does so by calling the Requires() method in its constructor. Note that a Command may have multiple requirements, and Requires() should be called for each one.

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 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.

This class is provided by the OldCommands VendorDep * @see CommandGroup @see Subsystem

Overloaded function.

  1. __init__(self: commands1._impl._commands_v1.command.Command) -> None

Creates a new command.

The name of this command will be default.

  1. __init__(self: commands1._impl._commands_v1.command.Command, name: str) -> None

Creates a new command with the given name and no timeout.

Parameters

name – the name for this command

  1. __init__(self: commands1._impl._commands_v1.command.Command, timeout: seconds) -> None

Creates a new command with the given timeout and a default name.

Parameters

timeout – the time before this command “times out” @see IsTimedOut()

  1. __init__(self: commands1._impl._commands_v1.command.Command, subsystem: commands1._impl._commands_v1.command.Subsystem) -> None

Creates a new command with the given timeout and a default name.

Parameters

subsystem – the subsystem that the command requires

  1. __init__(self: commands1._impl._commands_v1.command.Command, name: str, timeout: seconds) -> None

Creates a new command with the given name and timeout.

Parameters
  • name – the name of the command

  • timeout – the time before this command “times out” @see IsTimedOut()

  1. __init__(self: commands1._impl._commands_v1.command.Command, name: str, subsystem: commands1._impl._commands_v1.command.Subsystem) -> None

Creates a new command with the given name and timeout.

Parameters
  • name – the name of the command

  • subsystem – the subsystem that the command requires

  1. __init__(self: commands1._impl._commands_v1.command.Command, timeout: seconds, subsystem: commands1._impl._commands_v1.command.Subsystem) -> None

Creates a new command with the given name and timeout.

Parameters
  • timeout – the time before this command “times out”

  • subsystem – the subsystem that the command requires @see IsTimedOut()

  1. __init__(self: commands1._impl._commands_v1.command.Command, name: str, timeout: seconds, subsystem: commands1._impl._commands_v1.command.Subsystem) -> None

Creates a new command with the given name and timeout.

Parameters
  • name – the name of the command

  • timeout – the time before this command “times out”

  • subsystem – the subsystem that the command requires @see IsTimedOut()

assertUnlocked(message: str) bool

If changes are locked, then this will generate a CommandIllegalUse error.

Parameters

message – The message to report on error (it is appended by a default message)

Returns

True if assert passed, false if assert failed.

cancel() None

This will cancel the current command.

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.

A command can not be canceled if it is a part of a command group, you must cancel the command group instead.

clearRequirements() None

Clears list of subsystem requirements.

This is only used by ConditionalCommand so canceling the chosen command works properly in CommandGroup.

doesRequire(subsystem: commands1._impl._commands_v1.command.Subsystem) bool

Checks if the command requires the given Subsystem.

Parameters

subsystem – the subsystem

Returns

whether or not the subsystem is required (false if given nullptr)

end() None

Called when the command ended peacefully.

This is where you may want to wrap up loose ends, like shutting off a motor that was being used in the command.

execute() None

The execute method is called repeatedly until this Command either finishes or is canceled.

getGroup() commands1._impl._commands_v1.command.CommandGroup

Returns the CommandGroup that this command is a part of.

Will return null if this Command is not in a group.

Returns

The CommandGroup that this command is a part of (or null if not in group)

getID() int

Get the ID (sequence number) for this command.

The ID is a unique sequence number that is incremented for each command.

Returns

The ID of this command

getName() str

Gets the name of this Command.

Returns

Name

getRequirements() set

Returns the requirements (as an std::set of Subsystem pointers) of this command.

Returns

The requirements (as an std::set of Subsystem pointers) of this command

getSubsystem() str

Gets the subsystem name of this Command.

Returns

Subsystem name

initSendable(builder: wpiutil._wpiutil.SendableBuilder) None
initialize() None

The initialize method is called the first time this Command is run after being started.

interrupted() None

Called when the command ends because somebody called Cancel() or another command shared the same requirements as this one, and booted it out.

This is where you may want to wrap up loose ends, like shutting off a motor that was being used in the command.

Generally, it is useful to simply call the End() method within this method, as done here.

isCanceled() bool

Returns whether or not this has been canceled.

Returns

whether or not this has been canceled

isCompleted() bool

Returns whether or not the command has completed running.

Returns

whether or not the command has completed running.

isFinished() bool

Returns whether this command is finished.

If it is, then the command will be removed and End() will be called.

It may be useful for a team to reference the IsTimedOut() method for time-sensitive commands.

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 InstantCommand for this.

Returns

Whether this command is finished. @see IsTimedOut()

isInitialized() bool

Returns whether or not the command has been initialized.

Returns

whether or not the command has been initialized.

isInterruptible() bool

Returns whether or not this command can be interrupted.

Returns

whether or not this command can be interrupted

isParented() bool

Returns whether the command has a parent.

Parameters

True – if the command has a parent.

isRunning() bool

Returns whether or not the command is running.

This may return true even if the command has just been canceled, as it may not have yet called Interrupted().

Returns

whether or not the command is running

isTimedOut() bool

Returns whether or not the TimeSinceInitialized() method returns a number which is greater than or equal to the timeout for the command.

If there is no timeout, this will always return false.

Returns

whether the time has expired

requires(subsystem: commands1._impl._commands_v1.command.Subsystem) None

This method specifies that the given Subsystem is used by this command.

This method is crucial to the functioning of the Command System in general.

Note that the recommended way to call this method is in the constructor.

Parameters

subsystem – The Subsystem required @see Subsystem

run() bool

The run method is used internally to actually run the commands.

Returns

Whether or not the command should stay within the Scheduler.

setInterruptible(interruptible: bool) None

Sets whether or not this command can be interrupted.

Parameters

interruptible – whether or not this command can be interrupted

setName(name: str) None

Sets the name of this Command.

Parameters

name – name

setParent(parent: commands1._impl._commands_v1.command.CommandGroup) None

Sets the parent of this command. No actual change is made to the group.

Parameters

parent – the parent

setRunWhenDisabled(run: bool) None

Sets whether or not this Command should run when the robot is disabled.

By default a command will not run when the robot is disabled, and will in fact be canceled.

Parameters

run – Whether this command should run when the robot is disabled.

setSubsystem(subsystem: str) None

Sets the subsystem name of this Command.

Parameters

subsystem – subsystem name

setTimeout(timeout: seconds) None

Sets the timeout of this command.

Parameters

timeout – the timeout @see IsTimedOut()

start() None

Starts up the command. Gets the command ready to start.

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.

timeSinceInitialized() seconds

Returns the time since this command was initialized.

This function will work even if there is no specified timeout.

Returns

the time since this command was initialized.

willRunWhenDisabled() bool

Returns whether or not this Command will run when the robot is disabled, or if it will cancel itself.

Returns

Whether this Command will run when the robot is disabled, or if it will cancel itself.