-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathEVs_AbsoluteIMU.cpp
90 lines (77 loc) · 2.65 KB
/
EVs_AbsoluteIMU.cpp
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
// EVs_AbsoluteIMU.cpp
//
// This is a class for controlling the AbsoluteIMU Sensor made by Mindsensors.
// Seehttp://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.
/*
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
*/
#include "EVs_AbsoluteIMU.h"
EVs_AbsoluteIMU::EVs_AbsoluteIMU(uint8_t i2c_address)
: EVShieldI2C(i2c_address)
{
}
uint8_t EVs_AbsoluteIMU::issueCommand(char command)
{
return writeByte(IMU_Command, (uint8_t) command);
}
void EVs_AbsoluteIMU::readGyro(gyro &currgyro)
{
char *b;
char str[200];
b = readString(0x53, 6);
currgyro.gx = readIntFromBuffer((uint8_t *)&b[0]);
currgyro.gy = readIntFromBuffer((uint8_t *)&b[2]);
currgyro.gz = readIntFromBuffer((uint8_t *)&b[4]);
currgyro.error = getErrorCode();
}
void EVs_AbsoluteIMU::readCompass(cmps &currcmps)
{
char str[200];
currcmps.heading = readInteger(0x4b);
currcmps.error = getErrorCode();
}
void EVs_AbsoluteIMU::readAccelerometer(accl &currAccl)
{
char *b;
char str[200];
currAccl.tx = readByte(0x42);
currAccl.ty = readByte(0x43);
currAccl.tz = readByte(0x44);
b = readString(0x45, 6);
currAccl.ax = readIntFromBuffer((uint8_t *)&b[0]);
currAccl.ay = readIntFromBuffer((uint8_t *)&b[2]);
currAccl.az = readIntFromBuffer((uint8_t *)&b[4]);
currAccl.error = getErrorCode();
}
void EVs_AbsoluteIMU::readMagneticField(magnetic_field &currmagnetic_field)
{
char *b;
char str[200];
b = readString(0x4d, 6);
currmagnetic_field.mx = readIntFromBuffer((uint8_t *)&b[0]);
currmagnetic_field.my = readIntFromBuffer((uint8_t *)&b[2]);
currmagnetic_field.mz = readIntFromBuffer((uint8_t *)&b[4]);
currmagnetic_field.error = getErrorCode();
}
bool EVs_AbsoluteIMU::beginCompassCalibration()
{
return issueCommand('C');
}
bool EVs_AbsoluteIMU::endCompassCalibration()
{
return issueCommand('c');
}