Programming Overview

The central point of the Canandcolor in ReduxLib is the Canandcolor object. The Canandcolor object lets you read the device’s position, velocity, set and read settings, read faults, and more.

Constructor

Creating a Canandcolor object is simple. The one parameter you need is the CAN device ID assigned to the sensor, generally configured by Alchemist.

// Creates a Canandcolor object referencing a Canandcolor with CAN ID 0
Canandcolor canandcolor = new Canandcolor(0);

// Creates a Canandcolor object referencing a Canandcolor with CAN ID 3
Canandcolor canandcolor3 = new Canandcolor(3);
using namespace redux::sensors::canandcolor;
// Creates a Canandcolor object referencing a Canandcolor with CAN ID 0
Canandcolor canandcolor{0};

// Creates a Canandcolor object referencing a Canandcolor with CAN ID 3
Canandcolor canandcolor3{3};

Reading Proximity

Proximity in the Canandcolor is represented as a value in the range [0, 1] which increases as the sensed object approaches the sensor. This represents the intensity of reflected IR to the sensor, and will saturate to 1 if an object is too close to the sensor.

Why is proximity unitless?

The returned proximity value depends on the material as the reflectivity of IR will change how proximity relates to distance. This is because proximity is proportional to reflected IR light intensity, rather than distance directly. It is intended that users measure the proximity value in conditions they are going to use the sensor in, and then hard-code thresholds relevant to their application.

double proximity = canandcolor.getProximity();
double proximity = canandcolor.GetProximity();

Reading Color

Color in the Canandcolor is represented as individual values in the range [0, 1] which represents the intensity of that channel of color. For example, a pure red object will have a red color value close to 1, and blue/green color values close to 0. In addition, Canandcolor.ColorData contains helper functions to convert the sensed color to HSV, and to WPILib Color objects

// Assumed declaration of a Canandcolor with CAN ID 0
Canandcolor canandcolor{0};

//Get the raw RGB values from the sensor
double red = canandcolor.getRed();
double blue = canandcolor.getBlue();
double green = canandcolor.getGreen();

//White is also a supported value, which can be used as an analog for proximity at very close distances
double white = canandcolor.getWhite();

//Get a Canandcolor ColorData object from the sensor
Canandcolor.ColorData color = canandcolor.getColor();

//Get the HSV readings from the color object
double hue = color.hue();
double saturation = color.saturation();
double value = color.value();

//Convert the color to a WPILib color instance
Color wpiColor = color.toWpilibColor();

Party Mode

Party Mode is an identification tool that blinks the onboard LED different colors at a user specified integer speed level. The period of the LED change will be equal to (50 milliseconds * level). Setting this to 0 will turn off party mode

canandcolor.setPartyMode(level);
canandcolor.SetPartyMode(level);

Presence Detection

Presence Detection checks if the sensor has sent a message in the last 2 seconds (by default). This is a useful tool to ensure that the sensor has not disconnected from the CAN bus. ReduxLib will also automatically warn the driver station of possibly disconnected devices.

canandcolor.isConnected();
canandcolor.IsConnected();

Temperature

The temperature function reports the onboard temperature reading of the device. This should be kept within 0 and 70 degrees Celsius for normal operation.

canandcolor.getTemperature();
canandcolor.GetTemperature();

Reset To Factory Default

Danger

Resetting the sensor to factory default will wipe all settings. There is no way to undo this other then manually re-inputting all of your settings.

Resets the sensor to factory zero. CAN device IDs are preserved.

canandcolor.resetFactoryDefaults();
canandcolor.ResetFactoryDefaults();