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.
Constructor
Section titled “Constructor”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 0Canandgyro canandgyro = new Canandgyro(0);// Creates a canandgyro object referencing a canandgyro with CAN ID 0Canandgyro canandgyro{0};Calibration Check
Section titled “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
Section titled “Heading”double heading = canandgyro.getYaw(); // gets the yaw (heading) in rotationsRotation3d rotation = canandgyro.getRotation3d(); // gets yaw, pitch, and roll in one Rotation3d objectcanandgyro.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 rotationsfrc::Rotation3d rotation = canandgyro.GetRotation3d(); // gets yaw, pitch, and roll in one Rotation3d objectcanandgyro.SetYaw(0_deg); // sets the yaw to 0 degrees. This does not affect pitch or rollParty Mode
Section titled “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 modecanandgyro.setPartyMode(1);// Stops party modecanandgyro.setPartyMode(0);// Starts party modecanandgyro.SetPartyMode(1);// Stops party modecanandgyro.SetPartyMode(0);Presence Detection
Section titled “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
Section titled “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
Section titled “Reset To Factory Default”Resets the gyro to factory zero, keeping its current CAN ID. This is a blocking operation.
canandgyro.resetFactoryDefaults();canandgyro.ResetFactoryDefaults();