Class TrcIntake

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

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

  • 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

      public TrcIntake(String instanceName, TrcMotor motor, TrcIntake.TriggerParams entryTrigger)
      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

      public TrcIntake(String instanceName, TrcMotor motor)
      Constructor: Creates an instance of the object.
      Parameters:
      instanceName - specifies the hardware name.
      motor - specifies the motor object.
  • 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 motor power.
      Returns:
      current motor power.
    • setPower

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

      public void setPower(double delay, double power, double duration, TrcEvent event)
      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

      public void setPower(double power, double duration, TrcEvent event)
      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

      public void cancel(String owner)
      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

      private void performAction(Object context)
      This method performs the action.
      Parameters:
      context - specifies the action parameters.
    • actionTimedOut

      private void actionTimedOut(Object context)
      This method is called when the action has timed out.
      Parameters:
      context - not used.
    • entryTriggerCallback

      private void entryTriggerCallback(Object context)
      This method is called when the entry trigger state has changed.
      Parameters:
      context - specifies the trigger state.
    • exitTriggerCallback

      private void exitTriggerCallback(Object context)
      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

      public double getSensorValue(TrcIntake.TriggerParams trigger)
      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

      public boolean getSensorState(TrcIntake.TriggerParams trigger)
      This method returns the sensor state read from the digital sensor of the trigger.
      Returns:
      digital trigger sensor state.
    • isTriggerActive

      public boolean isTriggerActive(TrcIntake.TriggerParams trigger)
      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.