Skip to content

Programming Your Canandgyro

The central point of the Boron Canandgyro in ReduxLib is the Canandgyro object. The Canandgyro object lets you read and write the device’s position, read and write settings, and read faults.

Creating a Canandgyro object is simple. The one parameter you need is the CAN ID assigned to the gyro, generally set in Alchemist.

// Creates a Canandgyro object referencing a Canandgyro with CAN ID 0
Canandgyro canandgyro = new Canandgyro(0);

The isCalibrating function can be used to check if the gyro is in calibration. This is useful if you want to re-zero your gyro after it finishes its calibration. This matches onboard LED - returning True with a yellow LED, and False as the LED turns green.

canandgyro.isCalibrating();
double heading = canandgyro.getYaw(); // gets the yaw (heading) in rotations
Rotation3d rotation = canandgyro.getRotation3d(); // gets yaw, pitch, and roll in one Rotation3d object
canandgyro.setYaw(0); // sets the yaw to 0 rotations. This does not affect pitch or roll.

Party Mode is an identification tool that blinks the onboard LED different colors. Setting this to 0 will turn off party mode.

// Starts party mode
canandgyro.setPartyMode(1);
// Stops party mode
canandgyro.setPartyMode(0);

Presence Detection checks if the gyro has sent a message in the last 2 seconds. This is a useful tool to ensure that the gyro has not been disconnected from the CAN bus.

canandgyro.isConnected();

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

canandgyro.getTemperature();

Resets the gyro to factory zero, keeping its current CAN ID. This is a blocking operation.

canandgyro.resetFactoryDefaults();