Interface Mechanism

All Known Implementing Classes:
Drive, Flag

public interface Mechanism
Generic interface to represent mechanisms on a robot. Commands can require sole ownership of a mechanism; when a command that requires a mechanism is running, no other commands may use it at the same time.

Even though this interface is named "Mechanism", it may be used to represent other physical hardware on a robot that should be controlled with commands - for example, an LED strip or a vision processor that can switch between different pipelines could be represented as mechanisms.

  • Method Details

    • getRegisteredScheduler

      default Scheduler getRegisteredScheduler()
      Returns the scheduler under which this subsystem and its default commands are registered. The scheduler is also used to fetch running commands for the subsystem.
      Returns:
      The registered scheduler.
    • getName

      default String getName()
      Gets the name of this mechanism. This will default to the name of this mechanism's class.
      Returns:
      The name of the mechanism.
    • setDefaultCommand

      default void setDefaultCommand(Command defaultCommand)
      Sets the default command to run on the mechanism when no other command is scheduled. The default command's priority is effectively the minimum allowable priority for any command requiring a mechanism. For this reason, it's recommended that a default command have a priority less than Command.DEFAULT_PRIORITY so it doesn't prevent low-priority commands from running.

      The default command is initially an idle command that only owns the mechanism without doing anything. This command has the lowest possible priority to allow any other command to run.

      Parameters:
      defaultCommand - the new default command
    • getDefaultCommand

      default Command getDefaultCommand()
      Gets the default command that was set by the latest call to setDefaultCommand(Command).
      Returns:
      The currently configured default command
    • run

      default NeedsNameBuilderStage run(Consumer<Coroutine> commandBody)
      Starts building a command that requires this mechanism.
      Parameters:
      commandBody - The main function body of the command.
      Returns:
      The command builder, for further configuration.
    • runRepeatedly

      default NeedsNameBuilderStage runRepeatedly(Runnable loopBody)
      Starts building a command that requires this mechanism. The given function will be called repeatedly in an infinite loop. Useful for building commands that don't need state or multiple stages of logic.
      Parameters:
      loopBody - The body of the infinite loop.
      Returns:
      The command builder, for further configuration.
    • idle

      default Command idle()
      Returns a command that idles this mechanism until another command claims it. The idle command has the lowest priority and can be interrupted by any other command.

      The default command for every mechanism is an idle command unless a different default command has been configured.

      Returns:
      A new idle command.
    • idleFor

      default Command idleFor(Time duration)
      Returns a command that idles this mechanism for the given duration of time.
      Parameters:
      duration - How long the mechanism should idle for.
      Returns:
      A new idle command.
    • getRunningCommands

      default List<Command> getRunningCommands()
      Gets all running commands that require this mechanism. Commands are returned in the order in which they were scheduled. The returned list is read-only. Every command in the list will have been scheduled by the previous entry in the list or by intermediate commands that do not require the mechanism.
      Returns:
      The currently running commands that require the mechanism.