-
Notifications
You must be signed in to change notification settings - Fork 18
/
EVs_AbsoluteIMU.h
160 lines (134 loc) · 5.9 KB
/
EVs_AbsoluteIMU.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// EVs_AbsoluteIMU.h
//
// This is a class for reading from AbsoluteIMU, made by Mindsensors.
// See http://www.mindsensors.com/index.php?module=pagemaster&PAGE_user_op=view_page&PAGE_id=169
// Initial version: 2013-01-22 by Michael Giles
// Modified for EVShield: 2015-2-16 by Michael Giles
// Large parts of the code is ported from the NXC library for the device,
// written by Deepak Patil.Deepak Patil
/*
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef EVs_AbsoluteIMU_H
#define EVs_AbsoluteIMU_H
/*!
\def IMU_Command
Command register used for calibration and sensitivity changes
*/
#define IMU_Command 0x41
#include "EVShieldI2C.h"
/**
* \struct magnetic_field
Magnetic Field related data
*/
struct magnetic_field
{
short mx_h; /*!<Magnetic field HSB x-axis value generated by AbsoluteIMU */
short mx_l; /*!<Magnetic field LSB x-axis value generated by AbsoluteIMU */
short my_h; /*!<Magnetic field HSB y-axis value generated by AbsoluteIMU */
short my_l; /*!<Magnetic field LSB y-axis value generated by AbsoluteIMU */
short mz_h; /*!<Magnetic field HSB z-axis value generated by AbsoluteIMU */
short mz_l; /*!<Magnetic field LSB z-axis value generated by AbsoluteIMU */
int mx; /*!<Magnetic field x-axis value derived from HSB and LSB values generated by AbsoluteIMU */
int my; /*!<Magnetic field y-axis value derived from HSB and LSB values generated by AbsoluteIMU */
int mz; /*!<Magnetic field z-axis value derived from HSB and LSB values generated by AbsoluteIMU */
int error; /*!<Error generated in case of communication breakdown */
};
/**
* \struct gyro
Gyroscope related data
*/
struct gyro
{
short gx_h; /*!<Gyroscope HSB x-axis value generated by AbsoluteIMU */
short gx_l; /*!<Gyroscope LSB x-axis value generated by AbsoluteIMU */
short gy_h; /*!<Gyroscope HSB y-axis value generated by AbsoluteIMU */
short gy_l; /*!<Gyroscope LSB y-axis value generated by AbsoluteIMU */
short gz_h; /*!<Gyroscope HSB z-axis value generated by AbsoluteIMU */
short gz_l; /*!<Gyroscope LSB z-axis value generated by AbsoluteIMU */
int gx; /*!<Gyroscope x-axis value derived from HSB and LSB values generated by AbsoluteIMU */
int gy; /*!<Gyroscope y-axis value derived from HSB and LSB values generated by AbsoluteIMU */
int gz; /*!<Gyroscope z-axis value derived from HSB and LSB values generated by AbsoluteIMU */
int error; /*!<Error generated in case of communication breakdown */
};
/**
* \struct accl
Accelerometer and Tilt related data
*/
struct accl
{
short tx; /*!<Tilt x-axis value generated by AbsoluteIMU */
short ty; /*!<Tilt y-axis value generated by AbsoluteIMU */
short tz; /*!<Tilt z-axis value generated by AbsoluteIMU */
short ax_h; /*!<Accelerometer HSB x-axis value generated by AbsoluteIMU */
short ax_l; /*!<Accelerometer LSB x-axis value generated by AbsoluteIMU */
short ay_h; /*!<Accelerometer HSB y-axis value generated by AbsoluteIMU */
short ay_l; /*!<Accelerometer LSB y-axis value generated by AbsoluteIMU */
short az_h; /*!<Accelerometer HSB z-axis value generated by AbsoluteIMU */
short az_l; /*!<Accelerometer LSB z-axis value generated by AbsoluteIMU */
int ax; /*!<Accelerometer x-axis value derived from HSB and LSB values generated by AbsoluteIMU */
int ay; /*!<Accelerometer y-axis value derived from HSB and LSB values generated by AbsoluteIMU */
int az; /*!<Accelerometer z-axis value derived from HSB and LSB values generated by AbsoluteIMU */
int error; /*!<Error generated in case of communication breakdown */
};
/**
* \struct cmps
Compass related data
*/
struct cmps
{
int heading; /*!<Compass value derived from HSB and LSB values generated by AbsoluteIMU */
short heading_h; /*!<Compass HSB value generated by AbsoluteIMU */
short heading_l; /*!<Compass LSB value generated by AbsoluteIMU */
int error; /*!<Error generated in case of communication breakdown */
};
/**
@brief This class interfaces with AbsoluteIMU sensor attached to EVShield
*/
class EVs_AbsoluteIMU : public EVShieldI2C
{
public:
/** constructor for the AbsoluteIMU; may supply an optional custom i2c address */
EVs_AbsoluteIMU(uint8_t i2c_address = 0x22);
/** write a command byte at the command register of the device */
uint8_t issueCommand(char command);
/**
* Get the Gyro readings from the IMU
* @param gyro structure
* @return parameter is returned with values */
void readGyro(gyro & currGyro);
/**
* Get the Compass readings from the IMU
* @param cmps structure
* @return parameter is returned with values */
void readCompass(cmps & currCompass);
/**
* Get the Tilt and Accelerometer readings from the IMU
* @param accl structure
* @return parameter is returned with values */
void readAccelerometer(accl & currAccelerometer);
/**
* Get the Magnetometer readings from the IMU
* @param magnetic_field structure
* @return parameter is returned with values */
void readMagneticField(magnetic_field & currMagnetic_field);
/**
* Start Compass calibration
* @return boolean value for success or failure */
bool beginCompassCalibration();
/**
* End Compass calibration
* @return boolean value for success or failure */
bool endCompassCalibration();
};
#endif