MatrixMiniR4 1.1.9
Matrix Mini R4 Arduino Library API Documentation
Loading...
Searching...
No Matches
MiniR4Motion.h
Go to the documentation of this file.
1
6#ifndef MINIR4MOTION_H
7#define MINIR4MOTION_H
8
9#include "MMLower.h"
10#include <EEPROM.h>
11
21{
22public:
24
25 enum class AxisType
26 {
33 };
34
35 bool begin(void)
36 {
37 bool result = applyIMUCalData();
38 return (result);
39 }
40
47 double getGyro(AxisType axis)
48 {
49 double x = 0, y = 0, z = 0;
50 mmL.GetIMUGyro(x, y, z);
51
52 if (axis == AxisType::X)
53 return x;
54 else if (axis == AxisType::Y)
55 return y;
56 else if (axis == AxisType::Z)
57 return z;
58 else
59 return 0;
60 }
61
68 double getAccel(AxisType axis)
69 {
70 double x = 0, y = 0, z = 0;
71 mmL.GetIMUAcc(x, y, z);
72
73 if (axis == AxisType::X)
74 return x;
75 else if (axis == AxisType::Y)
76 return y;
77 else if (axis == AxisType::Z)
78 return z;
79 else
80 return 0;
81 }
82
91 double getAccelRaw(AxisType axis)
92 {
93 float accdataCX[3];
94 bool result = getIMU_acc_real(accdataCX);
95
96 if (!result)
97 return 0;
98
99 if (axis == AxisType::X)
100 return accdataCX[0];
101 else if (axis == AxisType::Y)
102 return accdataCX[1];
103 else if (axis == AxisType::Z)
104 return accdataCX[2];
105 else
106 return 0;
107 }
108
115 double getEuler(AxisType axis)
116 {
117 double roll = 0, pitch = 0, yaw = 0;
118 mmL.GetIMUEuler(roll, pitch, yaw);
119
120 if (axis == AxisType::Roll)
121 return roll;
122 else if (axis == AxisType::Pitch)
123 return pitch;
124 else if (axis == AxisType::Yaw)
125 return yaw;
126 else
127 return -999.0f;
128 }
129
136 uint8_t getAccel_All(double * dataX)
137 {
138 double x = 0, y = 0, z = 0;
139 mmL.GetIMUAcc(x, y, z);
140
141 dataX[0] = x;
142 dataX[1] = y;
143 dataX[2] = z;
144
145 return 0;
146 }
147
154 uint8_t getGyro_All(double * dataX)
155 {
156 double x = 0, y = 0, z = 0;
157 mmL.GetIMUGyro(x, y, z);
158 dataX[0] = x;
159 dataX[1] = y;
160 dataX[2] = z;
161
162 return 0;
163 }
164
171 uint8_t getEuler_All(double * dataX)
172 {
173 double roll = 0, pitch = 0, yaw = 0;
174 mmL.GetIMUEuler(roll, pitch, yaw);
175
176 dataX[0] = roll;
177 dataX[1] = pitch;
178 dataX[2] = yaw;
179
180 return 0;
181 }
182
194 bool saveIMUCalData(float face1, float face2, float face3, float face4, float face5, float face6)
195 {
196 float accdata[6] = {face1, face2, face3, face4, face5, face6};
197
198 int Address_F = 50;
199 EEPROM.put(Address_F, accdata[0]);
200 Address_F += sizeof(float);
201 EEPROM.put(Address_F, accdata[1]);
202 Address_F += sizeof(float);
203 EEPROM.put(Address_F, accdata[2]);
204 Address_F += sizeof(float);
205 EEPROM.put(Address_F, accdata[3]);
206 Address_F += sizeof(float);
207 EEPROM.put(Address_F, accdata[4]);
208 Address_F += sizeof(float);
209 EEPROM.put(Address_F, accdata[5]);
210
211 MMLower::RESULT result = mmL.SetIMU_Calib_data(accdata);
212 return (result == MMLower::RESULT::OK);
213 }
214
223 {
224 float accdata[6];
225
226 int Address_F = 50;
227 EEPROM.get(Address_F, accdata[0]);
228 Address_F += sizeof(float);
229 EEPROM.get(Address_F, accdata[1]);
230 Address_F += sizeof(float);
231 EEPROM.get(Address_F, accdata[2]);
232 Address_F += sizeof(float);
233 EEPROM.get(Address_F, accdata[3]);
234 Address_F += sizeof(float);
235 EEPROM.get(Address_F, accdata[4]);
236 Address_F += sizeof(float);
237 EEPROM.get(Address_F, accdata[5]);
238
239 MMLower::RESULT result = mmL.SetIMU_Calib_data(accdata);
240 return (result == MMLower::RESULT::OK);
241 }
242
248 bool getAllSpeed(int32_t * Speed_value)
249 {
250 int32_t Speed_En[4];
251 MMLower::RESULT result = mmL.GetALLEncoderSpeed(Speed_En);
252 delay(1);
253 result = mmL.GetALLEncoderSpeed(Speed_En);
254 Speed_value[0] = Speed_En[0];
255 Speed_value[1] = Speed_En[1];
256 Speed_value[2] = Speed_En[2];
257 Speed_value[3] = Speed_En[3];
258
259 return (result == MMLower::RESULT::OK);
260 }
261
271 bool getIMU_acc_real(float * accdataCX)
272 {
273 float Speed_En[4];
274 MMLower::RESULT result = mmL.Get_IMU_nancalib_acc(Speed_En);
275 delay(2);
276 result = mmL.Get_IMU_nancalib_acc(Speed_En);
277
278 accdataCX[0] = Speed_En[0];
279 accdataCX[1] = Speed_En[1];
280 accdataCX[2] = Speed_En[2];
281
282 return (result == MMLower::RESULT::OK);
283 }
284
290 bool resetIMUValues(void) { return (mmL.SetIMUToZero() == MMLower::RESULT::OK); }
291
292private:
293};
294
295#endif // MINIR4MOTION_H
MMLower mmL(8, 9, 57600)
Handling the Lower MCU (STM32) communication.
bool applyIMUCalData(void)
Load and send IMU calibration data from EEPROM (R4 EEPROM 0x32 - 0x49)
bool getIMU_acc_real(float *accdataCX)
Gets the raw (uncalibrated) IMU accelerometer data.
bool saveIMUCalData(float face1, float face2, float face3, float face4, float face5, float face6)
Save IMU calibration data with 6 individual parameters (R4 EEPROM 0x32 - 0x49)
bool resetIMUValues(void)
Resets the IMU values to zero.
double getAccel(AxisType axis)
Gets the accelerometer value for a specified axis.
uint8_t getGyro_All(double *dataX)
Gets the gyro value for a specified axis.
double getGyro(AxisType axis)
Gets the gyro value for a specified axis.
double getAccelRaw(AxisType axis)
Gets the raw (uncalibrated) IMU accelerometer data for a specific axis.
uint8_t getEuler_All(double *dataX)
Gets the Euler angle for a specified axis.
bool begin(void)
uint8_t getAccel_All(double *dataX)
Gets the accelerometer value for a specified axis.
double getEuler(AxisType axis)
Gets the Euler angle for a specified axis.
bool getAllSpeed(int32_t *Speed_value)
Gets the current encoder Speed value. (RPS)