Class Canandcolor.Settings
- Enclosing class:
- Canandcolor
Canandcolor
.
This class holds settings values that can be used to reconfigure Canandcolor via
Canandcolor.setSettings(com.reduxrobotics.sensors.canandcolor.Canandcolor.Settings, double, int)
.
Additionally, objects of this class are returned from Canandcolor.getSettings(double, double, int)
and
Canandcolor.getSettingsAsync()
which can be used to read the device's settings.
// Object initialization Canandcolor canandcolor = new Canandcolor(0); // Only settings that are explicitly set here will be edited, so other settings // such as the status frame period will remain untouched. // For example, canandcolor.setSettings(new Canandcolor.Settings()); will be a no-op. canandcolor.setSettings(new Canandcolor.Settings() .setProximityFramePeriod(0) // disables proximity reading updates .setColorFramePeriod(0.020) // sets the rate of color measurements to every 20 ms .setColorConfig(Canandcolor.ColorPeriod.k80ms) // sets the color integration period to 80 milliseconds ); // canandcolor.setSettings will block by default for up to 500 ms to confirm all values were set.Objects returned by the blocking
Canandcolor.getSettings(double, double, int)
method, unlike v2023,
may now return null on its getters. This occurs when getSettings would've previously
returned null -- however, this allows for partial settings fetches.
To check if the settings fetch succeeded, one can use CanandSettings.allSettingsReceived()
to check
all fields are populated.
Example blocking fetch:
// Object initialization Canandcolor canandcolor = new Canandcolor(0); // Robot code Canandcolor.Settings stg = canandcolor.getSettings(0.5); // wait up to 500 ms if (stg.allSettingsReceived()) { // print the status frame period (usually 1000 ms) System.out.printf("status frame period: %d\n", stg.getStatusFramePeriod()); }
-
Field Summary
Fields inherited from class com.reduxrobotics.canand.CanandSettings
ephemeral, values
-
Constructor Summary
ConstructorDescriptionSettings()
Instantiates a newCanandcolor.Settings
object that is "completely blank" -- holding no settings values at all.Settings
(Canandcolor.Settings toCopy) Instantiates a newCanandcolor.Settings
object that copies its settings from the input instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected byte[]
Gets the list of settings addresses this settings class records.Gets the device's sampling/integration period for the color sensor, if set.Gets the color frame period in seconds [0..65.535], or null if the value has not been set on this object.Gets the digout status frame period in seconds [0..65.535], or null if the value has not been set on this object.Sets the output mode configuration of a digital output pad.Gets whether or not to transmit frame periods early if data has just been received.Gets whether or not the onboard lamp LED setting is to be on.Gets the lamp LED's brightness, scaled from 0.0 (off) to 1.0 (max)Gets whether or not the onboard lamp LED setting is to be on.Gets the proximity frame period in seconds [1..65.535], or null if the value has not been set on this object.Gets the status frame period in seconds [1..65.535], or null if the value has not been set on this object.Sets the sampling/integration period for the color sensor.setColorFramePeriod
(double period) Sets the color frame period in seconds.setDigoutFramePeriod
(double period) Sets the digital output (digout) frame period in seconds.setDigoutOutputMode
(Canandcolor.Digout digout, DigoutMode config) Sets the output mode of a digital output pad.setFramePeriodLatencyAdjustment
(boolean adjust) Sets whether or not to transmit frame periods early if data has just been received.setLampLED
(boolean lamp) Sets whether or not the onboard lamp LED is to be powered.setLampLEDBrightness
(double brightness) Sets the brightness of the onboard lamp LED.Sets fine-tuned settings for the proximity sensor through values in aCanandcolorProximityConfig
object.setProximityFramePeriod
(double period) Sets the proximity frame period in seconds.setStatusFramePeriod
(double period) Sets the status frame period in seconds.Methods inherited from class com.reduxrobotics.canand.CanandSettings
allSettingsReceived, checkBounds, getBool, getFilteredMap, getIntAsDouble, getMap, getMissingIndexes, isEmpty, setEphemeral, toString
-
Constructor Details
-
Settings
public Settings()Instantiates a newCanandcolor.Settings
object that is "completely blank" -- holding no settings values at all. Settings are only populated into theCanandcolor.Settings
object explicitly through the various setter methods -- runningcanandcolor.setSetting(new Canandcolor.Settings())
would not update the device at all. To reset a device back to factory defaults, useCanandcolor.resetFactoryDefaults(double)
-
Settings
Instantiates a newCanandcolor.Settings
object that copies its settings from the input instance.- Parameters:
toCopy
- the input settings object to copy
-
-
Method Details
-
fetchSettingsAddresses
protected byte[] fetchSettingsAddresses()Description copied from class:CanandSettings
Gets the list of settings addresses this settings class records. This is typically a static list of constants from a Details class.- Specified by:
fetchSettingsAddresses
in classCanandSettings
- Returns:
- settings addresses.
-
setStatusFramePeriod
Sets the status frame period in seconds. By factory default, the device will broadcast 1 status message every second (period=1.0).- Parameters:
period
- the new period for status frames in seconds in range [0.001_s, 65.535_s].- Returns:
- the calling object, so these calls can be chained
-
setProximityFramePeriod
Sets the proximity frame period in seconds. By factory default, proximity frames are broadcast every 10 milliseconds (period=0.01). If 0 is passed in, proximity frames will be disabled andCanandcolor.getProximity()
will not return new values.- Parameters:
period
- the new period for proximity frames in seconds in range [0_s, 65.535_s].- Returns:
- the calling object, so these calls can be chained
-
setColorFramePeriod
Sets the color frame period in seconds. By factory default, color frames are broadcast every 40 milliseconds (period=0.04). If 0 is passed in, color frames will be disabled andCanandcolor.getColor()
and other color-reading methods will not return new values.- Parameters:
period
- the new period for color frames in seconds in range [0_s, 65.535_s].- Returns:
- the calling object, so these calls can be chained
-
setDigoutFramePeriod
Sets the digital output (digout) frame period in seconds. By factory default, digout frames are broadcast every 100 milliseconds (period=0.10). If 0 is passed in, digout frames will be disabled andCanandcolor.getDigoutState()
will not return new values.- Parameters:
period
- the new period for digout frames in seconds in range [0_s, 65.535_s].- Returns:
- the calling object, so these calls can be chained
-
setFramePeriodLatencyAdjustment
Sets whether or not to transmit frame periods early if data has just been received. This applies only in the case where frame periods for color and proximity are equal to or less than the configured sampling periods of their corresponding ICs, which is true by default.This increases CAN utilization a little, but minimizes latency.
By factory default this setting is enabled.- Parameters:
adjust
- Whether to enable latency adjustment- Returns:
- the calling object, so these calls can be chained
-
setLampLED
Sets whether or not the onboard lamp LED is to be powered.The LED can als be physically turned off regardless of setting with the onboard switch.
The LED is useful for measuring the color of objects that do not themselves emit light (e.g. most game pieces) or for using the white channel to estimate very close proximity.
By factory default this setting is enabled.- Parameters:
lamp
- whether to enable or disable the lamp LED- Returns:
- the calling object, so these calls can be chained
-
setLampLEDBrightness
Sets the brightness of the onboard lamp LED.The LED can als be physically turned off regardless of setting with the onboard switch.
By factory default this setting is set to max brightness (1.0)- Parameters:
brightness
- scaled brightness from 0.0 (off) to 1.0 (max brightness)- Returns:
- the calling object, so these calls can be chained
-
setProximityConfig
Sets fine-tuned settings for the proximity sensor through values in aCanandcolorProximityConfig
object.- Parameters:
cfg
- the configruation object to apply setings from- Returns:
- the calling object, so these calls can be chained
-
setColorConfig
Sets the sampling/integration period for the color sensor.- Parameters:
period
- theCanandcolor.ColorPeriod
to apply- Returns:
- the calling object, so these calls can be chained
-
setDigoutOutputMode
Sets the output mode of a digital output pad. Digout pins can be set into one of three modes:- disabled, by passing in a
DigoutMode.Disabled
object - high or low via digout slots, by passing in a
DigoutMode.DigoutSlot
object and usingCanandcolor.setDigoutSlot(com.reduxrobotics.sensors.canandcolor.Canandcolor.Digout, int, com.reduxrobotics.sensors.canandcolor.digout.DigoutSlot, double)
- a duty cycle (PWM) output of values from either the color or proximity sensor, by
passing in a
DigoutMode.DutyCycle
) object
- Parameters:
digout
- the digout to configure (eitherCanandcolor.Digout.kDigout1
orCanandcolor.Digout.kDigout2
)config
- aDigoutMode
specifying how the digout should output if at all.- Returns:
- the calling object, so these calls can be chained
- See Also:
- disabled, by passing in a
-
getStatusFramePeriod
Gets the status frame period in seconds [1..65.535], or null if the value has not been set on this object.- Returns:
- the status frame period in seconds [1..65.535], or null if the value has not been set on this object.
-
getProximityFramePeriod
Gets the proximity frame period in seconds [1..65.535], or null if the value has not been set on this object. A value of 0 means proximity messages are disabled.- Returns:
- the frame period in seconds [0..65.535], or null if the value has not been set on this object.
-
getColorFramePeriod
Gets the color frame period in seconds [0..65.535], or null if the value has not been set on this object. A value of 0 means color messages are disabled.- Returns:
- the frame period in seconds [0..65.535], or null if the value has not been set on this object.
-
getDigoutFramePeriod
Gets the digout status frame period in seconds [0..65.535], or null if the value has not been set on this object. A value of 0 means digout status messages are disabled.- Returns:
- the frame period in seconds [0..65.535], or null if the value has not been set on this object.
-
getFramePeriodLatencyAdjustment
Gets whether or not to transmit frame periods early if data has just been received. By factory default this setting is enabled.- Returns:
- true if on, false if off, null if unset
-
getLampLED
Gets whether or not the onboard lamp LED setting is to be on.- Returns:
- true if on, false if off, null if unset
-
getLampLEDBrightness
Gets the lamp LED's brightness, scaled from 0.0 (off) to 1.0 (max)- Returns:
- the brightness factor [0.0..1.0] or null if unset
-
getProximityConfig
Gets whether or not the onboard lamp LED setting is to be on.- Returns:
- true if on, false if off, null if unset
-
getColorConfig
Gets the device's sampling/integration period for the color sensor, if set.- Returns:
Canandcolor.ColorPeriod
enum or null if unset
-
getDigoutOutputMode
Sets the output mode configuration of a digital output pad.- Parameters:
digout
- the digital output config to fetch- Returns:
- the
DigoutMode
or null if unset
-