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);
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.reduxrobotics.sensors.canandcolor.digout.DigoutSlot
DigoutSlot.CompareAffine, DigoutSlot.CompareImmidiate, DigoutSlot.Disabled, DigoutSlot.PrevClauseTrueFor, DigoutSlot.PrevSlotTrueFor
-
Constructor Summary
ConstructorDescriptionCompareAffine
(Canandcolor.DataSource src1, SlotComparison comparator, Canandcolor.DataSource src2) Simplified constructor assuming no affine transformation, so just directly comparing data sources against each other.CompareAffine
(Canandcolor.DataSource src1, SlotComparison comparator, Canandcolor.DataSource src2, double scale, double offset) Simplified constructor assuming no inversion or clause joining.CompareAffine
(Canandcolor.DataSource src1, SlotComparison comparator, Canandcolor.DataSource src2, double scale, double offset, ClauseAction clauseAction, boolean invert) Primary constructor. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theclauseAction
record component.Returns the value of thecomparator
record component.final boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.boolean
invert()
Returns the value of theinvert
record component.double
offset()
Returns the value of theoffset
record component.double
scale()
Returns the value of thescale
record component.src1()
Returns the value of thesrc1
record component.src2()
Returns the value of thesrc2
record component.long
Serializes the digout slot into a value writeable to device settings.final String
toString()
Returns a string representation of this record class.
-
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 sourcecomparator
- The comparison operation to usesrc2
- Right hand side data sourcescale
- 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 sourcecomparator
- The comparison operation to usesrc2
- Right hand side data sourcescale
- 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 sourcecomparator
- The comparison operation to usesrc2
- 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 interfaceDigoutSlot
- Returns:
- 48-bit long
-
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. -
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. -
equals
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 withObjects::equals(Object,Object)
; primitive components are compared with '=='. -
src1
Returns the value of thesrc1
record component.- Returns:
- the value of the
src1
record component
-
comparator
Returns the value of thecomparator
record component.- Returns:
- the value of the
comparator
record component
-
src2
Returns the value of thesrc2
record component.- Returns:
- the value of the
src2
record component
-
scale
public double scale()Returns the value of thescale
record component.- Returns:
- the value of the
scale
record component
-
offset
public double offset()Returns the value of theoffset
record component.- Returns:
- the value of the
offset
record component
-
clauseAction
Returns the value of theclauseAction
record component.- Returns:
- the value of the
clauseAction
record component
-
invert
public boolean invert()Returns the value of theinvert
record component.- Returns:
- the value of the
invert
record component
-