WebbotLib AVR library
WebbotLib It just does it
C++documentationCdocumentation

Compass

Supports compasses.
Remember that little magnetic gadget you had as kid? Yes - a compass measures a bearing in degrees. ie hold it flat and spin around and the bearing should change all the way from 0 through to 359 and then back to 0 when you are back in your start position.
Some device provide additional information like 'roll' and 'pitch'. Roll is like twisting your hand when you are locking or unlocking a door, and 'pitch' is like raising or lowering your 'arm'.
All reading from this library are in degree but devices that don't support roll and pitch will return zero for those values.
These devices either use one ADC pin for each reading, or provide an I2C interface but you will need to check the individual data sheets to see what power supply they need.
Since all of the devices have been implemented in the same way then it means that you can swap one device for another by only changing the #include and the MAKE command used to create the device.
So here is the generic way to work with a <DEVICE> of a given <MAKE> and <MODEL>:-
// Include the relevant sensor file
#include "Sensors/Acceleration/<MAKE>/<MODEL>.h"
// Create the device
<DEVICE> myCompass = MAKE_<DEVICE>(i2cAddress or ADC pins);
In your appInitHardware you should initialise the device:-
compassInit(myCompass);
Then in your main loop you can read the sensor using:-
compassRead(myCompass);
Each value can then be read independently into a variable of type 'COMPASS_TYPE':-
COMPASS_TYPE bearing = myCompass.compass.bearingDegrees;
COMPASS_TYPE roll = myCompass.compass.rollDegrees;
COMPASS_TYPE pitch = myCompass.compass.pitchDegrees;
Or dumped to the current rprintf destination using:-
compassDump(myCompass);

File

Valid XHTML 1.0 Transitional