Class TrcMotorGrabber

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

public class TrcMotorGrabber extends Object implements TrcExclusiveSubsystem
This class implements a platform independent auto-assist motor grabber subsystem. It contains one or two motors 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 Classes
    Modifier and Type
    Class
    Description
    private static class 
    This class encapsulates all the parameters required to perform the action.
    static class 
    This class contains all the parameters for the motor grabber.

    Nested classes/interfaces inherited from interface trclib.robotcore.TrcExclusiveSubsystem

    TrcExclusiveSubsystem.OwnershipParams
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    private final String
     
     
    private final TrcTimer
     
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor: Create an instance of the object.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    This method cancels the auto-assist operation and to clean up.
    private void
    autoAction(boolean intakeAction, String owner, double delay, double finishDelay, TrcEvent event, double timeout, TrcEvent.Callback triggerCallback, Object callbackContext)
    This method enables auto operation.
    void
    This method enables auto eject.
    void
    autoEject(String owner, double delay, double finishDelay, TrcEvent event, double timeout)
    This method enables auto eject.
    void
    autoEject(String owner, double delay, double finishDelay, TrcEvent event, double timeout, TrcEvent.Callback triggerCallback, Object callbackContext)
    This method enables auto eject.
    void
    autoEject(String owner, double finishDelay, TrcEvent event, double timeout)
    This method enables auto eject.
    void
    This method enables auto intake.
    void
    autoIntake(String owner, double delay, double finishDelay, TrcEvent event, double timeout)
    This method enables auto intake.
    void
    autoIntake(String owner, double delay, double finishDelay, TrcEvent event, double timeout, TrcEvent.Callback triggerCallback, Object callbackContext)
    This method enables auto intake.
    void
    autoIntake(String owner, double finishDelay, TrcEvent event, double timeout)
    This method enables auto intake.
    void
    This method cancels the auto-assist operation and to clean up.
    void
    This method starts the grabber motor with eject power.
    void
    eject(double duration, TrcEvent event)
    This method starts the grabber motor with eject power and optionally specifies the duration after which to turn off the motor automatically and signal an event if provided.
    void
    eject(String owner, double delay, double duration, TrcEvent event)
    This method starts the grabber motor with eject power and optionally specifies the duration after which to turn off the motor automatically and signal an event if provided.
    void
    eject(String owner, double duration, TrcEvent event)
    This method starts the grabber motor with eject power and optionally specifies the duration after which to turn off the motor automatically and signal an event if provided.
    private void
    finishAction(boolean completed)
    This method is called to finish and clean up the action.
    double
    This method returns the current grabber motor power.
    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 object is detected.
    void
    This method starts the grabber motor with intake power.
    void
    intake(double duration, TrcEvent event)
    This method starts the grabber motor with intake power and optionally specifies the duration after which to turn off the motor automatically and signal an event if provided.
    void
    intake(String owner, double delay, double duration, TrcEvent event)
    This method starts the grabber motor with intake power and optionally specifies the duration after which to turn off the motor automatically and signal an event if provided.
    void
    intake(String owner, double duration, TrcEvent event)
    This method starts the grabber motor with intake power and optionally specifies the duration after which to turn off the motor automatically and signal an event if provided.
    boolean
    This method checks if auto operation is active.
    boolean
    This method checks if the motor grabber is ON.
    private void
    This method performs the auto action which is to spin the motor for intake if we don't have the object or eject if we still have the object.
    private void
    This method is called when the grabber sensor is triggered.
    private void
    setPower(String owner, double delay, double power, double duration, TrcEvent event)
    This method spins the motor grabber with the specified power and optional duration.
    void
    This method stops the grabber motor.
    void
    stop(String owner)
    This method stops the grabber motor.
    This method returns the instance name.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • TrcMotorGrabber

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

    • toString

      public String toString()
      This method returns the instance name.
      Overrides:
      toString in class Object
      Returns:
      instance name.
    • getPower

      public double getPower()
      This method returns the current grabber motor power.
      Returns:
      current grabber motor power.
    • isOn

      public boolean isOn()
      This method checks if the motor grabber is ON.
      Returns:
      true if grabber is ON, false if open.
    • setPower

      private void setPower(String owner, double delay, double power, double duration, TrcEvent event)
      This method spins the motor grabber with the specified power and optional duration.
      Parameters:
      owner - specifies the ID string of the caller for checking ownership, can be null if caller is not ownership aware.
      delay - specifies the time in seconds to delay before setting the power, 0.0 if no delay.
      power - specifies the percentage power (range -1.0 to 1.0).
      duration - specifies the duration in seconds to run the motor and turns it off afterwards, 0.0 if not turning off.
      event - specifies the event to signal when the motor operation is completed.
    • stop

      public void stop(String owner)
      This method stops the grabber motor.
      Parameters:
      owner - specifies the ID string of the caller for checking ownership, can be null if caller is not ownership aware.
    • stop

      public void stop()
      This method stops the grabber motor.
    • intake

      public void intake(String owner, double delay, double duration, TrcEvent event)
      This method starts the grabber motor with intake power and optionally specifies the duration after which to turn off the motor automatically and signal an event if provided.
      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.
      duration - specifies the duration in seconds to run the motor and turns it off afterwards, 0.0 if not turning off.
      event - specifies the event to signal when the motor operation is completed.
    • intake

      public void intake(String owner, double duration, TrcEvent event)
      This method starts the grabber motor with intake power and optionally specifies the duration after which to turn off the motor automatically and signal an event if provided.
      Parameters:
      owner - specifies the owner ID to check if the caller has ownership of the subsystem.
      duration - specifies the duration in seconds to run the motor and turns it off afterwards, 0.0 if not turning off.
      event - specifies the event to signal when the motor operation is completed.
    • intake

      public void intake(double duration, TrcEvent event)
      This method starts the grabber motor with intake power and optionally specifies the duration after which to turn off the motor automatically and signal an event if provided.
      Parameters:
      duration - specifies the duration in seconds to run the motor and turns it off afterwards, 0.0 if not turning off.
      event - specifies the event to signal when the motor operation is completed.
    • intake

      public void intake()
      This method starts the grabber motor with intake power.
    • eject

      public void eject(String owner, double delay, double duration, TrcEvent event)
      This method starts the grabber motor with eject power and optionally specifies the duration after which to turn off the motor automatically and signal an event if provided.
      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.
      duration - specifies the duration in seconds to run the motor and turns it off afterwards, 0.0 if not turning off.
      event - specifies the event to signal when the motor operation is completed.
    • eject

      public void eject(String owner, double duration, TrcEvent event)
      This method starts the grabber motor with eject power and optionally specifies the duration after which to turn off the motor automatically and signal an event if provided.
      Parameters:
      owner - specifies the owner ID to check if the caller has ownership of the subsystem.
      duration - specifies the duration in seconds to run the motor and turns it off afterwards, 0.0 if not turning off.
      event - specifies the event to signal when the motor operation is completed.
    • eject

      public void eject(double duration, TrcEvent event)
      This method starts the grabber motor with eject power and optionally specifies the duration after which to turn off the motor automatically and signal an event if provided.
      Parameters:
      duration - specifies the duration in seconds to run the motor and turns it off afterwards, 0.0 if not turning off.
      event - specifies the event to signal when the motor operation is completed.
    • eject

      public void eject()
      This method starts the grabber motor with eject power.
    • 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 enableAutoAssist 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 spin the motor for intake if we don't have the object or eject if we still have the object. It arms the sensor trigger to detect object possession. 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.
    • autoAction

      private void autoAction(boolean intakeAction, String owner, double delay, double finishDelay, TrcEvent event, double timeout, TrcEvent.Callback triggerCallback, Object callbackContext)
      This method enables auto operation. It allows the caller to start monitoring the trigger sensor for the object in the grabber. If the operation is completed, it will automatically stop the motor. If an event is provided, it will also signal the event when the operation is completed.
      Parameters:
      intakeAction - specifies true if the action is intake, false if eject.
      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.
      finishDelay - specifies the delay in seconds between sensor trigger and finishing the operation, can be 0.0 for no delay. This is useful to make sure the grabber has a good grasp of the object before we turn off the motor.
      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.
      callbackContext - specifies the context object to be passed back to the callback, can be null if none.
    • autoIntake

      public void autoIntake(String owner, double delay, double finishDelay, TrcEvent event, double timeout, TrcEvent.Callback triggerCallback, Object callbackContext)
      This method enables auto intake. It allows the caller to start monitoring the trigger sensor for the object in the grabber. If the operation is completed, it will automatically stop the motor. 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.
      finishDelay - specifies the delay in seconds between sensor trigger and finishing the operation, can be 0.0 for no delay. This is useful to make sure the grabber has a good grasp of the object before we turn off the motor.
      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.
      callbackContext - specifies the context object to be passed back to the callback, can be null if none.
    • autoIntake

      public void autoIntake(String owner, double delay, double finishDelay, TrcEvent event, double timeout)
      This method enables auto intake. It allows the caller to start monitoring the trigger sensor for the object in the grabber. If the operation is completed, it will automatically stop the motor. 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.
      finishDelay - specifies the delay in seconds between sensor trigger and finishing the operation, can be 0.0 for no delay. This is useful to make sure the grabber has a good grasp of the object before we turn off the motor.
      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.
    • autoIntake

      public void autoIntake(String owner, double finishDelay, TrcEvent event, double timeout)
      This method enables auto intake. It allows the caller to start monitoring the trigger sensor for the object in the grabber. If the operation is completed, it will automatically stop the motor. 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.
      finishDelay - specifies the delay in seconds between sensor trigger and finishing the operation, can be 0.0 for no delay. This is useful to make sure the grabber has a good grasp of the object before we turn off the motor.
      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.
    • autoIntake

      public void autoIntake(String owner)
      This method enables auto intake. It allows the caller to start monitoring the trigger sensor for the object in the grabber. If the operation is completed, it will automatically stop the motor. 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.
    • autoEject

      public void autoEject(String owner, double delay, double finishDelay, TrcEvent event, double timeout, TrcEvent.Callback triggerCallback, Object callbackContext)
      This method enables auto eject. It allows the caller to start monitoring the trigger sensor for the object in the grabber. If the operation is completed, it will automatically stop the motor. 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.
      finishDelay - specifies the delay in seconds between sensor trigger and finishing the operation, can be 0.0 for no delay. This is useful to make sure the grabber has a good grasp of the object before we turn off the motor.
      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.
      callbackContext - specifies the context object to be passed back to the callback, can be null if none.
    • autoEject

      public void autoEject(String owner, double delay, double finishDelay, TrcEvent event, double timeout)
      This method enables auto eject. It allows the caller to start monitoring the trigger sensor for the object in the grabber. If the operation is completed, it will automatically stop the motor. 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.
      finishDelay - specifies the delay in seconds between sensor trigger and finishing the operation, can be 0.0 for no delay. This is useful to make sure the grabber has a good grasp of the object before we turn off the motor.
      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.
    • autoEject

      public void autoEject(String owner, double finishDelay, TrcEvent event, double timeout)
      This method enables auto eject. It allows the caller to start monitoring the trigger sensor for the object in the grabber. If the operation is completed, it will automatically stop the motor. 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.
      finishDelay - specifies the delay in seconds between sensor trigger and finishing the operation, can be 0.0 for no delay. This is useful to make sure the grabber has a good grasp of the object before we turn off the motor.
      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.
    • autoEject

      public void autoEject(String owner)
      This method enables auto eject. It allows the caller to start monitoring the trigger sensor for the object in the grabber. If the operation is completed, it will automatically stop the motor. 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.
    • 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.
    • hasObject

      public boolean hasObject()
      This method checks if object is detected.
      Returns:
      true if object is detected, false otherwise.
    • isAutoActive

      public boolean isAutoActive()
      This method checks if auto operation is active.
      Returns:
      true if auto operation is in progress, false otherwise.