Canandcolor Digital Ports

The canandcolor’s digital ports are very flexible outputs that can be used in multiple modes. Primarily, they are grouped into two categories: PWM output mode and digital logic mode.

In PWM mode, selected values (such as proximity, red channel, HSV hue, etc) are transmitted via a PWM signal. In digital logic mode, a custom digital logic system can be used to trigger the port on and off.

PWM Mode

The digital output ports can be configured to output the Red, Blue, Green, White, Hue, Saturation, Value, or Proximity values over PWM. Disabling a value’s CAN packet rate will not disable its PWM output, so this can be used without the CAN output.

Important

This can only be done on Digital Output 2!

// A Canandcolor object with CAN ID 0
Canandcolor canandcolor = new Canandcolor(0);

// Instantiate an empty settings object
CanandcolorSettings settings = canandcolor.getSettings();

// Sets DIG2 to output proximity over PWM
settings.setDigoutPinConfig(DigoutChannel.Index.kDigout2, DataSource.kProximity);

// Apply the configuration to the device.
if (canandcolor.setSettings(settings)) {
    System.out.println("digout configuration success");
} else {
    System.out.println("digout configuration failure");
}
using namespace redux::sensors::canandcolor;
using namespace redux::sensors::canandcolor::digout;

// Get a canandcolor object with CAN ID 0
Canandcolor canandcolor{0};

// Instantiate an empty settings object.
CanandcolorSettings settings{};

// Sets DIG2 to output proximity over PWM
settings.SetDigoutOutputConfig(DigoutChannel::Index::kDigout2, DataSource::kProximity);

if (canandcolor.SetSettings(settings).IsEmpty()) {
    fmt::println("Settings set correctly!");
} else {
    fmt::println("Settings did not set correctly");
}

Digital Logic Mode

The canandcolor digital outputs can also be configured based off of programmable thresholds. Two versions, RGB and HSV configs are provided, and both can be programmed with distance thresholds as well. Here is an example of creating an RGB threshold.

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

//Fetch this canandcolor's settings
//This runs with a default timeout of 0.35 seconds
CanandcolorSettings settings = canandcolor.getSettings();

//Tells the device to emit a CAN packet immediately when the digout state changes
settings.setDigoutFrameTrigger(DigoutChannel.Index.kDigout1, DigoutFrameTrigger.kRisingAndFalling);

//Configures the output pin to be active high. This means the pin will be ON when the digital output is TRUE
canandcolor.digout1().configureOutputPin(DigoutPinConfig.kDigoutLogicActiveHigh);

//Create an HSV threshold on digital output 1
//This will trigger if the following conditions are met:
//Proximity is less then 0.15 for more then 0.01 seconds
//Hue is between 0.5 and 0.7 for 0.01
//This detects light blue items
color.digout1().configureSlots(new HSVDigoutConfig()
    .setMaxProximity(0.15)
    .setProximityInRangeFor(0.01)
    .setMinHue(0.5)
    .setMaxHue(0.7)
    .setColorInRangeFor(0.01)
);

//Save settings to device
canandcolor.setSettings(settings, 0.050);
//Coming soon