Package trclib.subsystem
Class TrcShooter
java.lang.Object
trclib.subsystem.TrcShooter
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This class encapsulates the parameters for the pan or tilt motors.static interface
This interface must be implemented by the caller to provide a method for shooting the object.Nested classes/interfaces inherited from interface trclib.robotcore.TrcExclusiveSubsystem
TrcExclusiveSubsystem.OwnershipParams
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private final TrcTimer
private TrcEvent
private String
private final String
final TrcMotor
private TrcEvent
private final TrcShooter.PanTiltParams
private TrcEvent
private TrcEvent
final TrcMotor
final TrcMotor
private Double
private TrcShooter.ShootOperation
private String
private final TrcTimer
final TrcMotor
private TrcEvent
private final TrcShooter.PanTiltParams
final TrcDbgTrace
-
Constructor Summary
ConstructorsConstructorDescriptionTrcShooter
(String instanceName, TrcMotor shooterMotor1, TrcMotor shooterMotor2, TrcMotor tiltMotor, TrcShooter.PanTiltParams tiltParams, TrcMotor panMotor, TrcShooter.PanTiltParams panParams) Constructor: Creates an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
aimShooter
(double velocity1, double velocity2, double tiltAngle, double panAngle) This method sets the shooter velocity and the tilt/pan angles if tilt/pan exist.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.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.void
cancel()
This method cancel a pending shooter operation if any.void
This method cancel a pending shooter operation if any.private void
finish
(boolean completed) This method is called when the shooter operation is finished or canceled.This method returns the current absolute pan angle if any.This method returns the current absolute pan angle target from horizontal if any.This method returns the pan motor object if any.This method returns the current applied pan power duty cycle (in the range of -1 to 1) if any.This method returns the shooter motor 1 object.double
This methods returns the shooter motor 1 current power.double
This method returns the shooter motor 1 current RPM.double
This method returns the shooter motor 1 current target RPM.double
This method returns the shooter motor 1 current target velocity.double
This method returns the shooter motor 1 current velocity.This method returns the shooter motor 2 object if any.This methods returns the shooter motor 2 current power if any.This method returns the shooter motor 2 current RPM if any.double
This method returns the shooter motor 2 current target RPM if any.double
This method returns the shooter motor 2 current target velocity if any.This method returns the shooter motor 2 current velocity if any.This method returns the current absolute tilt angle from horizontal if any.This method returns the current absolute tilt angle target from horizontal if any.This method returns the tilt motor object if any.This method returns the current applied tilt power duty cycle (in the range of -1 to 1) if any.boolean
isActive()
This method checks if the shooter is active.private void
This method is called when the shooter has reached target velocity or tilt/pan has reached target positions.boolean
This method checks if pan's lower limit switch is active.boolean
This method checks if pan's upper limit switch is active.void
setPanAngle
(double angle) This method sets the pan angle.void
setPanAngle
(double angle, TrcEvent completionEvent, double timeout) This method sets the pan angle.void
setPanAngle
(String owner, double angle) This method sets the pan angle.void
setPanAngle
(String owner, double angle, TrcEvent completionEvent, double timeout) This method sets the pan angle.void
setPanPidPower
(double power, boolean holdTarget) This method moves pan left and right with the specified power using PID control.void
setPanPidPower
(String owner, double power, boolean holdTarget) This method moves pan left and right with the specified power using PID control.void
setPanPower
(double power) This method moves pan left and right with the specified power.void
setPanPower
(String owner, double power) This method moves pan left and right with the specified power.void
setShooterMotorRPM
(double rpm1, double rpm2) This method sets the shooter motor velocity in RPM.void
setShooterMotorVelocity
(double velocity1, double velocity2) This method sets the shooter motor velocity.void
setTiltAngle
(double angle) This method sets the tilt angle.void
setTiltAngle
(double angle, TrcEvent completionEvent, double timeout) This method sets the tilt angle.void
setTiltAngle
(String owner, double angle) This method sets the tilt angle.void
setTiltAngle
(String owner, double angle, TrcEvent completionEvent, double timeout) This method sets the tilt angle.void
setTiltPidPower
(double power, boolean holdTarget) This method moves tilt up and down with the specified power using PID control.void
setTiltPidPower
(String owner, double power, boolean holdTarget) This method moves tilt up and down with the specified power using PID control.void
setTiltPower
(double power) This method moves tilt up and down with the specified power.void
setTiltPower
(String owner, double power) This method moves tilt up and down with the specified power.private void
shootCompleted
(Object context) This method is called when the object has been ejected from the shooter.void
This method stops the shooter.boolean
This method checks if tilt's lower limit switch is active.boolean
This method checks if tilt's upper limit switch is active.private void
This method is called if the shooter operation has timed out.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface trclib.robotcore.TrcExclusiveSubsystem
acquireExclusiveAccess, acquireOwnership, cancelExclusiveAccess, getCurrentOwner, hasOwnership, releaseExclusiveAccess, releaseOwnership, validateOwnership
-
Field Details
-
tracer
-
instanceName
-
shooterMotor1
-
shooterMotor2
-
tiltMotor
-
tiltParams
-
panMotor
-
panParams
-
aimTimer
-
shootTimer
-
currOwner
-
completionEvent
-
shootOp
-
shootOpOwner
-
shootOffDelay
-
active
private boolean active -
shooter1OnTargetEvent
-
shooter2OnTargetEvent
-
tiltOnTargetEvent
-
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
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
This method is called when the shooter has reached target velocity or tilt/pan has reached target positions.- Parameters:
context
- not used.
-
shootCompleted
This method is called when the object has been ejected from the shooter.- Parameters:
context
- not used.
-
timedOut
This method is called if the shooter operation has timed out.- Parameters:
context
- specifies true for shoot off timeout, false for operation timeout.
-
getShooterMotor1
This method returns the shooter motor 1 object.- Returns:
- shooter motor 1.
-
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
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
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
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
This method returns the tilt motor object if any.- Returns:
- tilt motor, null if none.
-
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
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
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
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
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
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
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
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
This method returns the pan motor object if any.- Returns:
- pan motor, null if none.
-
getPanAngle
This method returns the current absolute pan angle if any.- Returns:
- current pan angle in degrees, null if no pan motor.
-
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
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
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
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
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
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
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.
-