Package trclib.subsystem
Class TrcServoGrabber
java.lang.Object
trclib.subsystem.TrcServoGrabber
- All Implemented Interfaces:
TrcExclusiveSubsystem
This class implements a platform independent auto-assist servo grabber subsystem. It contains one or two servos
and optionally a sensor that detects if the object is within grasp of the grabber. It provides the autoAssist
methods that allow the caller to pickup or dump objects on a press of a button and the grabber subsystem will
automatically grab the object once it is within grasp. While it provides the auto-assist functionality to pickup
or dump objects, it also supports exclusive subsystem access by implementing TrcExclusiveSubsystem. This enables the
grabber subsystem to be aware of multiple callers' access to the subsystem. While one caller starts the subsystem
for an operation, nobody can access it until the previous caller is done with the operation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This class contains all the parameters for the servo grabber.Nested classes/interfaces inherited from interface trclib.robotcore.TrcExclusiveSubsystem
TrcExclusiveSubsystem.OwnershipParams
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTrcServoGrabber
(String instanceName, TrcServoGrabber.Params params) Constructor: Create an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionboolean
armTriggerCallback
(TrcEvent.Callback triggerCallback, Object callbackContext) This method arms the trigger callback.void
This method enables auto grabbing.void
autoGrab
(String owner, double delay, TrcEvent event, double timeout, TrcEvent.Callback triggerCallback, Object callbackContext) This method enables auto grabbing.void
cancel()
This method cancels the auto-assist operation and to clean up.void
close()
This method sets the servo grabber to its close position.void
This method sets the servo grabber to its close position and signals the given event after the close time has expired.void
This method sets the servo grabber to its close position and signals the given event after the close time has expired.void
This method sets the servo grabber to its close position and signals the given event after the close time has expired.double
This method returns the current grabber position.boolean
This method returns the sensor state read from the digital sensor.double
This method returns the sensor value read from the analog sensor.boolean
This method checks if the grabber has the object.boolean
This method checks if auto operation is active.boolean
isClosed()
This method checks if the grabber is closed.void
open()
This method sets the servo grabber to its open position.void
This method sets the servo grabber to its open position and signals the given event after the open time has expired.void
This method sets the servo grabber to its open position and signals the given event after the open time has expired.void
This method sets the servo grabber to its open position and signals the given event after the open time has expired.boolean
This method checks if the sensor has detected the object.toString()
This method returns the instance name.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
-
-
Constructor Details
-
TrcServoGrabber
Constructor: Create an instance of the object.- Parameters:
instanceName
- specifies the instance name.params
- specifies the servo grabber parameters.
-
-
Method Details
-
toString
This method returns the instance name. -
getPosition
public double getPosition()This method returns the current grabber position.- Returns:
- current grabber servo position.
-
isClosed
public boolean isClosed()This method checks if the grabber is closed.- Returns:
- true if grabber is closed, false if open.
-
open
This method sets the servo grabber to its open position and signals the given event after the open time has expired. It cancels the previous pending auto operation if any.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the subsystem.delay
- specifies the time in seconds to delay before setting the power, 0.0 if no delay.event
- specifies the event to be signaled after specified time has expired.
-
open
This method sets the servo grabber to its open position and signals the given event after the open time has expired. It cancels the previous pending auto operation if any.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the subsystem.event
- specifies the event to be signaled after specified time has expired.
-
open
This method sets the servo grabber to its open position and signals the given event after the open time has expired. It cancels the previous pending auto operation if any.- Parameters:
event
- specifies the event to be signaled after specified time has expired.
-
open
public void open()This method sets the servo grabber to its open position. It cancels the previous pending auto operation if any. -
close
This method sets the servo grabber to its close position and signals the given event after the close time has expired. It cancels the previous pending auto operation if any.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the subsystem.delay
- specifies the time in seconds to delay before setting the power, 0.0 if no delay.event
- specifies the event to be signaled after specified time has expired.
-
close
This method sets the servo grabber to its close position and signals the given event after the close time has expired. It cancels the previous pending auto operation if any.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the subsystem.event
- specifies the event to be signaled after specified time has expired.
-
close
This method sets the servo grabber to its close position and signals the given event after the close time has expired. It cancels the previous pending auto operation if any.- Parameters:
event
- specifies the event to be signaled after specified time has expired.
-
close
public void close()This method sets the servo grabber to its close position. It cancels the previous pending auto operation if any. -
armTriggerCallback
This method arms the trigger callback. This is useful in the trigger callback handler that if it decided the trigger is a false trigger, it can ignore the trigger and re-arm the trigger callback. Note that this is intended to be called from the trigger callback handler to re-arm the trigger callback. If it is called somewhere else and there was no pending auto operation or no callback, this call will fail and will return false.- Parameters:
triggerCallback
- specifies the method to call when a trigger occurred, can be null if not provided. If triggerCallback is provided, it is the responsibility of triggerCallback to close the grabber to grab the object and to cancel the operation. In other words, autoGrab mode will not end automatically.callbackContext
- specifies the context object to be passed back to the callback, can be null if none.- Returns:
- true if rearm is successful, false otherwise.
-
autoGrab
public void autoGrab(String owner, double delay, TrcEvent event, double timeout, TrcEvent.Callback triggerCallback, Object callbackContext) This method enables auto grabbing. It allows the caller to start monitoring the trigger sensor for the object in the vicinity. If the object is within grasp, it will automatically grab the object. If an event is provided, it will also signal the event when the operation is completed.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the grabber subsystem.delay
- specifies the delay time in seconds before executing the action.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.triggerCallback
- specifies the method to call when a trigger occurred, can be null if not provided. If triggerCallback is provided, it is the responsibility of triggerCallback to close the grabber to grab the object and to cancel the operation. In other words, autoGrab mode will not end automatically.callbackContext
- specifies the context object to be passed back to the callback, can be null if none.
-
autoGrab
This method enables auto grabbing. It allows the caller to start monitoring the trigger sensor for the object in the vicinity. If the object is within grasp, it will automatically grab the object. If an event is provided, it will also signal the event when the operation is completed.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the grabber subsystem.delay
- specifies the delay time in seconds before executing the action.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.
-
cancel
public void cancel()This method cancels the auto-assist operation and to clean up. It is called by the user for canceling the operation. -
getSensorValue
public double getSensorValue()This method returns the sensor value read from the analog sensor.- Returns:
- analog sensor value.
-
getSensorState
public boolean getSensorState()This method returns the sensor state read from the digital sensor.- Returns:
- digital sensor state.
-
sensorTriggered
public boolean sensorTriggered()This method checks if the sensor has detected the object.- Returns:
- true if object is detected, false otherwise.
-
hasObject
public boolean hasObject()This method checks if the grabber has the object.- Returns:
- true if grabber has the object, false otherwise.
-
isAutoActive
public boolean isAutoActive()This method checks if auto operation is active.- Returns:
- true if auto operation is in progress, false otherwise.
-