Package trclib.subsystem
Class TrcIntake
java.lang.Object
trclib.subsystem.TrcIntake
- All Implemented Interfaces:
TrcExclusiveSubsystem
This class implements a generic platform independent intake subsystem. It contains a motor or a continuous
servo and optionally entry and exit sensors that detects if the intake has captured objects. It provides the
auto methods that allow the caller to call the intake subsystem to pickup or eject objects on a press of
a button and the intake subsystem will stop itself once it is done. While it provides the auto functionality
to pickup or eject objects, it also supports exclusive subsystem access by implementing TrcExclusiveSubsystem.
This enables the intake subsystem to be aware of multiple callers' access to the subsystem. While one caller starts
the intake for an operation, nobody can access it until the previous operation is done or canceled.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
This class encapsulates all the parameters required to perform the intake action.private static enum
Specifies the operation types.static class
This class contains all the parameters of the Intake Trigger.Nested classes/interfaces inherited from interface trclib.robotcore.TrcExclusiveSubsystem
TrcExclusiveSubsystem.OwnershipParams
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate TrcIntake.ActionParams
private String
private boolean
final TrcIntake.TriggerParams
final TrcIntake.TriggerParams
private final String
final TrcMotor
private final TrcTimer
private final TrcEvent
final TrcDbgTrace
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor: Creates an instance of the object.TrcIntake
(String instanceName, TrcMotor motor, TrcIntake.TriggerParams entryTrigger) Constructor: Creates an instance of the object.TrcIntake
(String instanceName, TrcMotor motor, TrcIntake.TriggerParams entryTrigger, TrcIntake.TriggerParams exitTrigger) Constructor: Creates an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
actionTimedOut
(Object context) This method is called when the action has timed out.void
autoEjectForward
(double power, double finishDelay) This method performs the auto eject forward operation.void
autoEjectForward
(double delay, double power, double finishDelay) This method performs the auto eject forward operation.void
autoEjectForward
(double delay, double power, double finishDelay, TrcEvent event, double timeout) This method performs the auto eject forward operation.void
autoEjectForward
(String owner, double delay, double power, double finishDelay, TrcEvent event, double timeout) This method performs the auto eject forward operation.void
autoEjectReverse
(double power, double finishDelay) This method performs the auto eject reverse operation.void
autoEjectReverse
(double delay, double power, double finishDelay) This method performs the auto eject reverse operation.void
autoEjectReverse
(double delay, double power, double finishDelay, TrcEvent event, double timeout) This method performs the auto eject reverse operation.void
autoEjectReverse
(String owner, double delay, double power, double finishDelay, TrcEvent event, double timeout) This method performs the auto eject reverse operation.void
autoIntakeForward
(double power, double retainPower, double finishDelay) This method performs the auto intake forward operation.void
autoIntakeForward
(double delay, double power, double retainPower, double finishDelay) This method performs the auto intake forward operation.void
autoIntakeForward
(double delay, double power, double retainPower, double finishDelay, TrcEvent event, double timeout) This method performs the auto intake forward operation.void
autoIntakeForward
(String owner, double delay, double power, double retainPower, double finishDelay, TrcEvent event, double timeout) This method performs the auto intake forward operation.void
autoIntakeReverse
(double power, double retainPower, double finishDelay) This method performs the auto intake reverse operation.void
autoIntakeReverse
(double delay, double power, double retainPower, double finishDelay) This method performs the auto intake reverse operation.void
autoIntakeReverse
(double delay, double power, double retainPower, double finishDelay, TrcEvent event, double timeout) This method performs the auto intake reverse operation.void
autoIntakeReverse
(String owner, double delay, double power, double retainPower, double finishDelay, TrcEvent event, double timeout) This method performs the auto intake reverse operation.private void
autoOperation
(String owner, TrcIntake.Operation operation, double delay, double power, double retainPower, double finishDelay, TrcEvent event, double timeout) This method performs an auto operation.void
cancel()
This method cancel a pending operation if any.void
This method cancel a pending operation if any.private void
entryTriggerCallback
(Object context) This method is called when the entry trigger state has changed.private void
exitTriggerCallback
(Object context) This method is called when the exit trigger state has changed.private void
finish
(boolean completed) This method is called to finish the operation and to clean up.double
getPower()
This method returns the current motor power.boolean
getSensorState
(TrcIntake.TriggerParams trigger) This method returns the sensor state read from the digital sensor of the trigger.double
getSensorValue
(TrcIntake.TriggerParams trigger) This method returns the sensor value read from the analog sensor of the trigger.boolean
This method checks if object is detected in the intake.boolean
This method checks if auto operation is active.boolean
isTriggerActive
(TrcIntake.TriggerParams trigger) This method checks if the trigger sensor has detected an object.private void
performAction
(Object context) This method performs the action.boolean
registerEntryTriggerNotifyEvent
(TrcTrigger.TriggerMode triggerMode, TrcEvent notifyEvent) This method registers a notification event to be signaled when the entry trigger occurred.boolean
registerExitTriggerNotifyEvent
(TrcTrigger.TriggerMode triggerMode, TrcEvent notifyEvent) This method registers a notification event to be signaled when the exit trigger occurred.void
setPower
(double power) This method sets the motor output value for the set period of time.void
setPower
(double power, double duration) This method sets the motor output value for the set period of time.void
setPower
(double delay, double power, double duration) This method sets the motor output value for the set period of time.void
This method sets the motor output value for the set period of time.void
This method sets the motor output value for the set period of time.void
This method sets the motor output value for the set period of time.toString()
This method returns the instance name.boolean
This method unregisters the notification event for the entry trigger.boolean
This method unregisters the notification event for the exit trigger.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface trclib.robotcore.TrcExclusiveSubsystem
acquireExclusiveAccess, acquireOwnership, cancelExclusiveAccess, getCurrentOwner, hasOwnership, releaseExclusiveAccess, releaseOwnership, validateOwnership
-
Field Details
-
tracer
-
instanceName
-
motor
-
entryTrigger
-
exitTrigger
-
timer
-
timerEvent
-
actionParams
-
currOwner
-
delayFinishPending
private boolean delayFinishPending
-
-
Constructor Details
-
TrcIntake
public TrcIntake(String instanceName, TrcMotor motor, TrcIntake.TriggerParams entryTrigger, TrcIntake.TriggerParams exitTrigger) Constructor: Creates an instance of the object.- Parameters:
instanceName
- specifies the hardware name.motor
- specifies the motor object.entryTrigger
- specifies the entry trigger parameters, can be null if no entry trigger.exitTrigger
- specifies the exit trigger parameters, can be null if no exit trigger.
-
TrcIntake
Constructor: Creates an instance of the object.- Parameters:
instanceName
- specifies the hardware name.motor
- specifies the motor object.entryTrigger
- specifies the entry trigger object, can be null if none.
-
TrcIntake
Constructor: Creates an instance of the object.- Parameters:
instanceName
- specifies the hardware name.motor
- specifies the motor object.
-
-
Method Details
-
toString
This method returns the instance name. -
getPower
public double getPower()This method returns the current motor power.- Returns:
- current motor power.
-
setPower
This method sets the motor output value for the set period of time. The motor will be turned off after the set time expires.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the intake subsystem.delay
- specifies the delay in seconds to wait before setting the power of the motor.power
- specifies the percentage power or velocity (range -1.0 to 1.0) to be set.duration
- specifies the duration in seconds to have power set.event
- specifies the event to signal when time has expired.
-
setPower
This method sets the motor output value for the set period of time. The motor will be turned off after the set time expires.- Parameters:
delay
- specifies the delay in seconds to wait before setting the power of the motor.power
- specifies the percentage power or velocity (range -1.0 to 1.0) to be set.duration
- specifies the duration in seconds to have power set.event
- specifies the event to signal when time has expired.
-
setPower
This method sets the motor output value for the set period of time. The motor will be turned off after the set time expires.- Parameters:
power
- specifies the percentage power or velocity (range -1.0 to 1.0) to be set.duration
- specifies the duration in seconds to have power set.event
- specifies the event to signal when time has expired.
-
setPower
public void setPower(double delay, double power, double duration) This method sets the motor output value for the set period of time. The motor will be turned off after the set time expires.- Parameters:
delay
- specifies the delay in seconds to wait before setting the power of the motor.power
- specifies the percentage power or velocity (range -1.0 to 1.0) to be set.duration
- specifies the duration in seconds to have power set.
-
setPower
public void setPower(double power, double duration) This method sets the motor output value for the set period of time. The motor will be turned off after the set time expires.- Parameters:
power
- specifies the percentage power or velocity (range -1.0 to 1.0) to be set.duration
- specifies the duration in seconds to have power set.
-
setPower
public void setPower(double power) This method sets the motor output value for the set period of time. The motor will be turned off after the set time expires.- Parameters:
power
- specifies the percentage power or velocity (range -1.0 to 1.0) to be set.
-
finish
private void finish(boolean completed) This method is called to finish the operation and to clean up. It can be called either at the end of timeout or when object has been captured or ejected to finish the operation and signal the caller for completion. It can also be called if the caller explicitly cancel the operation in which case the event will be set to canceled.- Parameters:
completed
- specifies true if the operation is completed, false if canceled.
-
cancel
This method cancel a pending 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 operation if any. -
performAction
This method performs the action.- Parameters:
context
- specifies the action parameters.
-
actionTimedOut
This method is called when the action has timed out.- Parameters:
context
- not used.
-
entryTriggerCallback
This method is called when the entry trigger state has changed.- Parameters:
context
- specifies the trigger state.
-
exitTriggerCallback
This method is called when the exit trigger state has changed.- Parameters:
context
- specifies the trigger state.
-
registerEntryTriggerNotifyEvent
public boolean registerEntryTriggerNotifyEvent(TrcTrigger.TriggerMode triggerMode, TrcEvent notifyEvent) This method registers a notification event to be signaled when the entry trigger occurred.- Parameters:
triggerMode
- specifies trigger mode that will signal the event.notifyEvent
- specifies the event to signal when entry trigger occurred.- Returns:
- true if success, false if there is no entry trigger or it is already enabled by someone else.
-
unregisterEntryTriggerNotifyEvent
public boolean unregisterEntryTriggerNotifyEvent()This method unregisters the notification event for the entry trigger.- Returns:
- true if success, false if trigger does not exist or has no notification event registered.
-
registerExitTriggerNotifyEvent
public boolean registerExitTriggerNotifyEvent(TrcTrigger.TriggerMode triggerMode, TrcEvent notifyEvent) This method registers a notification event to be signaled when the exit trigger occurred.- Parameters:
triggerMode
- specifies trigger mode that will signal the event.notifyEvent
- specifies the event to signal when exit trigger occurred.- Returns:
- true if success, false if there is no exit trigger or it is already enabled by someone else.
-
unregisterExitTriggerNotifyEvent
public boolean unregisterExitTriggerNotifyEvent()This method unregisters the notification event for the exit trigger.- Returns:
- true if success, false if trigger does not exist or has no notification event registered.
-
autoOperation
private void autoOperation(String owner, TrcIntake.Operation operation, double delay, double power, double retainPower, double finishDelay, TrcEvent event, double timeout) This method performs an auto operation. It allows the caller to start the intake spinning at the given power and it will stop itself once object is picked up or ejected in the intake at which time the given event will be signaled.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the intake subsystem.operation
- specifies the intake operation.delay
- specifies the delay time in seconds before executing the action.power
- specifies the power value to spin the intake.retainPower
- specifies the power to retain the object after it's captured, applicable only to intake object.finishDelay
- specifies the delay in seconds to fnish the auto operation to give it extra time spinning the intake.event
- specifies the event to signal when object is detected in the intake.timeout
- specifies a timeout value at which point it will give up and signal completion. The caller must call hasObject() to figure out if it has given up.
-
autoIntakeForward
public void autoIntakeForward(String owner, double delay, double power, double retainPower, double finishDelay, TrcEvent event, double timeout) This method performs the auto intake forward operation. It allows the caller to start the intake spinning at the given power and it will stop itself once object is picked up in the intake at which time the given event will be signaled.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the intake subsystem.delay
- specifies the delay time in seconds before executing the action.power
- specifies the power value to spin the intake.retainPower
- specifies the power to retain the object after it's captured.finishDelay
- specifies the delay in seconds to fnish the auto operation to give it extra time spinning the intake.event
- specifies the event to signal when object is detected in the intake.timeout
- specifies a timeout value at which point it will give up and signal completion. The caller must call hasObject() to figure out if it has given up.
-
autoIntakeForward
public void autoIntakeForward(double delay, double power, double retainPower, double finishDelay, TrcEvent event, double timeout) This method performs the auto intake forward operation. It allows the caller to start the intake spinning at the given power and it will stop itself once object is picked up in the intake at which time the given event will be signaled.- Parameters:
delay
- specifies the delay time in seconds before executing the action.power
- specifies the power value to spin the intake.retainPower
- specifies the power to retain the object after it's captured.finishDelay
- specifies the delay in seconds to fnish the auto operation to give it extra time spinning the intake.event
- specifies the event to signal when object is detected in the intake.timeout
- specifies a timeout value at which point it will give up and signal completion. The caller must call hasObject() to figure out if it has given up.
-
autoIntakeForward
public void autoIntakeForward(double delay, double power, double retainPower, double finishDelay) This method performs the auto intake forward operation. It allows the caller to start the intake spinning at the given power and it will stop itself once object is picked up in the intake.- Parameters:
delay
- specifies the delay time in seconds before executing the action.power
- specifies the power value to spin the intake.retainPower
- specifies the power to retain the object after it's captured.finishDelay
- specifies the delay in seconds to fnish the auto operation to give it extra time spinning the intake.
-
autoIntakeForward
public void autoIntakeForward(double power, double retainPower, double finishDelay) This method performs the auto intake forward operation. It allows the caller to start the intake spinning at the given power and it will stop itself once object is picked up in the intake.- Parameters:
power
- specifies the power value to spin the intake.retainPower
- specifies the power to retain the object after it's captured.finishDelay
- specifies the delay in seconds to fnish the auto operation to give it extra time spinning the intake.
-
autoIntakeReverse
public void autoIntakeReverse(String owner, double delay, double power, double retainPower, double finishDelay, TrcEvent event, double timeout) This method performs the auto intake reverse operation. It allows the caller to start the intake spinning at the given power and it will stop itself once object is picked up in the intake at which time the given event will be signaled.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the intake subsystem.delay
- specifies the delay time in seconds before executing the action.power
- specifies the power value to spin the intake.retainPower
- specifies the power to retain the object after it's captured.finishDelay
- specifies the delay in seconds to fnish the auto operation to give it extra time spinning the intake.event
- specifies the event to signal when object is detected in the intake.timeout
- specifies a timeout value at which point it will give up and signal completion. The caller must call hasObject() to figure out if it has given up.
-
autoIntakeReverse
public void autoIntakeReverse(double delay, double power, double retainPower, double finishDelay, TrcEvent event, double timeout) This method performs the auto intake reverse operation. It allows the caller to start the intake spinning at the given power and it will stop itself once object is picked up in the intake at which time the given event will be signaled.- Parameters:
delay
- specifies the delay time in seconds before executing the action.power
- specifies the power value to spin the intake.retainPower
- specifies the power to retain the object after it's captured.finishDelay
- specifies the delay in seconds to fnish the auto operation to give it extra time spinning the intake.event
- specifies the event to signal when object is detected in the intake.timeout
- specifies a timeout value at which point it will give up and signal completion. The caller must call hasObject() to figure out if it has given up.
-
autoIntakeReverse
public void autoIntakeReverse(double delay, double power, double retainPower, double finishDelay) This method performs the auto intake reverse operation. It allows the caller to start the intake spinning at the given power and it will stop itself once object is picked up in the intake.- Parameters:
delay
- specifies the delay time in seconds before executing the action.power
- specifies the power value to spin the intake.retainPower
- specifies the power to retain the object after it's captured.finishDelay
- specifies the delay in seconds to fnish the auto operation to give it extra time spinning the intake.
-
autoIntakeReverse
public void autoIntakeReverse(double power, double retainPower, double finishDelay) This method performs the auto intake reverse operation. It allows the caller to start the intake spinning at the given power and it will stop itself once object is picked up in the intake.- Parameters:
power
- specifies the power value to spin the intake.retainPower
- specifies the power to retain the object after it's captured.finishDelay
- specifies the delay in seconds to fnish the auto operation to give it extra time spinning the intake.
-
autoEjectForward
public void autoEjectForward(String owner, double delay, double power, double finishDelay, TrcEvent event, double timeout) This method performs the auto eject forward operation. It allows the caller to start the intake spinning at the given power and it will stop itself once object is ejected in the intake at which time the given event will be signaled.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the intake subsystem.delay
- specifies the delay time in seconds before executing the action.power
- specifies the power value to spin the intake. It assumes positive power to pick up and negative power to eject.finishDelay
- specifies the delay in seconds to fnish the auto operation to give it extra time spinning the intake.event
- specifies the event to signal when object is detected in the intake.timeout
- specifies a timeout value at which point it will give up and signal completion. The caller must call hasObject() to figure out if it has given up.
-
autoEjectForward
public void autoEjectForward(double delay, double power, double finishDelay, TrcEvent event, double timeout) This method performs the auto eject forward operation. It allows the caller to start the intake spinning at the given power and it will stop itself once object is ejected in the intake at which time the given event will be signaled.- Parameters:
delay
- specifies the delay time in seconds before executing the action.power
- specifies the power value to spin the intake. It assumes positive power to pick up and negative power to eject.finishDelay
- specifies the delay in seconds to fnish the auto operation to give it extra time spinning the intake.event
- specifies the event to signal when object is detected in the intake.timeout
- specifies a timeout value at which point it will give up and signal completion. The caller must call hasObject() to figure out if it has given up.
-
autoEjectForward
public void autoEjectForward(double delay, double power, double finishDelay) This method performs the auto eject forward operation. It allows the caller to start the intake spinning at the given power and it will stop itself once object is ejected in the intake.- Parameters:
delay
- specifies the delay time in seconds before executing the action.power
- specifies the power value to spin the intake. It assumes positive power to pick up and negative power to eject.finishDelay
- specifies the delay in seconds to fnish the auto operation to give it extra time spinning the intake.
-
autoEjectForward
public void autoEjectForward(double power, double finishDelay) This method performs the auto eject forward operation. It allows the caller to start the intake spinning at the given power and it will stop itself once object is ejected in the intake.- Parameters:
power
- specifies the power value to spin the intake. It assumes positive power to pick up and negative power to eject.finishDelay
- specifies the delay in seconds to fnish the auto operation to give it extra time spinning the intake.
-
autoEjectReverse
public void autoEjectReverse(String owner, double delay, double power, double finishDelay, TrcEvent event, double timeout) This method performs the auto eject reverse operation. It allows the caller to start the intake spinning at the given power and it will stop itself once object is ejected in the intake at which time the given event will be signaled.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the intake subsystem.delay
- specifies the delay time in seconds before executing the action.power
- specifies the power value to spin the intake. It assumes positive power to pick up and negative power to eject.finishDelay
- specifies the delay in seconds to fnish the auto operation to give it extra time spinning the intake.event
- specifies the event to signal when object is detected in the intake.timeout
- specifies a timeout value at which point it will give up and signal completion. The caller must call hasObject() to figure out if it has given up.
-
autoEjectReverse
public void autoEjectReverse(double delay, double power, double finishDelay, TrcEvent event, double timeout) This method performs the auto eject reverse operation. It allows the caller to start the intake spinning at the given power and it will stop itself once object is ejected in the intake at which time the given event will be signaled.- Parameters:
delay
- specifies the delay time in seconds before executing the action.power
- specifies the power value to spin the intake. It assumes positive power to pick up and negative power to eject.finishDelay
- specifies the delay in seconds to fnish the auto operation to give it extra time spinning the intake.event
- specifies the event to signal when object is detected in the intake.timeout
- specifies a timeout value at which point it will give up and signal completion. The caller must call hasObject() to figure out if it has given up.
-
autoEjectReverse
public void autoEjectReverse(double delay, double power, double finishDelay) This method performs the auto eject reverse operation. It allows the caller to start the intake spinning at the given power and it will stop itself once object is ejected in the intake.- Parameters:
delay
- specifies the delay time in seconds before executing the action.power
- specifies the power value to spin the intake. It assumes positive power to pick up and negative power to eject.finishDelay
- specifies the delay in seconds to fnish the auto operation to give it extra time spinning the intake.
-
autoEjectReverse
public void autoEjectReverse(double power, double finishDelay) This method performs the auto eject reverse operation. It allows the caller to start the intake spinning at the given power and it will stop itself once object is ejected in the intake.- Parameters:
power
- specifies the power value to spin the intake. It assumes positive power to pick up and negative power to eject.finishDelay
- specifies the delay in seconds to fnish the auto operation to give it extra time spinning the intake.
-
getSensorValue
This method returns the sensor value read from the analog sensor of the trigger.- Parameters:
trigger
- specifies the trigger.- Returns:
- analog trigger sensor value.
-
getSensorState
This method returns the sensor state read from the digital sensor of the trigger.- Returns:
- digital trigger sensor state.
-
isTriggerActive
This method checks if the trigger sensor has detected an object.- Parameters:
trigger
- specifies the trigger to check.- Returns:
- true if trigger sensor detected an object, false otherwise.
-
hasObject
public boolean hasObject()This method checks if object is detected in the intake.- Returns:
- true if object is detected in the intake, false otherwise.
-
isAutoActive
public boolean isAutoActive()This method checks if auto operation is active.- Returns:
- true if auto operation is in progress, false otherwise.
-