Enum Class DigoutFrameTrigger

java.lang.Object
java.lang.Enum<DigoutFrameTrigger>
com.reduxrobotics.sensors.canandcolor.DigoutFrameTrigger
All Implemented Interfaces:
Serializable, Comparable<DigoutFrameTrigger>, Constable

public enum DigoutFrameTrigger extends Enum<DigoutFrameTrigger>
Enum representing whether to transmit a digout message when the overall value of a DigoutChannel changes state.

Digout frames are by default transmitted every 100 ms on the CAN bus but using this enum can cause the frame to be sent immidiately once the a digout channel's logic slots make its state change.

This can be used even if outputting digout state via the physical outputs is disabled and can be used to asynchronously alert user code to some event via the Frame API, with the overarching goal of enabling robot code to react quickly to events.

This enum can be passed to:

As an applied example, consider the following code snippet:
 // Instantiate object
 Canandcolor color = new Canandcolor(0); 
 
 // Setup digouts; in this case we check if something is close.
 color.digout1().configureSlots(new HSVDigoutConfig().setMaxProximity(0.4));
 
 // This line configures digout packets to be sent immidiately when they change to true 
 // but not when they change to false.
 // 
 // These messages are broadcast in addition to messages sent during regular frame periods.
 color.setSettings(
   new CanandcolorSettings()
     .setDigoutFrameTrigger(DigoutChannel.Index.kDigout1, DigoutFrameTrigger.kFalling)
 );
 
 // This line does the same thing.
 color.digout1().configureFrameTrigger(DigoutFrameTrigger.kFalling);
 
 // Add a callback to perform some action
 color.getDigoutFrame().addCallback(frame -> {
     // This callback gets executed on a separate message update thread away from robot update code.
     if (frame.getValue().getDigoutChannelValue(DigoutChannel.Index.kDigout1)) {
         // Perform some action; e.g. stopping an intake motor.
         // Note that this callback will fire on *any* digout frame, not just one that gets sent because of a message trigger,
         // as by default, digout messages are also broadcasted periodically.
         // User code is thus responsible for appropriate state management (and thread safety!) here.
     }
 });
 
 
  • Enum Constant Details

    • kDisabled

      public static final DigoutFrameTrigger kDisabled
      Disable all extra digout logic-triggered frame packets for the digout channel.
    • kRising

      public static final DigoutFrameTrigger kRising
      Send a message when the digout channel value changes from false to true.
    • kFalling

      public static final DigoutFrameTrigger kFalling
      Send a message when the digout channel value changes from true to false.
    • kRisingAndFalling

      public static final DigoutFrameTrigger kRisingAndFalling
      Send a message when the digout channle value changes at all.
  • Method Details

    • values

      public static DigoutFrameTrigger[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static DigoutFrameTrigger valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • getIndex

      public int getIndex()
      Gets the corresponding index for the value in question.
      Returns:
      the index for the opcode (used in serialization)
    • fromIndex

      public static DigoutFrameTrigger fromIndex(int idx)
      Returns a corresponding vlaue from the given index.
      Parameters:
      idx - the index to fetch.
      Returns:
      a valid value. If invalid, returns disabled.