Record Class DigoutSlot.CompareAffine

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

public static record DigoutSlot.CompareAffine(Canandcolor.DataSource src1, SlotComparison comparator, Canandcolor.DataSource src2, double scale, double offset, ClauseAction clauseAction, boolean invert) extends Record implements DigoutSlot
A DigoutSlot that compares two data sources against each other, while scaling and offsetting the first data slot's value.
 // For two data source values src1 and src2, we compute:
 clamp(src1 * affine + offset, 0.0, 1.0) [operator] src2
  
 // where clamp(value, a, b) is defined as min(max(value, a), b)
 

Example usage:

 // Configure digout1 to check if the red value is less than blue, with the red value adjusted down a little to account for less ambient red readings.
 Canandcolor canandcolor = new Canandcolor(0);
 // ...
 canandcolor.clearAllDigoutSlots(Canandcolor.Digout.kDigout1);
 canandcolor.setSettings(new Canandcolor.Settings().setDigoutOutputMode(Canandcolor.Digout.kDigout1, new DigoutMode.DigoutSlot()));
 
 var slot = new DigoutSlot.CompareAffine(Canandcolor.DataSource.kRed, SlotComparison.kLessThan, Canandcolor.DataSource.kBlue, 1.0, -0.2);
 canandcolor.setDigoutSlot(Canandcolor.Digout.kDigout1, 0, slot);
 
  • Constructor Details

    • CompareAffine

      public CompareAffine(Canandcolor.DataSource src1, SlotComparison comparator, Canandcolor.DataSource src2, double scale, double offset, ClauseAction clauseAction, boolean invert)
      Primary constructor.
      Parameters:
      src1 - Left hand side data source
      comparator - The comparison operation to use
      src2 - Right hand side data source
      scale - How much to scale the left hand side data source [0.0..1.0, both inclusive]
      offset - How much to offset the left hand side data source [-0.5 inclusive..0.5 exclusive)
      clauseAction - if and how the digout slot should join with the next indexed slot.
      invert - whether to invert the value of the result
    • CompareAffine

      public CompareAffine(Canandcolor.DataSource src1, SlotComparison comparator, Canandcolor.DataSource src2, double scale, double offset)
      Simplified constructor assuming no inversion or clause joining. Constructs a compare affine slot where there is no scaling or offsetting of src1, nor inversion and for this slot to terminate a clause.
      Parameters:
      src1 - Left hand side data source
      comparator - The comparison operation to use
      src2 - Right hand side data source
      scale - How much to scale the left hand side data source [0.0..1.0, both inclusive]
      offset - How much to offset the left hand side data source [-0.5 inclusive..0.5 exclusive)
    • CompareAffine

      public CompareAffine(Canandcolor.DataSource src1, SlotComparison comparator, Canandcolor.DataSource src2)
      Simplified constructor assuming no affine transformation, so just directly comparing data sources against each other. Constructs a compare affine slot where there is no scaling or offsetting of src1, nor inversion and for this slot to terminate a clause.
      Parameters:
      src1 - Left hand side data source
      comparator - The comparison operation to use
      src2 - Right hand side data source
  • 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.
    • src1

      public Canandcolor.DataSource src1()
      Returns the value of the src1 record component.
      Returns:
      the value of the src1 record component
    • comparator

      public SlotComparison comparator()
      Returns the value of the comparator record component.
      Returns:
      the value of the comparator record component
    • src2

      public Canandcolor.DataSource src2()
      Returns the value of the src2 record component.
      Returns:
      the value of the src2 record component
    • scale

      public double scale()
      Returns the value of the scale record component.
      Returns:
      the value of the scale record component
    • offset

      public double offset()
      Returns the value of the offset record component.
      Returns:
      the value of the offset 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