Class Canandcolor.Settings

java.lang.Object
com.reduxrobotics.canand.CanandSettings
com.reduxrobotics.sensors.canandcolor.Canandcolor.Settings
Enclosing class:
Canandcolor

public static class Canandcolor.Settings extends CanandSettings
The settings class for the 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());
 }
 
  • Constructor Details

    • Settings

      public Settings()
      Instantiates a new Canandcolor.Settings object that is "completely blank" -- holding no settings values at all. Settings are only populated into the Canandcolor.Settings object explicitly through the various setter methods -- running canandcolor.setSetting(new Canandcolor.Settings()) would not update the device at all. To reset a device back to factory defaults, use Canandcolor.resetFactoryDefaults(double)
    • Settings

      public Settings(Canandcolor.Settings toCopy)
      Instantiates a new Canandcolor.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 class CanandSettings
      Returns:
      settings addresses.
    • setStatusFramePeriod

      public Canandcolor.Settings setStatusFramePeriod(double period)
      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

      public Canandcolor.Settings setProximityFramePeriod(double period)
      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 and Canandcolor.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

      public Canandcolor.Settings setColorFramePeriod(double period)
      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 and Canandcolor.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

      public Canandcolor.Settings setDigoutFramePeriod(double period)
      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() 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

      public Canandcolor.Settings setFramePeriodLatencyAdjustment(boolean adjust)
      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

      public Canandcolor.Settings setLampLED(boolean lamp)
      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

      public Canandcolor.Settings setLampLEDBrightness(double brightness)
      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

      public Canandcolor.Settings setProximityConfig(CanandcolorProximityConfig cfg)
      Sets fine-tuned settings for the proximity sensor through values in a CanandcolorProximityConfig object.
      Parameters:
      cfg - the configruation object to apply setings from
      Returns:
      the calling object, so these calls can be chained
    • setColorConfig

      public Canandcolor.Settings setColorConfig(Canandcolor.ColorPeriod period)
      Sets the sampling/integration period for the color sensor.
      Parameters:
      period - the Canandcolor.ColorPeriod to apply
      Returns:
      the calling object, so these calls can be chained
    • setDigoutOutputMode

      public Canandcolor.Settings setDigoutOutputMode(Canandcolor.Digout digout, DigoutMode config)
      Sets the output mode of a digital output pad. Digout pins can be set into one of three modes:
      Parameters:
      digout - the digout to configure (either Canandcolor.Digout.kDigout1 or Canandcolor.Digout.kDigout2)
      config - a DigoutMode specifying how the digout should output if at all.
      Returns:
      the calling object, so these calls can be chained
      See Also:
    • getStatusFramePeriod

      public Double 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

      public Double 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

      public Double 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

      public Double 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

      public Boolean 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

      public Boolean 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

      public Double 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

      public CanandcolorProximityConfig 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

      public Canandcolor.ColorPeriod getColorConfig()
      Gets the device's sampling/integration period for the color sensor, if set.
      Returns:
      Canandcolor.ColorPeriod enum or null if unset
    • getDigoutOutputMode

      public DigoutMode getDigoutOutputMode(Canandcolor.Digout digout)
      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