Zumo32U4 library
Zumo32U4IMU.h
Go to the documentation of this file.
1// Copyright Pololu Corporation. For more information, see http://www.pololu.com/
2
5#pragma once
6
12#define LSM303D_ADDR 0b0011101
13#define L3GD20H_ADDR 0b1101011
14#define LSM6DS33_ADDR 0b1101011
15#define LIS3MDL_ADDR 0b0011110
23#define LSM303D_REG_STATUS_M 0x07
24#define LSM303D_REG_OUT_X_L_M 0x08
25#define LSM303D_REG_WHO_AM_I 0x0F
26#define LSM303D_REG_CTRL1 0x20
27#define LSM303D_REG_CTRL2 0x21
28#define LSM303D_REG_CTRL5 0x24
29#define LSM303D_REG_CTRL6 0x25
30#define LSM303D_REG_CTRL7 0x26
31#define LSM303D_REG_STATUS_A 0x27
32#define LSM303D_REG_OUT_X_L_A 0x28
33
34#define L3GD20H_REG_WHO_AM_I 0x0F
35#define L3GD20H_REG_CTRL1 0x20
36#define L3GD20H_REG_CTRL4 0x23
37#define L3GD20H_REG_STATUS 0x27
38#define L3GD20H_REG_OUT_X_L 0x28
39
40#define LSM6DS33_REG_WHO_AM_I 0x0F
41#define LSM6DS33_REG_CTRL1_XL 0x10
42#define LSM6DS33_REG_CTRL2_G 0x11
43#define LSM6DS33_REG_CTRL3_C 0x12
44#define LSM6DS33_REG_STATUS_REG 0x1E
45#define LSM6DS33_REG_OUTX_L_G 0x22
46#define LSM6DS33_REG_OUTX_L_XL 0x28
47
48#define LIS3MDL_REG_WHO_AM_I 0x0F
49#define LIS3MDL_REG_CTRL_REG1 0x20
50#define LIS3MDL_REG_CTRL_REG2 0x21
51#define LIS3MDL_REG_CTRL_REG3 0x22
52#define LIS3MDL_REG_CTRL_REG4 0x23
53#define LIS3MDL_REG_STATUS_REG 0x27
54#define LIS3MDL_REG_OUT_X_L 0x28
58enum class Zumo32U4IMUType : uint8_t {
60 Unknown,
65};
66
76{
77public:
78
81 template <typename T> struct vector
82 {
83 T x, y, z;
84 };
85
87 vector<int16_t> a = {0, 0, 0};
88
90 vector<int16_t> g = {0, 0, 0};
91
93 vector<int16_t> m = {0, 0, 0};
94
97 uint8_t getLastError() { return lastError; }
98
103 bool init();
104
110 Zumo32U4IMUType getType() { return type; }
111
114 void enableDefault();
115
118
121
125
131 void writeReg(uint8_t addr, uint8_t reg, uint8_t value);
132
139 uint8_t readReg(uint8_t addr, uint8_t reg);
140
143 void readAcc();
144
147 void readGyro();
148
151 void readMag();
152
156 void read();
157
162 bool accDataReady();
163
168 bool gyroDataReady();
169
174 bool magDataReady();
175
176private:
177
178 uint8_t lastError = 0;
180
181 int16_t testReg(uint8_t addr, uint8_t reg);
182 void readAxes16Bit(uint8_t addr, uint8_t firstReg, vector<int16_t> & v);
183};
Zumo32U4IMUType
The type of the inertial sensors.
Definition: Zumo32U4IMU.h:58
Interfaces with the inertial sensors on the Zumo 32U4.
Definition: Zumo32U4IMU.h:76
void readAcc()
Takes a reading from the accelerometer and makes the measurements available in a.
void readGyro()
Takes a reading from the gyro and makes the measurements available in g.
vector< int16_t > a
Raw accelerometer readings.
Definition: Zumo32U4IMU.h:87
vector< int16_t > m
Raw magnetometer readings.
Definition: Zumo32U4IMU.h:93
vector< int16_t > g
Raw gyro readings.
Definition: Zumo32U4IMU.h:90
bool accDataReady()
Indicates whether the accelerometer has new measurement data ready.
void configureForBalancing()
Configures the sensors with settings optimized for balancing.
bool gyroDataReady()
Indicates whether the gyro has new measurement data ready.
void readMag()
Takes a reading from the magnetometer and makes the measurements available in m.
uint8_t readReg(uint8_t addr, uint8_t reg)
Reads an 8-bit sensor register.
Zumo32U4IMUType getType()
Returns the type of the inertial sensors on the Zumo 32U4.
Definition: Zumo32U4IMU.h:110
void read()
Takes a reading from all three sensors (accelerometer, gyro, and magnetometer) and makes their measur...
void writeReg(uint8_t addr, uint8_t reg, uint8_t value)
Writes an 8-bit sensor register.
bool init()
Initializes the inertial sensors and detects their type.
Definition: Zumo32U4IMU.cpp:11
void enableDefault()
Enables all of the inertial sensors with a default configuration.
Definition: Zumo32U4IMU.cpp:31
uint8_t getLastError()
Returns 0 if the last I2C communication with the IMU was successful, or a non-zero status code if the...
Definition: Zumo32U4IMU.h:97
void configureForTurnSensing()
Configures the sensors with settings optimized for turn sensing.
bool magDataReady()
Indicates whether the magnetometer has new measurement data ready.
void configureForFaceUphill()
Configures the sensors with settings optimized for the FaceUphill example program.
Represents a 3-dimensional vector with x, y, and z components.
Definition: Zumo32U4IMU.h:82