Class ShooterSuperstructure

java.lang.Object
frc.robot.superstructure.ShooterSuperstructure

public class ShooterSuperstructure extends Object
A superstructure that controls the functionality of the shooter. This helps coordinate the various subsystems involved with the shooter.

This class is built around the foundation of a state machine, and has a defined list of states it can be in. This helps keep track of the different steps involved in shooting, which makes it a lot easier to tweak behavior and a lot harder to introduce weird bugs where things get into undefined states.

This class also has a concept of shooting sources. These provide target values for the shooter subsystems, and can be built to dynamically update, which aids in the development of things like shoot-from-anywhere functionality.

  • Constructor Details

    • ShooterSuperstructure

      public ShooterSuperstructure(Shooter shooter, Hood hood, Turret turret, HopperUptake hopperUptake, DigitalInput uptakeBeamBreak)
      Creates a new ShooterSuperstructure.
      Parameters:
      shooter - The shooter to control.
      hood - The hood to control.
      turret - The turret to control.
      hopperUptake - The hopper/uptake subsystem to control.
      uptakeBeamBreak - The beam break for the uptake.
  • Method Details

    • update

      public void update()
      Updates the shooter state depending on the current shooting source.

      The main purpose of this method is to handle transitions between different state machine states, as well as updating subsystem targets. Every time this method is run, it will check the current state of the superstructure, and, depending on the current state of the superstructure, the current value of the selected ShootingSource, and feedback from subsystem sensors, this will update the subsystem targets and transition to different states.

    • turnOffCommand

      public Command turnOffCommand()
      Command to turn off the shooter. This can be called from any state, and completely stops the shooter.

      Can be run while disabled.

      Returns:
      Command to run.
    • homeCommand

      public Command homeCommand()
      Command to home the shooter. This can be called from any state, and places the shooter back into automatic control.

      Can be run while disabled.

      Returns:
      Command to run.
    • startManualControlCommand

      public Command startManualControlCommand()
      Command to start manual control of the shooter. This can be called from any state, and allows for controlling the shooter with the other commands.

      Can be run while disabled.

      Returns:
      Command to run.
    • startShootingCommand

      public Command startShootingCommand()
      Command to start shooting. This can only be called from the ShooterSuperstructure.ShooterState.SHOOTING_STAGE_2_READY_TO_SHOOT state.
      Returns:
      Command to run.
    • startShootingWhenReadyCommand

      public Command startShootingWhenReadyCommand()
      Command to start shooting. This will wait until we enter the ShooterSuperstructure.ShooterState.SHOOTING_STAGE_2_READY_TO_SHOOT state to start shooting.

      Exits when exiting the ShooterSuperstructure.ShooterState.SHOOTING_STAGE_3_SHOOTING state.

      Returns:
      Command to run.
    • setStateCommand

      public Command setStateCommand(Supplier<ShooterValues> values)
      Sets the shooter state to the specified state. This requires that you are in ShooterSuperstructure.ShooterState.MANUAL_CONTROL.

      This assumes that we are not tracking a target, since that is done internally.

      Parameters:
      values - Supplier for the values to set the shooter to.
      Returns:
      Command to run.
    • setSourceCommand

      public Command setSourceCommand(ShootingSource source)
      Sets the shooting source to the given source. This can be called from any state.

      Can be run while disabled.

      Parameters:
      source - The source to set.
      Returns:
      Command to run.
    • readyToShootTrigger

      public Trigger readyToShootTrigger()
      Trigger that returns true when ready to shoot. Should be useful for triggering controller haptics.
      Returns:
      Trigger, true when in ShooterSuperstructure.ShooterState.SHOOTING_STAGE_2_READY_TO_SHOOT, false otherwise.
    • subsystemsAtTargets

      public boolean subsystemsAtTargets()
      Checks if the subsystems are at their targets. This checks flywheel speed, hood position, turret position, and uptake speed.
      Returns:
      Are all the shooter subsystems at their targets?
    • subsystemsNeedPause

      public boolean subsystemsNeedPause()
      Checks if the subsystems need for shooting to pause. This checks if the turret is no longer at its target (we can assume other subsystems are close enough).
      Returns:
      True if we need to pause shooting to wait for subsystems to catch up, false otherwise.
      API Note:
      This is intended for internal use, but is made public for logging purposes.
    • getState

      Gets the current state of the shooter state machine.
    • setSource

      public void setSource(ShootingSource source)
      Sets the shooting source to use.

      This can be called at any time, and will immediately take over the current setting.

      Parameters:
      source - Source to set.
    • getSourceName

      public String getSourceName()
      Gets the name of the current shooting source.