Record Class DigoutSlot.PrevClauseTrueFor

java.lang.Object
java.lang.Record
com.reduxrobotics.sensors.canandcolor.digout.DigoutSlot.PrevClauseTrueFor
All Implemented Interfaces:
DigoutSlot
Enclosing interface:
DigoutSlot

public static record DigoutSlot.PrevClauseTrueFor(double timeSec, ClauseAction clauseAction, boolean invert) extends Record implements DigoutSlot
A DigoutSlot that is true if the preceding clause has been true for at least a certain period of time.

Example usage:

 // Configure digout1 to be true if the HSV hue is above 0.32 and the proximity value is above 0.3 for at least 2 seconds
 // (e.g. an object is in front of the sensor detected and it's probably blue rather than red)
 Canandcolor canandcolor = new Canandcolor(0);
 // ...
 canandcolor.clearAllDigoutSlots(Canandcolor.Digout.kDigout1);
 canandcolor.setSettings(new Canandcolor.Settings().setDigoutOutputMode(Canandcolor.Digout.kDigout1, new DigoutMode.DigoutSlot()));
 
 canandcolor.setDigoutSlot(Canandcolor.Digout.kDigout1, 0, 
                           new DigoutSlot.CompareImmidiate(Canandcolor.DataSource.kHue, SlotComparison.kGreaterThan, 0.32, ClauseAction.kAndWithNextSlot, false));
 canandcolor.setDigoutSlot(Canandcolor.Digout.kDigout1, 1, 
                           new DigoutSlot.CompareImmidiate(Canandcolor.DataSource.kProximity, SlotComparison.kGreaterThan, 0.3, ClauseAction.kTerminate, false));
 canandcolor.setDigoutSlot(Canandcolor.Digout.kDigout1, 2, new DigoutSlot.PrevClauseTrueFor(2, ClauseAction.kTerminate, false));
 

An instance of this object can be passed to Canandcolor.setDigoutSlot(Canandcolor.Digout, int, DigoutSlot, double) to apply it.

  • Constructor Details

    • PrevClauseTrueFor

      public PrevClauseTrueFor(double timeSec, ClauseAction clauseAction, boolean invert)
      Primary constructor.
      Parameters:
      timeSec - time the previous slot must be true (in seconds, ranging from [0 inclusive..65.536 exclusive))
      clauseAction - if and how the digout slot should join with the next indexed slot.
      invert - whether to invert the value of the result (that is, the previous clause has been true at most timeSec seconds, rather than at least)
  • Method Details

    • toSettingData

      public long toSettingData()
      Description copied from interface: DigoutSlot
      Serializes the digout slot into a value writeable to device settings.
      Specified by:
      toSettingData in interface DigoutSlot
      Returns:
      48-bit long
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • timeSec

      public double timeSec()
      Returns the value of the timeSec record component.
      Returns:
      the value of the timeSec record component
    • clauseAction

      public ClauseAction clauseAction()
      Returns the value of the clauseAction record component.
      Returns:
      the value of the clauseAction record component
    • invert

      public boolean invert()
      Returns the value of the invert record component.
      Returns:
      the value of the invert record component