Shield Code 6.0
Loading...
Searching...
No Matches
IMU.cpp
Go to the documentation of this file.
1
7#include <Arduino.h>
8#include <Wire.h>
9#include <LIS3MDL.h>
10#include <LSM6.h>
11#include<IMU.hpp>
12
13//note - it's two byte data.
15void initIMU(LIS3MDL* mag, LSM6* gyro_acc){
16 Wire.begin();
17 mag->init();
18 gyro_acc->init();
19
20// Notes to help Leah and possibly you:
21 // CTRL5 controls temperature sensor, magnetic resolution selection, magnetic data rate collection, latch interrupt
22 // CTRL6 does magnetic full-scale selection
23 // CTRL7 does high-pass filter mode (acc), filtered acc data selection, temperature sensor only mode, manetic data low-power mode, and magnetic sensor mode selection (first two don't matter for magnetometer)
24
26 // Temp sensor enabled.
27 // OM = 11 (ultra-high resolution mode)
28 // DO = 111, 80 Hz ODR (output data rate)
29 // FAST_ODR = 1 (enables ODR higher than 80 hz)
30 // Self-tests disabled.
31 // 0xFE = 0b11111110
32 // Leah, 05.09.19
33 mag->writeReg(mag->CTRL_REG1, 0xFE);
34 // FS = 00 (+/- 4 gauss full scale). Ideal would be +/-1 gauss.
35 // 0x00 = 0b00000000
36 // Leah, 05.09.19
37 mag->writeReg(mag->CTRL_REG2, 0x00);
38 // LP = 0 (low power mode off)
39 // SIM = 0 (default mode for 4-wire interface. 1 for 3-wire interface)
40 // MD = 00 (continuous-conversion mode)
41 // 0x00 = 0b00000000
42 // Leah, 05.09.19
43 mag->writeReg(mag->CTRL_REG3, 0x00);
44 // Added to select Z-axis operative mode.
45 // OMZ = 11 (ultra-high performance mode)
46 // BLE = 0 (default. 1 for data Msb at lower address)
47 // 0x0C = 0b00001100
48 // Leah, 05.09.19
49 mag->writeReg(mag->CTRL_REG4, 0x0C);
50
51
53 // ODR_XL[3:0] = 0100, 104 Hz ODR (sample rate) high performance
54 // FS_XL: 10, full scale accelerometre range of +/- 4 g.
55 // BW_XL: 01, anti-aliasing filter at 200 Hz (old library value was 194 Hz)
56 // 0x49 = 0b01001001
57 // Leah, 05.09.19
58 gyro_acc->writeReg(gyro_acc->CTRL1_XL, 0x49);
59 // Zen_XL = Yen_XL = Xen_XL = 1 (all axes enabled)
60 // 0x38 = 0b00111000
61 // Probably not necessary but here just to be safe
62 // Leah, 05.09.19
63 gyro_acc->writeReg(gyro_acc->CTRL9_XL, 0x38);
64 // CTRL5_C controls self-test, but the default values for both acc. and gyro are 00, which disables self-test.
66 // ODR_G = 0100 (104 Hz)
67 // +/- 1000 dps full scale (FS_G = 10). If payloads are at 2.3 Hz ~ 828 dps, then +/- 1000 is ideal.
68 // FS_125 = 0 (disabled gyro full-scale at 125 dps)
69 // 0x48 = 0b01001000
70 // Leah, 05.09.19
71 gyro_acc->writeReg(gyro_acc->CTRL2_G, 0x48);
72 // For safety:
73 // Zen = Yen = Xen = 1 (all axes enabled)
74 // Everything else in register disabled
75 // 0x38 = 0b00111000
76 // Leah, 05.09.19
77 gyro_acc->writeReg(gyro_acc->CTRL10_C, 0x38);
78}
80void sampleIMU(LIS3MDL* mag, LSM6* imu, int16_t* data){
81 mag->read();
82 imu->read();
83 data[0]=mag->m.x;
84 data[1]=mag->m.y;
85 data[2]=mag->m.z;
86 data[3]=imu->a.x;
87 data[4]=imu->a.y;
88 data[5]=imu->a.z;
89 data[6]=imu->g.x;
90 data[7]=imu->g.y;
91 data[8]=imu->g.z;
92}
void initIMU(LIS3MDL *mag, LSM6 *gyro_acc)
Definition: IMU.cpp:15
void sampleIMU(LIS3MDL *mag, LSM6 *imu, int16_t *data)
Definition: IMU.cpp:80
Header file for the IMU library for Dartmouth's 317 Lab.