Class CanandcolorSettings
Canandcolor
.
This class holds settings values that can be used to reconfigure Canandcolor via
Canandcolor.setSettings(CanandcolorSettings)
.
Additionally, objects of this class are returned from Canandcolor.getSettings()
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 CanandcolorSettings()); will be a no-op. canandcolor.setSettings(new CanandcolorSettings() .setProximityFramePeriod(0) // disables proximity reading updates .setColorFramePeriod(0.020) // sets the rate of color measurements to every 20 ms .setColorIntegrationPeriod(ColorPeriod.k25ms) // sets the color integration period to 25 milliseconds ); // canandcolor.setSettings will block by default for up to 350 ms to confirm all values were set.
To check if the settings fetch succeeded, one can use CanandSettings.allSettingsReceived()
to check
all fields are populated. If that flag is true, all Optional
values returned by the getters
can be assumed to not be Optional.empty()
.
// Object initialization Canandcolor canandcolor = new Canandcolor(0); // Robot code CanandcolorSettings stg = canandcolor.getSettings(0.5); // wait up to 500 ms if (stg.allSettingsReceived()) { // print the status frame period (usually 100 ms) System.out.printf("status frame period: %d\n", stg.getStatusFramePeriod().get()); }
-
Field Summary
Fields inherited from class com.reduxrobotics.canand.CanandSettings
ephemeral, values
-
Constructor Summary
ConstructorDescriptionInstantiates a newCanandcolorSettings
object that is "completely blank" -- holding no settings values at all.Instantiates a newCanandcolorSettings
object that copies its settings from the input instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected int[]
Gets the list of settings addresses this settings class records.Gets the config for color frame period alignment with integration period.Gets the config for proximity frame period alignment with integration period.Gets the color frame period in seconds [0..65.535], or an emptyOptional
if the value has not been set on this object.Gets the sampling/integration period for the color sensor, if set on this object.Gets the digout status frame period in seconds [0..65.535], or an emptyOptional
if the value has not been set on this object.Gets the frame trigger configuration for a digital output.Gets the output configuration for a physical GPIO pin associated with the given digout channel.Gets the lamp LED's brightness, scaled from 0.0 (off) to 1.0 (max)Gets the proximity frame period in seconds [0..65.535], or an emptyOptional
if the value has not been set on this object.Gets the sampling/integration period for the proximity sensor, if set on this object.Gets the status frame period in seconds [0.001..65.535], or an emptyOptional
if the value has not been set on this object.setAlignColorFramesToIntegrationPeriod
(boolean align) Sets whether or not to align the transmission of color frames to the integration period of the color sensor.setAlignProximityFramesToIntegrationPeriod
(boolean align) Sets whether or not to align the transmission of proximity frames to the integration period of the proximity sensor.setColorFramePeriod
(double period) Sets the color frame period in seconds.setColorIntegrationPeriod
(ColorPeriod period) Sets the sampling/integration period for the color sensor.setDigoutFramePeriod
(double period) Sets the digital output (digout) frame period in seconds.setDigoutFrameTrigger
(DigoutChannel.Index digout, DigoutFrameTrigger trg) Sets digout message triggers which control if the Canandcolor should send digout messages on state change.setDigoutPinConfig
(DigoutChannel.Index digout, DigoutPinConfig config) Configures the physical GPIO pin associated with a given digital output channel.setLampLEDBrightness
(double brightness) Sets the brightness of the onboard lamp LED.setProximityFramePeriod
(double period) Sets the proximity frame period in seconds.Sets the integration period/multipulse configuration for the proximity sensor.setStatusFramePeriod
(double period) Sets the status frame period in seconds.Methods inherited from class com.reduxrobotics.canand.CanandSettings
allSettingsReceived, checkBounds, getBool, getFilteredMap, getFloatAsDouble, getIntAsDouble, getMap, getMissingIndexes, isEmpty, setEphemeral, toString
-
Constructor Details
-
CanandcolorSettings
public CanandcolorSettings()Instantiates a newCanandcolorSettings
object that is "completely blank" -- holding no settings values at all. Settings are only populated into theCanandcolorSettings
object explicitly through the various setter methods -- runningcanandcolor.setSetting(new CanandcolorSettings())
would not update the device at all. To reset a device back to factory defaults, useCanandcolor.resetFactoryDefaults()
-
CanandcolorSettings
Instantiates a newCanandcolorSettings
object that copies its settings from the input instance.- Parameters:
toCopy
- the input settings object to copy
-
-
Method Details
-
fetchSettingsAddresses
protected int[] 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 10 status messages per second (period=0.1).- Parameters:
period
- the new period for status frames in seconds in range [0.001_s, 16.383_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 20 milliseconds (period=0.02). If 0 is passed in, proximity frames will be disabled and
Canandcolor.getProximity()
will not return new values.Note that if
setAlignProximityFramesToIntegrationPeriod(boolean)
is enabled, then this becomes the maximum period between two proximity frames, as proximity frames may get scheduled to broadcast early at the rate of theproximity integration period
instead to minimize latency; but setting this option to zero still disables all proximity frames.- 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 25 milliseconds (period=0.025). If 0 is passed in, color frames will be disabled and
Canandcolor.getColor()
and other color-reading methods will not return new values.Note that if
setAlignColorFramesToIntegrationPeriod(boolean)
is enabled, then this becomes the maximum period between two proximity frames, as proximity frames may get scheduled to broadcast early at the rate of thecolor integration period
instead to minimize latency; but setting this option to zero still disables all color frames.- 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 and
Canandcolor.getDigoutState()
andDigoutChannel.getValue()
/DigoutChannel.getStickyValue()
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
-
setLampLEDBrightness
Sets the brightness of the onboard lamp LED.The LED can also 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
-
setColorIntegrationPeriod
Sets the sampling/integration period for the color sensor.If
setAlignColorFramesToIntegrationPeriod(boolean)
is set, this also effectively determines the frame period of the color frame as well.- Parameters:
period
- theColorPeriod
to apply- Returns:
- the calling object, so these calls can be chained
- See Also:
-
setProximityIntegrationPeriod
Sets the integration period/multipulse configuration for the proximity sensor.If
setAlignProximityFramesToIntegrationPeriod(boolean)
is set, this also effectively determines the frame period of the proximity frame as well.- Parameters:
period
- theProximityPeriod
to apply- Returns:
- the calling object, so these calls can be chained
- See Also:
-
setDigoutPinConfig
Configures the physical GPIO pin associated with a given digital output channel.Note that these pin outputs are independent of the actual digital output channel's value, which is always continuously calcuated from digout slots.
These pins can be set into one of two or three modes:
- output disabled, by passing in
DigoutPinConfig.kDisabled
- output the value from the digout channel by passing in
DigoutPinConfig.kDigoutLogicActiveHigh
orDigoutPinConfig.kDigoutLogicActiveLow
- (only supported on
kDigout2
) a duty cycle (PWM) output of values from either the color or proximity sensor, by passing in aDataSource
) object
DigoutChannel.configureOutputPin(DigoutPinConfig)
for how to pass in aDigoutPinConfig
.- Parameters:
digout
- the channel to configure (eitherDigoutChannel.Index.kDigout1
orDigoutChannel.Index.kDigout2
). Note that channel 1 does not support duty cycle output.config
- aDigoutPinConfig
specifying how the digout should output if at all.- Returns:
- the calling object, so these calls can be chained
- output disabled, by passing in
-
setDigoutFrameTrigger
public CanandcolorSettings setDigoutFrameTrigger(DigoutChannel.Index digout, DigoutFrameTrigger trg) Sets digout message triggers which control if the Canandcolor should send digout messages on state change.These triggers can function even if digout output for the corresponding
DigoutChannel.Index
viasetDigoutPinConfig(DigoutChannel.Index, DigoutPinConfig)
is disabled or set to duty cycle output. This allows user code to quickly react to digout logic purely over CAN without needing direct GPIO digital I/O connections.- Parameters:
digout
- the digout to configure (eitherDigoutChannel.Index.kDigout1
orDigoutChannel.Index.kDigout2
)trg
- digout message trigger- Returns:
- the calling object, so these calls can be chained
- See Also:
-
setAlignProximityFramesToIntegrationPeriod
Sets whether or not to align the transmission of proximity frames to the integration period of the proximity sensor.This setting makes the Cannadcolor transmit proximity frames whenever it finishes processing new proximity data.
For example, if the proximity frame period is normally set to 200 ms, and the configured
ProximityPeriod
is 10 ms, passing true to this method would make the sensor emit a new proximity frame every 10 ms when the proximity sensor updates.- Parameters:
align
- true if to enable this feature- Returns:
- the calling object, so these calls can be chained
-
setAlignColorFramesToIntegrationPeriod
Sets whether or not to align the transmission of color frames to the integration period of the color sensor.This setting makes the Cannadcolor transmit color frames whenever it finishes processing new color data.
For example, if the color frame period is normally set to 200 ms, and the configured
ColorPeriod
is 25ms, passing true to this method would make the sensor emit a new color frame every 25ms when the color sensor updates.- Parameters:
align
- true if to enable this feature- Returns:
- the calling object, so these calls can be chained
-
getStatusFramePeriod
Gets the status frame period in seconds [0.001..65.535], or an emptyOptional
if the value has not been set on this object.- Returns:
- the status frame period in seconds [0.001..65.535], or an empty
Optional
if the value has not been set on this object.
-
getProximityFramePeriod
Gets the proximity frame period in seconds [0..65.535], or an emptyOptional
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 an empty
Optional
if the value has not been set on this object.
-
getColorFramePeriod
Gets the color frame period in seconds [0..65.535], or an emptyOptional
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 an empty
Optional
if the value has not been set on this object.
-
getDigoutFramePeriod
Gets the digout status frame period in seconds [0..65.535], or an emptyOptional
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 an empty
Optional
if the value has not been set on this object.
-
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 an empty
Optional
if unset
-
getColorIntegrationPeriod
Gets the sampling/integration period for the color sensor, if set on this object.- Returns:
ColorPeriod
enum orOptional.empty()
if unset
-
getProximityIntegrationPeriod
Gets the sampling/integration period for the proximity sensor, if set on this object.- Returns:
ProximityPeriod
orOptional.empty()
if unset
-
getDigoutPinConfig
Gets the output configuration for a physical GPIO pin associated with the given digout channel.- Parameters:
digout
- the digital output config to fetch- Returns:
- the
DigoutPinConfig
orOptional.empty()
if unset
-
getDigoutFrameTrigger
Gets the frame trigger configuration for a digital output.- Parameters:
digout
- the digital output config to fetch- Returns:
- the
DigoutFrameTrigger
orOptional.empty()
if unset
-
getAlignProximityFramesToIntegrationPeriod
Gets the config for proximity frame period alignment with integration period.- Returns:
- the config state (true if enabled) or
Optional.empty()
if unset - See Also:
-
getAlignColorFramesToIntegrationPeriod
Gets the config for color frame period alignment with integration period.- Returns:
- the config state (true if enabled) or
Optional.empty()
if unset - See Also:
-