Programming Your Canandmag
The central point of the Helium Canandmag in ReduxLib is the Canandmag object. The Canandmag object lets you read the device’s position, velocity, set and read settings, read faults, and more.
Constructor
Section titled “Constructor”Creating a Canandmag object is simple. The one parameter you need is the CAN ID assigned to the encoder, generally set in Alchemist.
//Creates a Canandmag object referencing a Canandmag with CAN ID 0Canandmag canandmag = new Canandmag(0);
//Creates a Canandmag object referencing a Canandmag with CAN ID 3Canandmag canandmag3 = new Canandmag(3);//Put the following in the header file#include <redux/sensors/Canandmag.h>using namespace redux::sensors::canandmag;//Creates a Canandmag object referencing a Canandmag with CAN ID 0Canandmag canandmag{0};
//Creates a Canandmag object referencing a Canandmag with CAN ID 3Canandmag canandmag3{3};Magnet Check
Section titled “Magnet Check”The magnetInRange function can be used to check if the magnet is correctly set up and in range of the sensor.
This maintains parity with the onboard LED: when the magnet is not in range the LED will turn red, and when it is in range the LED will turn green.
canandmag.magnetInRange();canandmag.MagnetInRange();Party Mode
Section titled “Party Mode”Party Mode is an identification tool that blinks the onboard LED different colors at a user specified integer speed level. The period of the LED change will be equal to (50 milliseconds * level). Setting this to 0 will turn off party mode.
canandmag.setPartyMode(level);canandmag.SetPartyMode(level);Presence Detection
Section titled “Presence Detection”Presence Detection checks if the encoder has sent a message in the last 2 seconds. This is a useful tool to ensure that the encoder has not disconnected from the CAN bus.
canandmag.isPresent();canandmag.IsPresent();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.
canandmag.getTemperature();canandmag.GetTemperature();Reset To Factory Default
Section titled “Reset To Factory Default”Resets the encoder to factory zero. The clearZero boolean passed controls whether the absolute position offset should be cleared too; if set to true then this value will be reset to 0.
canandmag.resetFactoryDefaults(clearZero);canandmag.ResetFactoryDefaults(clearZero);