Class CanandcolorDigoutSlot
java.lang.Object
com.reduxrobotics.sensors.canandcolor.CanandcolorDigoutSlot
Represents a digout "slot" which helps determine the digital output's value.
Instances of this class can be passed to
Canandcolor.setDigoutSlot(CanandcolorDigitalOutput, int, CanandcolorDigoutSlot, double)
to configure the Canandcolor's slots.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Whether the slot should "join" with the next slot at index + 1 to form a clause.static enum
Specifies how the slot (assuming clause joining is enabled) should join with the next slot.static enum
Enum of numerical comparisons.static enum
Data sources that digout slots can use to perform comparisons.static enum
Enums corresponding to digout slot opcodes. -
Method Summary
Modifier and TypeMethodDescriptionstatic CanandcolorDigoutSlot
compareAffine
(CanandcolorDigoutSlot.DataSource src1, double scale, double offset, CanandcolorDigoutSlot.Comparison comparator, CanandcolorDigoutSlot.DataSource src2) Returns a newCanandcolorDigoutSlot
object for a slot that compares two data sources against each other, while scaling and offsetting the first data slot's value.static CanandcolorDigoutSlot
compareImmidiate
(CanandcolorDigoutSlot.DataSource src, CanandcolorDigoutSlot.Comparison comparator, double immidiate) Returns a newCanandcolorDigoutSlot
object for a slot that compares a data source against a constant value (the immidiate).static CanandcolorDigoutSlot
compareSources
(CanandcolorDigoutSlot.DataSource src1, CanandcolorDigoutSlot.Comparison comparator, CanandcolorDigoutSlot.DataSource src2) Returns a newCanandcolorDigoutSlot
object for a slot that compares two data sourcces against each other directly with no affine transformation.static CanandcolorDigoutSlot
Returns a newCanandcolorDigoutSlot
object for a disabled and unconfigured slot.static CanandcolorDigoutSlot
fromSettingData
(long data) Deserializes a 48-bit setting value into aCanandcolorDigoutSlot
object.int
getArg1()
Gets the slot's 16-bit arg1 value.int
getArg2()
Gets the slot's 16-bit arg2 value.Gets if the slot joins with the next slot to form a clauseGets whether the slot's value is ANDed or ORed with the next slot if forming a clauseboolean
Gets whether or not the slot is enabled.Gets the slot's opcode (which determines what it does)static CanandcolorDigoutSlot
prevClauseTrueFor
(double timeSec) Returns a newCanandcolorDigoutSlot
object for a slot that is true if the previous clause has been true for a certain period of time.static CanandcolorDigoutSlot
prevSlotTrueFor
(double timeSec) Returns a newCanandcolorDigoutSlot
object for a slot that is true if the previous slot has been true for a certain period of time.setArg1
(int arg1) Sets the slot's 16-bit arg1 value.setArg2
(int arg2) Sets the slot's 16-bit arg2 value.setClauseJoin
(CanandcolorDigoutSlot.ClauseJoin clauseJoin) Sets if the slot joins with the next slot to form a clausesetClauseOperator
(CanandcolorDigoutSlot.ClauseOperator clauseOperator) Sets whether the slot's value is ANDed or ORed with the next slot if forming a clausesetEnabled
(boolean enabled) Sets whether or not the slot is enabled.Sets the slot's opcode (which determines what it does)long
Serializes theCanandcolorDigoutSlot
to a value that can be written in a set settings packet.
-
Method Details
-
disabledSlot
Returns a newCanandcolorDigoutSlot
object for a disabled and unconfigured slot.- Returns:
- a config that can be passed to
Canandcolor.setDigoutSlot(CanandcolorDigitalOutput, int, CanandcolorDigoutSlot, double)
-
compareImmidiate
public static CanandcolorDigoutSlot compareImmidiate(CanandcolorDigoutSlot.DataSource src, CanandcolorDigoutSlot.Comparison comparator, double immidiate) Returns a newCanandcolorDigoutSlot
object for a slot that compares a data source against a constant value (the immidiate). Slots with this config will evaluate (src_value [operator] immidiate) -- for example, passing incompareImmidiate(DataSource.kProximity, Comparison.kLessThan, 0.5)
will yield a slot which will check if the proximity reading is less than 0.5.- Parameters:
src
- The data source to compare on the LHScomparator
- The comparator to useimmidiate
- The constant value to compare on the RHS- Returns:
- a config that can be passed to
Canandcolor.setDigoutSlot(CanandcolorDigitalOutput, int, CanandcolorDigoutSlot, double)
-
compareAffine
public static CanandcolorDigoutSlot compareAffine(CanandcolorDigoutSlot.DataSource src1, double scale, double offset, CanandcolorDigoutSlot.Comparison comparator, CanandcolorDigoutSlot.DataSource src2) Returns a newCanandcolorDigoutSlot
object for a slot 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)
- Parameters:
src1
- Left hand side data sourcescale
- How much to scale the left hand side data source (between 0.0 to 1.0 inclusive)offset
- How much to offset the left hand side data sourcecomparator
- Comparison operator for LHS and RHSsrc2
- The right hand side data source- Returns:
- a config that can be passed to
Canandcolor.setDigoutSlot(CanandcolorDigitalOutput, int, CanandcolorDigoutSlot, double)
-
compareSources
public static CanandcolorDigoutSlot compareSources(CanandcolorDigoutSlot.DataSource src1, CanandcolorDigoutSlot.Comparison comparator, CanandcolorDigoutSlot.DataSource src2) Returns a newCanandcolorDigoutSlot
object for a slot that compares two data sourcces against each other directly with no affine transformation.// Executes src [operator] src2
- Parameters:
src1
- Left hand side data sourcecomparator
- Comparison operator for LHS and RHSsrc2
- Right hand side data source- Returns:
- a config that can be passed to
Canandcolor.setDigoutSlot(CanandcolorDigitalOutput, int, CanandcolorDigoutSlot, double)
-
prevSlotTrueFor
Returns a newCanandcolorDigoutSlot
object for a slot that is true if the previous slot has been true for a certain period of time.- Parameters:
timeSec
- time the previous slot must be true (in seconds)- Returns:
- a config that can be passed to
Canandcolor.setDigoutSlot(CanandcolorDigitalOutput, int, CanandcolorDigoutSlot, double)
-
prevClauseTrueFor
Returns a newCanandcolorDigoutSlot
object for a slot that is true if the previous clause has been true for a certain period of time.- Parameters:
timeSec
- time the previous clause must be true (in seconds)- Returns:
- a config that can be passed to
Canandcolor.setDigoutSlot(CanandcolorDigitalOutput, int, CanandcolorDigoutSlot, double)
-
getEnabled
public boolean getEnabled()Gets whether or not the slot is enabled. Disabled slots are skipped in computation.- Returns:
- value
-
setEnabled
Sets whether or not the slot is enabled. Disabled slots are skipped in computation.- Parameters:
enabled
- true if enabled, false if not- Returns:
- the object this is called on (to enable chaining calls)
-
getClauseJoin
Gets if the slot joins with the next slot to form a clause- Returns:
- the clause join configuration
-
setClauseJoin
Sets if the slot joins with the next slot to form a clause- Parameters:
clauseJoin
-CanandcolorDigoutSlot.ClauseJoin
enum- Returns:
- the object this is called on (to enable chaining calls)
-
getClauseOperator
Gets whether the slot's value is ANDed or ORed with the next slot if forming a clause- Returns:
- the clause operator configuration
-
setClauseOperator
Sets whether the slot's value is ANDed or ORed with the next slot if forming a clause- Parameters:
clauseOperator
-CanandcolorDigoutSlot.ClauseOperator
enum- Returns:
- the object this is called on (to enable chaining calls)
-
getOpcode
Gets the slot's opcode (which determines what it does)- Returns:
- the opcode of the slot
-
setOpcode
Sets the slot's opcode (which determines what it does)- Parameters:
opcode
- the opcode to set- Returns:
- the object this is called on (to enable chaining calls)
-
getArg1
public int getArg1()Gets the slot's 16-bit arg1 value. The exact format of arg1 is dependent on the opcode.- Returns:
- arg1 value
-
setArg1
Sets the slot's 16-bit arg1 value. The exact format of arg1 is dependent on the opcode.- Parameters:
arg1
- the value to use. Only lower 16 bits are considered.- Returns:
- the object this is called on (to enable chaining calls)
-
getArg2
public int getArg2()Gets the slot's 16-bit arg2 value. The exact format of arg2 is dependent on the opcode.- Returns:
- arg2 value
-
setArg2
Sets the slot's 16-bit arg2 value. The exact format of arg2 is dependent on the opcode.- Parameters:
arg2
- the value to use. Only lower 16 bits are considered.- Returns:
- the object this is called on (to enable chaining calls)
-
toSettingData
public long toSettingData()Serializes theCanandcolorDigoutSlot
to a value that can be written in a set settings packet.- Returns:
- long value (only lower 48 bits are relevant)
-
fromSettingData
Deserializes a 48-bit setting value into aCanandcolorDigoutSlot
object.- Parameters:
data
- setting data- Returns:
CanandcolorDigoutSlot
object
-