Canandcolor Proximity Config

The CanandcolorProximityConfig object is used to reconfigure the Canandcolor’s proximity sensor.

Note

We extremely recommended to leave all of these at their defaults.

They either effect the device’s power draw (negligible on an FRC robot) or its accuracy at close sensing ranges (1 cm or less).

If you find that one of these settings makes a significant effect, let us know so it can be documented!

Creation

// Constructs a new proximity configuration with the factory default config.
CanandcolorProximityConfig config = new CanandcolorProximityConfig();
using namespace redux::sensors::canandcolor;
// Constructs a new proximity configuration with the factory default config.
CanandcolorProximityConfig config{};

Values are fetched and updated using Canandcolor.getSetting/Canandcolor.Settings.getProximityConfig and setSetting/setProximityConfig.

Saving To Device

When you are ready to send and save the settings to the device, set the config via CanandcolorSettings.

// Assumed declaration of a Canandcolor object with device ID 0
Canandcolor canandcolor = new Canandcolor(0);

// Fetch the existing configuration from the Canandcolor
Canandcolor.Settings settings = canandcolor.GetSettings();

// Get the current CanandcolorProximityConfig
CanandcolorProximityConfig config = settings.getProximityConfig();

// ...modify the proximity config...

// Set the modified proximity config on the settings object
settings.setProximityConfig(config);

// Write the new proximity settings to the Canandcolor
canandcolor.setSettings(settings, 0.500);

Sampling Period

The sampling period of the sensor is how frequently the Canandcolor samples the onboard proximity sensor. Theoretically, lowering this value will decrease the power draw of the sensor, but in practice the effects are nearly negligible on an FRC robot. For this reason, it is recommended to keep it on the default value of 10ms.

//Sets the sampling period to 10 milliseconds
config.setSamplingPeriod(CanandcolorProximityConfig.SamplingPeriod.k10ms);
//Sets the sampling period to 10 milliseconds
config.SetSamplingPeriod(CanandcolorProximityConfig::SamplingPeriod::k10ms);

Integration Period

The integration period of the sensor is how long it emits IR pulses for. The sensor operates by emitting a pulse of IR light and recording the reflected light. Longer pulses can read at further distances, but will saturate at close distances leading to worse read resolution. The default value of 400 microseconds results in great overall resolution, as shorter pulses are more optimized for very close (1-2 cm) ranging.

//Sets the integration period to 400 microseconds
config.setIntegrationPeriod(CanandcolorProximityConfig.IntegrationPeriod.k400us);
//Sets the integration period to 400 microseconds
config.SetIntegrationPeriod(CanandcolorProximityConfig::IntegrationPeriod::k400us);

LED Current

The LED current setting adjusts the current limit for the IR LED. Higher intensities allow for longer range sensing, but the tradeoff is that more current can saturate the sensor at very close (1-2 cm) distances. The default value of 20mA results in great overall resolution, as lower intensities are more optimized for very close (1-2 cm) ranging.

//Sets the IR LED current to 20 milliamps.
config.setLEDCurrent(CanandcolorProximityConfig.LEDCurrent.k20mA);
// Sets the IR LED current to 20 milliamps.
config.SetLEDCurrent(CanandcolorProximityConfig::LEDCurrent::k20mA);

Multiple Pulses

In order to improve long distance ranging, the sensor can output multiple pulses of the LED per range operation. This has the downside of potentially saturating the object at close (1-2 cm) distances, but massively improves long distance (>2cm) ranging. The default value of 8 pulses results in great overall resolution, as the lower numbers of pulses result in negligible changes in most applications.

// Sets the sensor to send 8 pulses per range operation
config.setMultiPulse(CanandcolorProximityConfig.MultiPulse.k8Pulse);
// Sets the sensor to send 8 pulses per range operation
config.setMultiPulse(CanandcolorProximityConfig::MultiPulse::k8Pulse);

High Gain Mode

Enabling high gain mode helps increase the sensitivity of the device by doubling the amplification gain from the IR sensor. This increases the dynamic range of the sensor, but also makes it easier to saturate the sensor at closer ranges. By default, this is disabled, since enabling this setting has negligible to negative effects in normal operation of the sensor. It is recommended to leave this setting disabled.

// Enable high gain mode.
config.setHighGainMode(true);
// Enable high gain mode.
config.SetHighGainMode(true);

Sunlight Cancellation

Turns on the built in sunlight cancellation system in the sensor. This can be useful if the device is being used outdoors, or in an environment where environmental IR from the sun could affect readings. By default, this is disabled.

// Enable sunlight cancellation mode
config.setSunlightCancellation(true);
// Enable Sunlight cancellation mode
config.SetSunlightCancellation(true);

Offset/Cancellation Value

Sets a fixed 12 bit value to subtract from the reading. This can be used to compensate for ambient IR in the environment. Accepted values range from 0 to 4095 inclusive.

// Sets the offset value to 0
config.setOffsetCancellationValue(0);
// Sets the offset value to 0
config.SetOffsetCancellationValue(0);