commandbased module

class commandbased.commandbasedrobot.CommandBasedRobot(self: wpilib._wpilib.TimedRobot, period: seconds = 0.02) → None[source]

Bases: wpilib._wpilib.TimedRobot

The base class for a Command-Based Robot. To use, instantiate commands and trigger them.

Constructor for TimedRobot.

Parameters

period – Period.

commandPeriodic()[source]

Run the scheduler regularly. If an error occurs during a competition, prevent it from crashing the program.

handleCrash(error)[source]

Called if an exception is raised in the Scheduler during a competition. Writes an error message to the driver station by default. If you want more complex behavior, override this method in your robot class.

class commandbased.cancelcommand.CancelCommand(command)[source]

When this command is run, it cancels the command it was passed.

Parameters

command (Command) – The command to cancel.

initialize(self: wpilib.command._commands_v1.Command) → None[source]

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

isFinished(self: wpilib.command._commands_v1.Command) → bool[source]

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 cancelled 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()

These functions can be used to make programming CommandGroups much more intuitive. For more information, check each method’s docstring.

commandbased.flowcontrol.IF(condition)[source]

Use as a decorator for a function. That function will be placed into a CommandGroup and run inside a ConditionalCommand with the given condition. The decorated function must accept one positional argument that will be used as its ‘self’.

commandbased.flowcontrol.ELIF(condition)[source]

Use as a decorator for a function. That function will be placed into a CommandGroup which will be triggered by a ConditionalCommand that uses the passed condition. That ConditionalCommand will then be added as the onFalse for the ConditionalCommand created by a previous IF or ELIF.

commandbased.flowcontrol.ELSE(func)[source]

Use as a decorator for a function. That function will be placed into a CommandGroup which will be added as the onFalse for the ConditionalCommand created by a previous IF or ELIF.

commandbased.flowcontrol.WHILE(condition)[source]

Use as a decorator for a function. That function will be placed into a CommandGroup, which will be added to a ConditionalCommand. It will be modified to restart itself automatically.

commandbased.flowcontrol.RETURN()[source]

Calling this function will end the source CommandGroup immediately.

commandbased.flowcontrol.BREAK(steps=1)[source]

Calling this function will end the loop that contains it. Pass an integer to break out of that number of nested loops.

class commandbased.flowcontrol.CommandFlow(*args, **kwargs)[source]

Overloaded function.

  1. __init__(self: wpilib.command._commands_v1.CommandGroup) -> None

  2. __init__(self: wpilib.command._commands_v1.CommandGroup, name: str) -> None

Creates a new CommandGroup with the given name.

Parameters

name – The name for this command group

addParallel(*args, **kwargs)[source]

Overloaded function.

  1. addParallel(self: wpilib.command._commands_v1.CommandGroup, command: wpilib.command._commands_v1.Command) -> None

Adds a new child Command to the group. The Command will be started after all the previously added Commands.

Instead of waiting for the child to finish, a CommandGroup will have it run at the same time as the subsequent Commands. The child will run until either it finishes, a new child with conflicting requirements is started, or the main sequence runs a Command with conflicting requirements. In the latter two cases, the child will be canceled even if it says it can’t be interrupted.

Note that any requirements the given Command has will be added to the group. For this reason, a Command’s requirements can not be changed after being added to a group.

It is recommended that this method be called in the constructor.

Parameters

command – The command to be added

  1. addParallel(self: wpilib.command._commands_v1.CommandGroup, command: wpilib.command._commands_v1.Command, timeout: float) -> None

Adds a new child Command to the group with the given timeout. The Command will be started after all the previously added Commands.

Once the Command is started, it will run until it finishes, is interrupted, or the time expires, whichever is sooner. Note that the given Command will have no knowledge that it is on a timer.

Instead of waiting for the child to finish, a CommandGroup will have it run at the same time as the subsequent 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 Command with conflicting requirements. In the latter two cases, the child will be canceled even if it says it can’t be interrupted.

Note that any requirements the given Command has will be added to the group. For this reason, a Command’s requirements can not be changed after being added to a group.

It is recommended that this method be called in the constructor.

Parameters
  • command – The command to be added

  • timeout – The timeout (in seconds)

addSequential(*args, **kwargs)[source]

Overloaded function.

  1. addSequential(self: wpilib.command._commands_v1.CommandGroup, command: wpilib.command._commands_v1.Command) -> None

Adds a new Command to the group. The Command will be started after all the previously added Commands.

Note that any requirements the given Command has will be added to the group. For this reason, a Command’s requirements can not be changed after being added to a group.

It is recommended that this method be called in the constructor.

Parameters

command – The Command to be added

  1. addSequential(self: wpilib.command._commands_v1.CommandGroup, command: wpilib.command._commands_v1.Command, timeout: float) -> None

Adds a new Command to the group with a given timeout. The Command will be started after all the previously added commands.

Once the Command is started, it will be run until it finishes or the time expires, whichever is sooner. Note that the given Command will have no knowledge that it is on a timer.

Note that any requirements the given Command has will be added to the group. For this reason, a Command’s requirements can not be changed after being added to a group.

It is recommended that this method be called in the constructor.

Parameters
  • command – The Command to be added

  • timeout – The timeout (in seconds)

setParent(self: wpilib.command._commands_v1.Command, parent: frc::CommandGroup) → None[source]

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

Parameters

parent – the parent

start(self: wpilib.command._commands_v1.Command) → None[source]

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.