Class HSVDigoutConfig

java.lang.Object
com.reduxrobotics.sensors.canandcolor.DigoutConfig
com.reduxrobotics.sensors.canandcolor.HSVDigoutConfig

public final class HSVDigoutConfig extends DigoutConfig
A digital output configuration that uses thresholds in the HSV color space to match color readings.

Basic usage example:

 Canandcolor color = new Canandcolor(0);
 // Check if the an object is close and the color sensor is seeing blue for at least 10 milliseconds,
 color.digout1().configureSlots(new HSVDigoutConfig()
   .setMaxProximity(0.15)
   .setProximityInRangeFor(0.01)
   .setMinHue(0.5)
   .setMaxHue(0.7)
   .setColorInRangeFor(0.01)
 );
 // Instantly send CAN digout frames when the above condition changes at all.
 color.digout1().configureFrameTrigger(DigoutFrameTrigger.kRisingAndFalling);
 // Configure the DIG-1 GPIO pin to also output the condition
 color.digout1().configureOutputPin(DigoutPinConfig.kDigoutLogicActiveHigh);
 // Check value over CAN
 color.digout1().getValue();
 

If the minHue is larger than the maxHue, then (minHue <= hue <= 1.0) || (0.0 <= hue <= maxHue) is instead evaluated, which can be used to screen for red hues. E.g.

 Canandcolor color = new Canandcolor(0);
 // Check for red values:
 color.digout1().configureSlots(new HSVDigoutConfig()
   .setMinHue(0.8)
   .setMaxHue(0.2)
   .setColorInRangeFor(0.01)
 );
 

will check for hue values from [0.8..1.0] and [0.0..0.2], allowing for proper handling of the wraparound.

See Also:
  • Constructor Details

    • HSVDigoutConfig

      public HSVDigoutConfig()
      Default constructor.
  • Method Details

    • setMinProximity

      public HSVDigoutConfig setMinProximity(double thresh)
      Sets the value that the proximity reading has to be greater than or equal to for the digout to be true.

      If not specified, this value is 0.0

      Parameters:
      thresh - proximity threshold
      Returns:
      calling object
    • setMaxProximity

      public HSVDigoutConfig setMaxProximity(double thresh)
      Sets the value that the proximity reading has to be less than or equal to for the digout to be true.

      If not specified, this value is 1.0

      Parameters:
      thresh - proximity threshold
      Returns:
      calling object
    • setProximityInRangeFor

      public HSVDigoutConfig setProximityInRangeFor(double seconds)
      Sets the minimum time that the proximity reading has to match the upper and lower thresholds in order for the digout to be true.

      This threshold has millisecond resolution, but the units are still seconds.

      This threshold has millisecond resolution, but the units are still seconds.

      Parameters:
      seconds - The minimum number of seconds. The default value is 0 (zero time required)
      Returns:
      calling object
    • setMinHue

      public HSVDigoutConfig setMinHue(double thresh)
      Sets the value that the HSV hue reading has to be greater than or equal to for the digout to be true.

      If not specified, this value is 0.0

      If the min hue threshold is larger than the max hue threshold, the sensor will evaluate

       minHue <= hue OR hue <= maxHue 
       
      instead of the usual
       minHue <= hue AND hue <= maxHue 
       

      which is useful when trying to detect red objects as one could set the min hue to 0.9 and the max hue to 0.1 but still get correct results across the wraparound.

      Parameters:
      thresh - color value threshold
      Returns:
      calling object
    • setMaxHue

      public HSVDigoutConfig setMaxHue(double thresh)
      Sets the value that the HSV hue reading has to be greater than or equal to for the digout to be true.

      If not specified, this value is 1.0

      If the min hue threshold is larger than the max hue threshold, the sensor will evaluate

       minHue <= hue OR hue <= maxHue 
       
      instead of the usual
       minHue <= hue AND hue <= maxHue 
       

      which is useful when trying to detect red objects as one could set the min hue to 0.9 and the max hue to 0.1 but still get correct results across the wraparound.

      Parameters:
      thresh - color value threshold
      Returns:
      calling object
    • setMinSaturation

      public HSVDigoutConfig setMinSaturation(double thresh)
      Sets the value that the HSV saturation reading has to be greater than or equal to for the digout to be true.

      If not specified, this value is 0.0

      Parameters:
      thresh - color value threshold
      Returns:
      calling object
    • setMaxSaturation

      public HSVDigoutConfig setMaxSaturation(double thresh)
      Sets the value that the HSV saturation reading has to be greater than or equal to for the digout to be true.

      If not specified, this value is 1.0

      Parameters:
      thresh - color value threshold
      Returns:
      calling object
    • setMinValue

      public HSVDigoutConfig setMinValue(double thresh)
      Sets the value that the HSV value reading has to be greater than or equal to for the digout to be true.

      If not specified, this value is 0.0

      Parameters:
      thresh - color value threshold
      Returns:
      calling object
    • setMaxValue

      public HSVDigoutConfig setMaxValue(double thresh)
      Sets the value that the HSV value reading has to be greater than or equal to for the digout to be true.

      If not specified, this value is 1.0

      Parameters:
      thresh - color value threshold
      Returns:
      calling object
    • setColorInRangeFor

      public HSVDigoutConfig setColorInRangeFor(double seconds)
      Sets the minimum time that the color readings have to match the upper and lower HSV thresholds in order for the digout to be true.

      This can be used to "debounce" readings by requiring the color to match the thresholds for multiple readings.

      This threshold has millisecond resolution, but the units are still seconds.

      Parameters:
      seconds - The minimum number of seconds. The default value is 0 (zero time required)
      Returns:
      calling object