Class Turret

All Implemented Interfaces:
Sendable, Subsystem

public class Turret extends SubsystemBase
The turret that the shooter is attached to.
API Note:
All set position methods in this class are robot-relative, since we don't want to interact with Drivetrain if we don't have to.
  • Constructor Details

    • Turret

      public Turret()
      Creates a new Turret.
  • Method Details

    • periodic

      public void periodic()
    • simulationPeriodic

      public void simulationPeriodic()
    • setPositionCommand

      public Command setPositionCommand(Supplier<Angle> position)
      Command to set the turret to a certain position with MotionMagic.
      Parameters:
      position - Angle to turn to.
      Returns:
      Command to run.
    • isInArrayBinarySearch

      public static boolean isInArrayBinarySearch(double[] values, double target, double tolerance)
      generic binary search, needed for findRotationsFromEncoders, replace if there is one in a library i don't know about
      Parameters:
      values - the list of values to search
      target - the target value
      tolerance - the tolerance of whether a value is the same
      Returns:
    • unspoolCommand

      public Command unspoolCommand()
      Command to unspool the turret. This rotates back to an equivalent position +/- 0.5 rotations from center.

      This allows you to "unspool" the mechanism, untwisting the wires.

      Returns:
      Command to run.
    • setPosition

      public void setPosition(Angle position)
      Commands the turret motor closed loop controller to a certain position, wrapping if applicable.
      Parameters:
      position - Angle to turn to. Wrapped to be within [0-1] rotations (and the shortest path to the target is then taken).
    • getPositionDirect

      public Angle getPositionDirect()
      Gets the current position of the turret with no wrapping.
      Returns:
      The current position of the turret, with no wrapping and scaled to match gear ratios.
    • getPosition

      public Angle getPosition()
      Gets the current position of the turret, wrapped to stay within [0-1].
      Returns:
      The current position of the turret, wrapped and scaled to match gear ratios.
    • isAtTarget

      public boolean isAtTarget()
      Checks if the turret is at its setpoint.
      Returns:
      Is the turret at its setpoint?
    • unspool

      public void unspool()
      Rotates back to an equivalent position +/- 0.5 rotations from center.

      This allows you to "unspool" the mechanism, untwisting the wires.