Class TrcServoGrabber

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

public class TrcServoGrabber extends Object implements 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.
  • Field Details

  • Constructor Details

    • TrcServoGrabber

      public TrcServoGrabber(String instanceName, TrcServoGrabber.Params params)
      Constructor: Create an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
      params - specifies the servo grabber parameters.
  • Method Details

    • toString

      public String toString()
      This method returns the instance name.
      Overrides:
      toString in class Object
      Returns:
      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.
    • setPosition

      private void setPosition(String owner, double delay, double position, TrcEvent event, double timeout)
      This method sets the grabber position.
      Parameters:
      owner - specifies the owner ID to check if the caller has ownership of the subsystem.
      delay - specifies the delay in seconds before setting the position of the servo, can be zero if no delay.
      position - specifies the physical position of the servo motor. This value may be in degrees if setPhysicalRange is called with the degree range.
      event - specifies an event object to signal when the timeout event has expired.
      timeout - specifies a maximum time value the operation should be completed in seconds.
    • open

      public void open(String owner, double delay, TrcEvent event)
      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

      public void open(String owner, TrcEvent event)
      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

      public void open(TrcEvent event)
      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

      public void close(String owner, double delay, TrcEvent event)
      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

      public void close(String owner, TrcEvent event)
      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

      public void close(TrcEvent event)
      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.
    • finishAction

      private void finishAction(boolean completed)
      This method is called to finish and clean up the action.
      Parameters:
      completed - specifies true to complete the action, false to cancel.
    • actionTimedOut

      private void actionTimedOut(Object context)
      This method cancels the auto-assist operation and to clean up. It is called by autoAssistGrab to cancel a previous operation or if the auto-assist has set a timeout and it has expired. Auto-assist will not be canceled even if the sensor trigger caused it to grab an object. If a timeout is not set, auto-assist remains enabled and can auto grab an object over and over again until the user calls this method to cancel the operation.
      Parameters:
      context - not used.
    • sensorTriggerCallback

      private void sensorTriggerCallback(Object context)
      This method is called when the grabber sensor is triggered.
      Parameters:
      context - not used.
    • performAction

      private void performAction(Object context)
      This method performs the auto action which is to close the grabber if it was open and the object is in proximity or to open the grabber if it was close and it doesn't have the object. It arms the sensor trigger to detect the object for auto grabbing. If there is a timeout, it arms the timeout timer for canceling the auto action when the timer expires.
      Parameters:
      context - specifies the action parameters.
    • armTriggerCallback

      public boolean armTriggerCallback(TrcEvent.Callback triggerCallback, Object callbackContext)
      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

      public void autoGrab(String owner, double delay, TrcEvent event, double timeout)
      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.