Enum Class DigoutFrameTrigger
- All Implemented Interfaces:
Serializable
,Comparable<DigoutFrameTrigger>
,Constable
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:
-
CanandcolorSettings.setDigoutFrameTrigger(DigoutChannel.Index, DigoutFrameTrigger)
which may be then used withCanandcolor.setSettings(CanandcolorSettings)
to configure the device, -
or to
DigoutChannel.configureFrameTrigger(DigoutFrameTrigger)
, which will directly configure the associated channel.
// 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. } });
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantDescriptionDisable all extra digout logic-triggered frame packets for the digout channel.Send a message when the digout channel value changes from true to false.Send a message when the digout channel value changes from false to true.Send a message when the digout channle value changes at all. -
Method Summary
Modifier and TypeMethodDescriptionstatic DigoutFrameTrigger
fromIndex
(int idx) Returns a corresponding vlaue from the given index.int
getIndex()
Gets the corresponding index for the value in question.static DigoutFrameTrigger
Returns the enum constant of this class with the specified name.static DigoutFrameTrigger[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
kDisabled
Disable all extra digout logic-triggered frame packets for the digout channel. -
kRising
Send a message when the digout channel value changes from false to true. -
kFalling
Send a message when the digout channel value changes from true to false. -
kRisingAndFalling
Send a message when the digout channle value changes at all.
-
-
Method Details
-
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
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 nameNullPointerException
- 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
Returns a corresponding vlaue from the given index.- Parameters:
idx
- the index to fetch.- Returns:
- a valid value. If invalid, returns disabled.
-