Programming Your Canandcolor
The central point of the Canandcolor in ReduxLib is the Canandcolor object. The Canandcolor object lets you read the detected color, measured proximity, set and read settings, read faults, and more.
Constructor
Section titled “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 0Canandcolor canandcolor = new Canandcolor(0);
// Creates a Canandcolor object referencing a Canandcolor with CAN ID 3Canandcolor canandcolor3 = new Canandcolor(3);using namespace redux::sensors::canandcolor;// Creates a Canandcolor object referencing a Canandcolor with CAN ID 0Canandcolor canandcolor{0};
// Creates a Canandcolor object referencing a Canandcolor with CAN ID 3Canandcolor canandcolor3{3};Reading Proximity
Section titled “Reading Proximity”Proximity in the Canandcolor is represented as a value in the range [0, 1] which decreases 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.
double proximity = canandcolor.getProximity();double proximity = canandcolor.GetProximity();Reading Color
Section titled “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 light will have a red color value close to 1, and blue/green color values close to 0.
In addition, ColorData contains helper functions to convert the sensed color to HSV, and to WPILib Color objects.
For most applications, users will want to use the HSV functions instead of RGB, as HSV is much easier to tune and senses
color more independent of ambient conditions and brightness.
//Get the raw RGB values from the sensordouble red = canandcolor.getRed();double blue = canandcolor.getBlue();double green = canandcolor.getGreen();
//Get the HSV readings from the color objectdouble hue = canandcolor.getHSVHue();double saturation = canandcolor.getHSVSaturation();double value = canandcolor.getHSVValue();
//Get a Canandcolor ColorData object from the sensorColorData color = canandcolor.getColor();
//Convert the color to a WPILib color instanceColor wpiColor = color.toWpilibColor();using namespace redux::sensors::canandcolor;
//Get the raw RGB values from the sensordouble 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 distancesdouble white = canandcolor.getWhite();
//Get the HSV readings from the color objectdouble hue = canandcolor.Hue();double saturation = canandcolor.Saturation();double value = canandcolor.Value();
//Get a CanandcolorColorData object from the sensorCanandcolorColorData color = canandcolor.getColor();
//Convert the color to a WPILib color instancefrc::Color wpiColor = color.ToWpilibColor();Presence Detection
Section titled “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
Section titled “Temperature”The temperature function reports the onboard temperature reading of the device. This should be kept within -5 and 45 degrees Celsius for normal operation.
canandcolor.getTemperature();canandcolor.GetTemperature();Reset To Factory Default
Section titled “Reset To Factory Default”Resets the sensor to factory defaults. CAN device IDs are preserved.
canandcolor.resetFactoryDefaults();canandcolor.ResetFactoryDefaults();