Class TrcShooter

java.lang.Object
trclib.subsystem.TrcShooter
All Implemented Interfaces:
TrcExclusiveSubsystem

public class TrcShooter extends Object implements TrcExclusiveSubsystem
This class implements a platform independent auto-assist shooter subsystem. It consists of a shooter motor and optionally a tilt motor and/or a pan motor. It provides methods to automate the shooting operation which includes aiming by panning and tilting to the specified angles and spinning the shooter motor to the specified velocity. It then uses the caller provided shoot method to shoot the object and signals completion if necessary.
  • Field Details

    • tracer

      public final TrcDbgTrace tracer
    • instanceName

      private final String instanceName
    • shooterMotor1

      public final TrcMotor shooterMotor1
    • shooterMotor2

      public final TrcMotor shooterMotor2
    • tiltMotor

      public final TrcMotor tiltMotor
    • tiltParams

      private final TrcShooter.PanTiltParams tiltParams
    • panMotor

      public final TrcMotor panMotor
    • panParams

      private final TrcShooter.PanTiltParams panParams
    • aimTimer

      private final TrcTimer aimTimer
    • shootTimer

      private final TrcTimer shootTimer
    • currOwner

      private String currOwner
    • completionEvent

      private TrcEvent completionEvent
    • shootOp

      private TrcShooter.ShootOperation shootOp
    • shootOpOwner

      private String shootOpOwner
    • shootOffDelay

      private Double shootOffDelay
    • active

      private boolean active
    • shooter1OnTargetEvent

      private TrcEvent shooter1OnTargetEvent
    • shooter2OnTargetEvent

      private TrcEvent shooter2OnTargetEvent
    • tiltOnTargetEvent

      private TrcEvent tiltOnTargetEvent
    • panOnTargetEvent

      private TrcEvent panOnTargetEvent
  • Constructor Details

    • TrcShooter

      public TrcShooter(String instanceName, TrcMotor shooterMotor1, TrcMotor shooterMotor2, TrcMotor tiltMotor, TrcShooter.PanTiltParams tiltParams, TrcMotor panMotor, TrcShooter.PanTiltParams panParams)
      Constructor: Creates an instance of the object.
      Parameters:
      instanceName - specifies the hardware name.
      shooterMotor1 - specifies the shooter motor 1 object.
      shooterMotor2 - specifies the shooter motor 2 object, can be null for one-motor shooter.
      tiltMotor - specifies the tilt motor object, can be null if none.
      tiltParams - specifies the tilt parameters, null if no tilt motor.
      panMotor - specifies the pan motor object, can be null if none.
      panParams - specifies the pan parameters, null if no pan motor.
  • Method Details

    • isActive

      public boolean isActive()
      This method checks if the shooter is active.
      Returns:
      true if shooter is active, false otherwise.
    • finish

      private void finish(boolean completed)
      This method is called when the shooter operation is finished or canceled.
      Parameters:
      completed - specifies true if the operation is completed, false if canceled.
    • cancel

      public void cancel(String owner)
      This method cancel a pending shooter operation if any.
      Parameters:
      owner - specifies the ID string of the caller for checking ownership, can be null if caller is not ownership aware.
    • cancel

      public void cancel()
      This method cancel a pending shooter operation if any.
    • aimShooter

      public void aimShooter(String owner, double velocity1, double velocity2, double tiltAngle, double panAngle, TrcEvent event, double timeout, TrcShooter.ShootOperation shootOp, Double shootOffDelay)
      This method sets the shooter velocity and the tilt/pan angles if tilt/pan exist. This method is asynchronous. When both shooter velocity and tilt/pan positions have reached target and if shoot method is provided, it will shoot and signal an event if provided.
      Parameters:
      owner - specifies the ID string of the caller for checking ownership, can be null if caller is not ownership aware.
      velocity1 - specifies the shooter motor 1 velocity in revolutions per second.
      velocity2 - specifies the shooter motor 2 velocity in revolutions per second, ignored if none.
      tiltAngle - specifies the absolute tilt angle in degrees.
      panAngle - specifies the absolute pan angle in degrees.
      event - specifies an event to signal when both reached target, can be null if not provided.
      timeout - specifies maximum timeout period, can be zero if no timeout.
      shootOp - specifies the shoot method, can be null if aim only.
      shootOffDelay - specifies the delay in seconds to turn off shooter after shooting, or zero if no delay (turn off immediately), only applicable if shootOp is not null. Can also be null if keeping the shooter on.
    • aimShooter

      public void aimShooter(String owner, double velocity1, double velocity2, double tiltAngle, double panAngle, TrcEvent event, double timeout)
      This method sets the shooter velocity and the tilt/pan angles if tilt/pan exist. This method is asynchronous. When both shooter velocity and tilt/pan positions have reached target and if shoot method is provided, it will shoot and signal an event if provided.
      Parameters:
      owner - specifies the ID string of the caller for checking ownership, can be null if caller is not ownership aware.
      velocity1 - specifies the shooter motor 1 velocity in revolutions per second.
      velocity2 - specifies the shooter motor 2 velocity in revolutions per second, ignored if none.
      tiltAngle - specifies the absolute tilt angle in degrees.
      panAngle - specifies the absolute pan angle in degrees.
      event - specifies an event to signal when both reached target, can be null if not provided.
      timeout - specifies maximum timeout period, can be zero if no timeout.
    • aimShooter

      public void aimShooter(double velocity1, double velocity2, double tiltAngle, double panAngle)
      This method sets the shooter velocity and the tilt/pan angles if tilt/pan exist. This method is asynchronous. When both shooter velocity and tilt/pan positions have reached target and if shoot method is provided, it will shoot and signal an event if provided.
      Parameters:
      velocity1 - specifies the shooter motor 1 velocity in revolutions per second.
      velocity2 - specifies the shooter motor 2 velocity in revolutions per second, ignored if none.
      tiltAngle - specifies the absolute tilt angle in degrees.
      panAngle - specifies the absolute pan angle in degrees.
    • onTarget

      private void onTarget(Object context)
      This method is called when the shooter has reached target velocity or tilt/pan has reached target positions.
      Parameters:
      context - not used.
    • shootCompleted

      private void shootCompleted(Object context)
      This method is called when the object has been ejected from the shooter.
      Parameters:
      context - not used.
    • timedOut

      private void timedOut(Object context)
      This method is called if the shooter operation has timed out.
      Parameters:
      context - specifies true for shoot off timeout, false for operation timeout.
    • getShooterMotor1

      public TrcMotor getShooterMotor1()
      This method returns the shooter motor 1 object.
      Returns:
      shooter motor 1.
    • getShooterMotor2

      public TrcMotor getShooterMotor2()
      This method returns the shooter motor 2 object if any.
      Returns:
      shooter motor 2, null if none.
    • getShooterMotor1Power

      public double getShooterMotor1Power()
      This methods returns the shooter motor 1 current power.
      Returns:
      shooter motor 1 current power.
    • getShooterMotor2Power

      public Double getShooterMotor2Power()
      This methods returns the shooter motor 2 current power if any.
      Returns:
      shooter motor 2 current power, null if none.
    • getShooterMotor1Velocity

      public double getShooterMotor1Velocity()
      This method returns the shooter motor 1 current velocity.
      Returns:
      shooter motor 1 current velocity in revolutions per second.
    • getShooterMotor1RPM

      public double getShooterMotor1RPM()
      This method returns the shooter motor 1 current RPM.
      Returns:
      shooter motor 1 current velocity in RPM.
    • getShooterMotor2Velocity

      public Double getShooterMotor2Velocity()
      This method returns the shooter motor 2 current velocity if any.
      Returns:
      shooter motor 2 current velocity in revolutions per second, null if none.
    • getShooterMotor2RPM

      public Double getShooterMotor2RPM()
      This method returns the shooter motor 2 current RPM if any.
      Returns:
      shooter motor 2 current velocity in RPM, null if none.
    • getShooterMotor1TargetVelocity

      public double getShooterMotor1TargetVelocity()
      This method returns the shooter motor 1 current target velocity.
      Returns:
      shooter motor 1 current target velocity in revolutions per second.
    • getShooterMotor1TargetRPM

      public double getShooterMotor1TargetRPM()
      This method returns the shooter motor 1 current target RPM.
      Returns:
      shooter motor 1 current target velocity in RPM.
    • getShooterMotor2TargetVelocity

      public double getShooterMotor2TargetVelocity()
      This method returns the shooter motor 2 current target velocity if any.
      Returns:
      shooter motor 2 current target velocity in revolutions per second, null if none.
    • getShooterMotor2TargetRPM

      public double getShooterMotor2TargetRPM()
      This method returns the shooter motor 2 current target RPM if any.
      Returns:
      shooter motor 2 current target velocity in RPM, null if none.
    • setShooterMotorVelocity

      public void setShooterMotorVelocity(double velocity1, double velocity2)
      This method sets the shooter motor velocity.
      Parameters:
      velocity1 - specifies the motor 1 velocity in revolutions per second.
      velocity2 - specifies the motor 2 velocity in revolutions per second, ignore if no motor 2.
    • setShooterMotorRPM

      public void setShooterMotorRPM(double rpm1, double rpm2)
      This method sets the shooter motor velocity in RPM.
      Parameters:
      rpm1 - specifies the motor 1 velocity in RPM.
      rpm2 - specifies the motor 2 velocity in RPM, ignore if no motor 2.
    • stopShooter

      public void stopShooter()
      This method stops the shooter. Use this method instead of setting shooter velocity to zero because the shooter will coast to a stop instead of stopping abruptly.
    • getTiltMotor

      public TrcMotor getTiltMotor()
      This method returns the tilt motor object if any.
      Returns:
      tilt motor, null if none.
    • getTiltAngle

      public Double getTiltAngle()
      This method returns the current absolute tilt angle from horizontal if any.
      Returns:
      current tilt angle in degrees, null if no tilt motor.
    • getTiltAngleTarget

      public Double getTiltAngleTarget()
      This method returns the current absolute tilt angle target from horizontal if any.
      Returns:
      current tilt angle target in degrees, null if no tilt motor.
    • setTiltAngle

      public void setTiltAngle(String owner, double angle, TrcEvent completionEvent, double timeout)
      This method sets the tilt angle.
      Parameters:
      owner - specifies the ID string of the caller for checking ownership, can be null if caller is not ownership aware.
      angle - specifies the tilt absolute angle from horizontal in degrees (horizontal is 0-degree).
      completionEvent - specifies the event to signal when tilt reached target angle, can be null if not provided.
      timeout - specifies timeout in seconds in case PID control cannot reach target.
    • setTiltAngle

      public void setTiltAngle(double angle, TrcEvent completionEvent, double timeout)
      This method sets the tilt angle.
      Parameters:
      angle - specifies the tilt absolute angle from horizontal in degrees (horizontal is 0-degree).
      completionEvent - specifies the event to signal when tilt reached target angle, can be null if not provided.
      timeout - specifies timeout in seconds in case PID control cannot reach target.
    • setTiltAngle

      public void setTiltAngle(String owner, double angle)
      This method sets the tilt angle.
      Parameters:
      owner - specifies the ID string of the caller for checking ownership, can be null if caller is not ownership aware.
      angle - specifies the tilt absolute angle from horizontal in degrees (horizontal is 0-degree).
    • setTiltAngle

      public void setTiltAngle(double angle)
      This method sets the tilt angle.
      Parameters:
      angle - specifies the tilt absolute angle from horizontal in degrees (horizontal is 0-degree).
    • getTiltPower

      public Double getTiltPower()
      This method returns the current applied tilt power duty cycle (in the range of -1 to 1) if any.
      Returns:
      current tilt power, null if no tilt motor.
    • setTiltPower

      public void setTiltPower(String owner, double power)
      This method moves tilt up and down with the specified power. It is typically used by TeleOp to control tilting by a joystick value in manual override mode.
      Parameters:
      owner - specifies the ID string of the caller for checking ownership, can be null if caller is not ownership aware.
      power - specifies the power duty cycle used to move tilt (in the range of -1 to 1).
    • setTiltPower

      public void setTiltPower(double power)
      This method moves tilt up and down with the specified power. It is typically used by TeleOp to control tilting by a joystick value in manual override mode.
      Parameters:
      power - specifies the power duty cycle used to move tilt (in the range of -1 to 1).
    • setTiltPidPower

      public void setTiltPidPower(String owner, double power, boolean holdTarget)
      This method moves tilt up and down with the specified power using PID control. It is typically used by TeleOp to control tilting by a joystick value.
      Parameters:
      owner - specifies the owner ID to check if the caller has ownership of the motor.
      power - specifies the upper bound power of the motor.
      holdTarget - specifies true to hold target when speed is set to 0, false otherwise.
    • setTiltPidPower

      public void setTiltPidPower(double power, boolean holdTarget)
      This method moves tilt up and down with the specified power using PID control. It is typically used by TeleOp to control tilting by a joystick value.
      Parameters:
      power - specifies the upper bound power of the motor.
      holdTarget - specifies true to hold target when speed is set to 0, false otherwise.
    • tiltLowerLimitSwitchActive

      public boolean tiltLowerLimitSwitchActive()
      This method checks if tilt's lower limit switch is active.
      Returns:
      true if active, false otherwise.
    • tiltUpperLimitSwitchActive

      public boolean tiltUpperLimitSwitchActive()
      This method checks if tilt's upper limit switch is active.
      Returns:
      true if active, false otherwise.
    • getPanMotor

      public TrcMotor getPanMotor()
      This method returns the pan motor object if any.
      Returns:
      pan motor, null if none.
    • getPanAngle

      public Double getPanAngle()
      This method returns the current absolute pan angle if any.
      Returns:
      current pan angle in degrees, null if no pan motor.
    • getPanAngleTarget

      public Double getPanAngleTarget()
      This method returns the current absolute pan angle target from horizontal if any.
      Returns:
      current pan angle target in degrees, null if no pan motor.
    • setPanAngle

      public void setPanAngle(String owner, double angle, TrcEvent completionEvent, double timeout)
      This method sets the pan angle.
      Parameters:
      owner - specifies the ID string of the caller for checking ownership, can be null if caller is not ownership aware.
      angle - specifies the pan absolute angle in degrees.
      completionEvent - specifies the event to signal when pan reached target angle, can be null if not provided.
      timeout - specifies timeout in seconds in case PID control cannot reach target.
    • setPanAngle

      public void setPanAngle(double angle, TrcEvent completionEvent, double timeout)
      This method sets the pan angle.
      Parameters:
      angle - specifies the pan absolute angle in degrees.
      completionEvent - specifies the event to signal when pan reached target angle, can be null if not provided.
      timeout - specifies timeout in seconds in case PID control cannot reach target.
    • setPanAngle

      public void setPanAngle(String owner, double angle)
      This method sets the pan angle.
      Parameters:
      owner - specifies the ID string of the caller for checking ownership, can be null if caller is not ownership aware.
      angle - specifies the pan absolute angle in degrees.
    • setPanAngle

      public void setPanAngle(double angle)
      This method sets the pan angle.
      Parameters:
      angle - specifies the pan absolute angle in degrees.
    • getPanPower

      public Double getPanPower()
      This method returns the current applied pan power duty cycle (in the range of -1 to 1) if any.
      Returns:
      current pan power, null if no pan motor.
    • setPanPower

      public void setPanPower(String owner, double power)
      This method moves pan left and right with the specified power. It is typically used by TeleOp to control panning by a joystick value in manual override mode.
      Parameters:
      owner - specifies the ID string of the caller for checking ownership, can be null if caller is not ownership aware.
      power - specifies the power duty cycle used to move pan (in the range of -1 to 1).
    • setPanPower

      public void setPanPower(double power)
      This method moves pan left and right with the specified power. It is typically used by TeleOp to control panning by a joystick value in manual override mode.
      Parameters:
      power - specifies the power duty cycle used to move pan (in the range of -1 to 1).
    • setPanPidPower

      public void setPanPidPower(String owner, double power, boolean holdTarget)
      This method moves pan left and right with the specified power using PID control. It is typically used by TeleOp to control panning by a joystick value.
      Parameters:
      owner - specifies the owner ID to check if the caller has ownership of the motor.
      power - specifies the upper bound power of the motor.
      holdTarget - specifies true to hold target when speed is set to 0, false otherwise.
    • setPanPidPower

      public void setPanPidPower(double power, boolean holdTarget)
      This method moves pan left and right with the specified power using PID control. It is typically used by TeleOp to control panning by a joystick value.
      Parameters:
      power - specifies the upper bound power of the motor.
      holdTarget - specifies true to hold target when speed is set to 0, false otherwise.
    • panLowerLimitSwitchActive

      public boolean panLowerLimitSwitchActive()
      This method checks if pan's lower limit switch is active.
      Returns:
      true if active, false otherwise.
    • panUpperLimitSwitchActive

      public boolean panUpperLimitSwitchActive()
      This method checks if pan's upper limit switch is active.
      Returns:
      true if active, false otherwise.