Programming Overview

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.

Constructor

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

Danger

Note that the Canandgyro only uses CAN 2.0B and will not work with CAN-FD.

// Creates a Canandgyro object referencing a Canandgyro with CAN ID 0
Canandgyro canandgyro = new Canandgyro(0);
//Put the following in the header file
#include <redux/sensors/Canandgyro.h>
using namespace redux::sensors::canandgyro;
// Creates a canandgyro object referencing a canandgyro with CAN ID 0
Canandgyro canandgyro{0};

Calibration Check

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();
canandgyro.IsCalibrating();

Heading

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.
units::angle::turn_t heading = canandgyro.GetYaw(); // gets the yaw in rotations
frc::Rotation3d rotation = canandgyro.GetRotation3d(); // gets yaw, pitch, and roll in one Rotation3d object
canandgyro.SetYaw(0_deg); // sets the yaw to 0 degrees. This does not affect pitch or roll

Party Mode

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);
// Starts party mode
canandgyro.SetPartyMode(1);
// Stops party mode
canandgyro.SetPartyMode(0);

Presence Detection

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();
canandgyro.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.

canandgyro.getTemperature();
canandgyro.GetTemperature();

Reset To Factory Default

Danger

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

In general, it is better practice to set the settings you want to be ensured to set a specific value than factory-resetting on every program start, as this reduces wear on the internal non-volatile flash memory.

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

canandgyro.resetFactoryDefaults();
canandgyro.ResetFactoryDefaults();