Class TrcPidConveyor

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

public class TrcPidConveyor extends Object implements TrcExclusiveSubsystem
This class implements a platform independent conveyor subsystem. It contains a motor and optionally an entry and an exit sensor that detects if the an object has entered or exited the conveyor. It also supports exclusive subsystem access by implementing TrcExclusiveSubsystem. This enables the conveyor subsystem to be aware of multiple callers' access to the subsystem. While one caller starts the conveyor for an operation, nobody can access it until the previous caller is done with the operation.
  • Field Details

  • Constructor Details

    • TrcPidConveyor

      public TrcPidConveyor(String instanceName, TrcMotor motor, TrcDigitalInput entrySensor, TrcDigitalInput exitSensor, TrcPidConveyor.Parameters params)
      Constructor: Creates an instance of the object.
      Parameters:
      instanceName - specifies the hardware name.
      motor - specifies the motor object.
      entrySensor - specifies the sensor object for the conveyor entry.
      exitSensor - specifies the sensor object for the conveyor exit.
      params - specifies the parameters object.
  • Method Details

    • getNumObjects

      public int getNumObjects()
      This method returns the number of objects in the conveyor. Note: Conveyor can only keep track of the number of objects if it has entry and exit sensors. Otherwise, the number of objects returned will not be correct.
      Returns:
      number of objects in the conveyor.
    • setPreloadedObjects

      public void setPreloadedObjects(int num)
      This method sets the number of preloaded objects in the conveyor.
      Parameters:
      num - specifies the number of preloaded objects in the conveyor.
    • registerEntryEvent

      public void registerEntryEvent(TrcEvent event)
      This method registers an event to be signaled when the entry sensor is triggered.
      Parameters:
      event - specifies event to signal when an object has entered the conveyor.
    • registerExitEvent

      public void registerExitEvent(TrcEvent event)
      This method registers an event to be signaled when the exit sensor is triggered.
      Parameters:
      event - specifies event to signal when an object has exited the conveyor.
    • isEntrySensorActive

      public boolean isEntrySensorActive()
      This method returns the sensor state read from the digital sensor.
      Returns:
      digital sensor state.
    • isExitSensorActive

      public boolean isExitSensorActive()
      This method returns the sensor state read from the digital sensor.
      Returns:
      digital sensor state.
    • setPower

      public void setPower(String owner, double power)
      This methods sets the conveyor motor power. This is useful if the entry sensor is positioned a little way back such that the conveyor motor needs to be ON and transport the object further in or out.
      Parameters:
      owner - specifies the owner ID to check if the caller has ownership of the conveyor.
      power - specifies the conveyor motor power.
    • move

      public void move(String owner, int units, TrcEvent event)
      This method advances or backs up the conveyor by the number of object units.
      Parameters:
      owner - specifies the owner ID to check if the caller has ownership of the conveyor.
      units - specifies the number of object units to advance or negative number to back up.
      event - specifies the event to signal when done, can be null if not provided.
    • move

      public void move(int units, TrcEvent event)
      This method advances or backs up the conveyor by the number of object units.
      Parameters:
      units - specifies the number of object units to advance or negative number to back up.
      event - specifies the event to signal when done, can be null if not provided.
    • move

      public void move(int units)
      This method advances or backs up the conveyor by the number of object units.
      Parameters:
      units - specifies the number of object units to advance or negative number to back up.
    • advance

      public void advance()
      This method advances the conveyor by the one object unit.
    • backup

      public void backup()
      This method backs up the conveyor by the one object unit.
    • onEntryEvent

      private void onEntryEvent(Object context)
      This method is called when the entry sensor is triggered.
      Parameters:
      context - specifies true if an object has activated the sensor, false if the object has deactivated it.
    • onExitEvent

      private void onExitEvent(Object context)
      This method is called when the exit sensor is triggered.
      Parameters:
      context - specifies true if an object has activated the sensor, false if the object has deactivated it.