Low-Latency and Near-Zero Utilization¶
One of the greatest strengths of the Canandcolor is that you can program it to have near-zero CAN utilization, without sacrificing the ability to detect objects and colors at the full speed of the sensor (200Hz for proximity, 40Hz for color). This is accomplished by linking the digital output CAN frame to the state of the digital output in the sensor. When the digital output trips, a frame is sent, allowing only infrequent updates when the digital logic is not being tripped.
Running the Canandcolor in a near-zero utilization mode enables users to put many Canandcolors on a robot, such as for game piece indexing, without loading up the CANbus with unecessary traffic. Canandcolors can be configured to automatically send out frames when certain conditions are met, such when an object has been detected.
Note
Note that achieving “true” 0% utilization is not recommended, as the device may show up as disconnected from CANbus due to low traffic. It can also make debugging difficult, as CAN data will not update without any frames. However, getting under 0.1% utilization is easy, as we will see below.
Usage¶
Setting up near-zero utilization operation is accomplished by setting CAN frame periods very high, setting up a digital output, and aligning the edges of the digital output to the CAN frame transmission trigger.
//Create a Canandcolor object with CAN ID 0
Canandcolor canandcolor = new Canandcolor(0);
//Instantiate an empty settings object.
CanandcolorSettings settings = canandcolor.getSettings();
//Sets all frame periods to 0.5 seconds to achieve less than 0.1% total CANbus utilization
settings.setColorFramePeriod(0.5);
settings.setProximityFramePeriod(0.5);
settings.setDigoutFramePeriod(0.5);
settings.setStatusFramePeriod(0.5);
//As an example, we are going to update the proximity and color data very quickly
//In your application, you should set these appropriately depending on environmental conditions
//This is to show how we can detect at the full bandwidth of the sensor without high latency or can utilization
settings.setProximityIntegrationPeriod(ProximityPeriod.k5ms);
settings.setColorIntegrationPeriod(ColorPeriod.k25ms);
//Ensure that proximity and color frames are not sent out automatically when the sensor data updates
settings.setAlignProximityFramesToIntegrationPeriod(false);
settings.setAlignColorFramesToIntegrationPeriod(false);
//Sets digital output port 1 to use the digital logic system, setting it to normally closed
settings.setDigoutPinConfig(canandcolor.digout1().channelIndex(), DigoutPinConfig.kDigoutLogicNormallyClosed);
//Sets the digout frame trigger to send when the digout goes high or low
settings.setDigoutFrameTrigger(canandcolor.digout1().channelIndex(), DigoutFrameTrigger.kRisingAndFalling);
//Save settings to device
canandcolor.setSettings(settings);
//Configure the digout slot to trigger when proximity is between 0 and 0.5
canandcolor.digout1().configureSlots(new HSVDigoutConfig()
.setMaxProximity(0.5)
.setMinProximity(0)
);
//canandcolor.digout1().getValue() will be updated every time the sensor enters or exit a digout trigger state.
//Create a Canandcolor object with CAN ID 0
Canandcolor canandcolor{0};
//Instantiate an empty settings object.
CanandcolorSettings settings{};
//Sets all frame periods to 0.5 seconds to achieve less than 0.1% total CANbus utilization
settings.SetColorFramePeriod(0.5);
settings.SetProximityFramePeriod(0.5);
settings.SetDigoutFramePeriod(0.5);
settings.SetStatusFramePeriod(0.5);
//As an example, we are going to update the proximity and color data very quickly
//In your application, you should set these appropriately depending on environmental conditions
//This is to show how we can detect at the full bandwidth of the sensor without high latency or can utilization
settings.SetProximityIntegrationPeriod(ProximityPeriod::k5ms);
settings.SetColorIntegrationPeriod(ColorPeriod::k25ms);
//Ensure that proximity and color frames are not sent out automatically when the sensor updates
settings.SetAlignProximityFramesToIntegrationPeriod(false);
settings.SetAlignColorFramesToIntegrationPeriod(false);
//Sets digital output port 1 to use the digital logic system, setting it to normally closed
settings.SetDigoutPinConfig(canandcolor::Digout1()::ChannelIndex(), DigoutPinConfig::kDigoutLogicNormallyClosed);
//Sets the digout frame trigger to send when the digout goes high or low
settings.SetDigoutFrameTrigger(canandcolor::Digout1()::ChannelIndex(), DigoutFrameTrigger::kRisingAndFalling);
//Save settings to device
canandcolor.SetSettings(settings);
//Configure the digout slot to trigger when the proximity is between 0 and 0.5
canandcolor::Digout1()::ConfigureSlots(new HSVDigoutConfig()
::SetMaxProximity(0.5)
::SetMinProximity(0)
);
//canandcolor::Digout1()::GetValue() will be updated every time the sensor enters or exit a digout trigger state.
Don’t forget to set the integration periods for the proximity and color sensors! Higher integration time will yield more accuracy and range at the cost of speed and latency.