Programming Overview

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

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 0
Canandmag canandmag = new Canandmag(0);

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

//Creates a Canandmag object referencing a Canandmag with CAN ID 3
Canandmag canandmag3{3};

Magnet Check

The Magnet In Range 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

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

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

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

Danger

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

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);