Browse Source

mpu9150: added new sensor (acceleromter, gyro and compass)

Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
Kiveisha Yevgeniy 10 years ago
parent
commit
8d25ecacdd

+ 3
- 0
examples/CMakeLists.txt View File

@@ -20,6 +20,7 @@ add_executable (gy65-example gy65.cxx)
20 20
 add_executable (stepmotor-example stepmotor.cxx)
21 21
 add_executable (pulsensor-example pulsensor.cxx)
22 22
 add_executable (mic-example mic-example.cxx)
23
+add_executable (mpu9150-example mpu9150-example.cxx)
23 24
 
24 25
 include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
25 26
 include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@@ -38,6 +39,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/gy65)
38 39
 include_directories (${PROJECT_SOURCE_DIR}/src/stepmotor)
39 40
 include_directories (${PROJECT_SOURCE_DIR}/src/pulsensor)
40 41
 include_directories (${PROJECT_SOURCE_DIR}/src/mic)
42
+include_directories (${PROJECT_SOURCE_DIR}/src/mpu9150)
41 43
 
42 44
 target_link_libraries (compass hmc5883l ${CMAKE_THREAD_LIBS_INIT})
43 45
 target_link_libraries (groveled grove ${CMAKE_THREAD_LIBS_INIT})
@@ -61,3 +63,4 @@ target_link_libraries (gy65-example gy65 ${CMAKE_THREAD_LIBS_INIT})
61 63
 target_link_libraries (stepmotor-example stepmotor ${CMAKE_THREAD_LIBS_INIT})
62 64
 target_link_libraries (pulsensor-example pulsensor ${CMAKE_THREAD_LIBS_INIT})
63 65
 target_link_libraries (mic-example mic ${CMAKE_THREAD_LIBS_INIT})
66
+target_link_libraries (mpu9150-example mpu9150 ${CMAKE_THREAD_LIBS_INIT})

+ 59
- 0
examples/mpu9150-example.cxx View File

@@ -0,0 +1,59 @@
1
+/*
2
+ * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3
+ * Copyright (c) 2014 Intel Corporation.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files (the
7
+ * "Software"), to deal in the Software without restriction, including
8
+ * without limitation the rights to use, copy, modify, merge, publish,
9
+ * distribute, sublicense, and/or sell copies of the Software, and to
10
+ * permit persons to whom the Software is furnished to do so, subject to
11
+ * the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+
25
+#include <unistd.h>
26
+#include <iostream>
27
+#include "mpu9150.h"
28
+
29
+int
30
+main(int argc, char **argv)
31
+{
32
+    //! [Interesting]
33
+    upm::Vector3D data;
34
+    upm::MPU9150 *sensor = new upm::MPU9150(0, ADDR);
35
+    sensor->getData ();
36
+    sensor->getAcceleromter (&data);
37
+    std::cout << "*************************************************" << std::endl;
38
+    std::cout << "DEVICE ID (" << (int) sensor->getDeviceID () << ")" << std::endl;
39
+    std::cout << "*************************************************" << std::endl;
40
+    std::cout << "ACCELEROMETER :: X (" << data.axisX << ")" << " Y (" << data.axisY << ")"
41
+                << " Z (" << data.axisZ << ")" << std::endl;
42
+
43
+    sensor->getGyro (&data);
44
+    std::cout << "GYRO :: X (" << data.axisX << ")" << " Y (" << data.axisY << ")"
45
+                << " Z (" << data.axisZ << ")" << std::endl;
46
+
47
+    sensor->getMagnometer (&data);
48
+    std::cout << "MAGNOMETER :: X (" << data.axisX << ")" << " Y (" << data.axisY << ")"
49
+                << " Z (" << data.axisZ << ")" << std::endl;
50
+    std::cout << "TEMPERATURE (" << sensor->getTemperature () << ")" << std::endl;
51
+    std::cout << "*************************************************" << std::endl;
52
+    //! [Interesting]
53
+
54
+    std::cout << "exiting application" << std::endl;
55
+
56
+    delete sensor;
57
+
58
+    return 0;
59
+}

+ 5
- 0
src/mpu9150/CMakeLists.txt View File

@@ -0,0 +1,5 @@
1
+set (libname "mpu9150")
2
+set (libdescription "giro, acceleromter and magnometer sensor based on mpu9150")
3
+set (module_src ${libname}.cxx)
4
+set (module_h ${libname}.h)
5
+upm_module_init()

+ 7
- 0
src/mpu9150/jsupm_mpu9150.i View File

@@ -0,0 +1,7 @@
1
+%module jsupm_mpu9150
2
+
3
+%{
4
+    #include "mpu9150.h"
5
+%}
6
+
7
+%include "mpu9150.h"

+ 226
- 0
src/mpu9150/mpu9150.cxx View File

@@ -0,0 +1,226 @@
1
+/*
2
+ * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3
+ * Copyright (c) 2014 Intel Corporation.
4
+ *
5
+ * Based on InvenSense MPU-6050 register map document rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)
6
+ * 8/24/2011 by Jeff Rowberg <jeff@rowberg.net>
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining
9
+ * a copy of this software and associated documentation files (the
10
+ * "Software"), to deal in the Software without restriction, including
11
+ * without limitation the rights to use, copy, modify, merge, publish,
12
+ * distribute, sublicense, and/or sell copies of the Software, and to
13
+ * permit persons to whom the Software is furnished to do so, subject to
14
+ * the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be
17
+ * included in all copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ */
27
+
28
+#include <iostream>
29
+#include <unistd.h>
30
+#include <stdlib.h>
31
+
32
+#include "mpu9150.h"
33
+
34
+using namespace upm;
35
+
36
+MPU9150::MPU9150 (int bus, int devAddr) {
37
+    m_name = "MPU9150";
38
+
39
+    m_i2cAddr = devAddr;
40
+    m_bus = bus;
41
+
42
+    m_i2Ctx = maa_i2c_init(m_bus);
43
+
44
+    maa_result_t ret = maa_i2c_address(m_i2Ctx, m_i2cAddr);
45
+    if (ret != MAA_SUCCESS) {
46
+        fprintf(stderr, "Messed up i2c bus\n");
47
+    }
48
+
49
+    initSensor ();
50
+}
51
+
52
+MPU9150::~MPU9150() {
53
+    maa_i2c_stop(m_i2Ctx);
54
+}
55
+
56
+maa_result_t
57
+MPU9150::initSensor () {
58
+    uint8_t regData = 0x0;
59
+
60
+    // setClockSource
61
+    updateRegBits ( MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CLKSEL_BIT,
62
+                    MPU6050_PWR1_CLKSEL_LENGTH, MPU6050_CLOCK_PLL_XGYRO);
63
+    // setFullScaleGyroRange
64
+    updateRegBits ( MPU6050_RA_GYRO_CONFIG, MPU6050_GCONFIG_FS_SEL_BIT,
65
+                    MPU6050_GCONFIG_FS_SEL_LENGTH, MPU6050_GYRO_FS_250);
66
+    // setFullScaleAccelRange
67
+    updateRegBits ( MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_AFS_SEL_BIT,
68
+                    MPU6050_ACONFIG_AFS_SEL_LENGTH, MPU6050_ACCEL_FS_2);
69
+    // setSleepEnabled
70
+    i2cReadReg_N (MPU6050_RA_PWR_MGMT_1, 0x1, &regData);
71
+    regData &= ~(1 << MPU6050_PWR1_SLEEP_BIT);
72
+    i2cWriteReg (MPU6050_RA_PWR_MGMT_1, regData);
73
+
74
+    return MAA_SUCCESS;
75
+}
76
+
77
+uint8_t
78
+MPU9150::getDeviceID () {
79
+    uint8_t regData = 0x0;
80
+    getRegBits (MPU6050_RA_WHO_AM_I, MPU6050_WHO_AM_I_BIT, MPU6050_WHO_AM_I_LENGTH, &regData);
81
+    return regData;
82
+}
83
+
84
+maa_result_t
85
+MPU9150::getData () {
86
+    uint8_t buffer[14];
87
+
88
+    for (int i = 0; i < SMOOTH_TIMES; i++) {
89
+        i2cReadReg_N (MPU6050_RA_ACCEL_XOUT_H, 14, buffer);
90
+        axisAcceleromter.rawData.axisX  = (((int16_t)buffer[0]) << 8)  | buffer[1];
91
+        axisAcceleromter.rawData.axisY  = (((int16_t)buffer[2]) << 8)  | buffer[3];
92
+        axisAcceleromter.rawData.axisZ  = (((int16_t)buffer[4]) << 8)  | buffer[5];
93
+        axisAcceleromter.sumData.axisX  += (double) axisAcceleromter.rawData.axisX / 16384;
94
+        axisAcceleromter.sumData.axisY  += (double) axisAcceleromter.rawData.axisY / 16384;
95
+        axisAcceleromter.sumData.axisZ  += (double) axisAcceleromter.rawData.axisZ / 16384;
96
+
97
+        axisGyroscope.rawData.axisX     = (((int16_t)buffer[8]) << 8)  | buffer[9];
98
+        axisGyroscope.rawData.axisY     = (((int16_t)buffer[10]) << 8) | buffer[11];
99
+        axisGyroscope.rawData.axisZ     = (((int16_t)buffer[12]) << 8) | buffer[13];
100
+        axisGyroscope.sumData.axisX     += (double) axisAcceleromter.rawData.axisX * 250 / 32768;
101
+        axisGyroscope.sumData.axisY     += (double) axisAcceleromter.rawData.axisY * 250 / 32768;
102
+        axisGyroscope.sumData.axisZ     += (double) axisAcceleromter.rawData.axisZ * 250 / 32768;
103
+
104
+        i2cWriteReg (MPU6050_RA_INT_PIN_CFG, 0x02);
105
+        usleep (10000);
106
+        m_i2cAddr = MPU9150_RA_MAG_ADDRESS;
107
+        i2cWriteReg (0x0A, 0x01);
108
+        usleep (10000);
109
+        i2cReadReg_N (MPU9150_RA_MAG_XOUT_L, 6, buffer);
110
+        m_i2cAddr = ADDR;
111
+
112
+        axisMagnetomer.rawData.axisX  = (((int16_t)buffer[0]) << 8)  | buffer[1];
113
+        axisMagnetomer.rawData.axisY  = (((int16_t)buffer[2]) << 8)  | buffer[3];
114
+        axisMagnetomer.rawData.axisZ  = (((int16_t)buffer[4]) << 8)  | buffer[5];
115
+        axisMagnetomer.sumData.axisX  += (double) axisMagnetomer.rawData.axisX * 1200 / 4096;
116
+        axisMagnetomer.sumData.axisY  += (double) axisMagnetomer.rawData.axisY * 1200 / 4096;
117
+        axisMagnetomer.sumData.axisZ  += (double) axisMagnetomer.rawData.axisZ * 1200 / 4096;
118
+    }
119
+
120
+    axisAcceleromter.data.axisX = axisAcceleromter.sumData.axisX / SMOOTH_TIMES;
121
+    axisAcceleromter.data.axisY = axisAcceleromter.sumData.axisY / SMOOTH_TIMES;
122
+    axisAcceleromter.data.axisZ = axisAcceleromter.sumData.axisZ / SMOOTH_TIMES;
123
+
124
+    axisGyroscope.data.axisX = axisGyroscope.sumData.axisX / SMOOTH_TIMES;
125
+    axisGyroscope.data.axisY = axisGyroscope.sumData.axisY / SMOOTH_TIMES;
126
+    axisGyroscope.data.axisZ = axisGyroscope.sumData.axisZ / SMOOTH_TIMES;
127
+
128
+    axisMagnetomer.data.axisX = axisMagnetomer.sumData.axisX / SMOOTH_TIMES;
129
+    axisMagnetomer.data.axisY = axisMagnetomer.sumData.axisY / SMOOTH_TIMES;
130
+    axisMagnetomer.data.axisZ = axisMagnetomer.sumData.axisZ / SMOOTH_TIMES;
131
+}
132
+
133
+maa_result_t
134
+MPU9150::getAcceleromter (Vector3D * data) {
135
+    data->axisX = axisAcceleromter.data.axisX;
136
+    data->axisY = axisAcceleromter.data.axisY;
137
+    data->axisZ = axisAcceleromter.data.axisZ;
138
+
139
+    return MAA_SUCCESS;
140
+}
141
+
142
+maa_result_t
143
+MPU9150::getGyro (Vector3D * data) {
144
+    data->axisX = axisGyroscope.data.axisX;
145
+    data->axisY = axisGyroscope.data.axisY;
146
+    data->axisZ = axisGyroscope.data.axisZ;
147
+
148
+    return MAA_SUCCESS;
149
+}
150
+
151
+maa_result_t
152
+MPU9150::getMagnometer (Vector3D * data) {
153
+    data->axisX = axisMagnetomer.data.axisX;
154
+    data->axisY = axisMagnetomer.data.axisY;
155
+    data->axisZ = axisMagnetomer.data.axisZ;
156
+
157
+    return MAA_SUCCESS;
158
+}
159
+
160
+float
161
+MPU9150::getTemperature () {
162
+    uint8_t buffer[2];
163
+    uint16_t tempRaw = 0;
164
+
165
+    updateRegBits (MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_TEMP_DIS_BIT, 0x1, 0x0);
166
+    i2cReadReg_N (MPU6050_RA_TEMP_OUT_H, 2, buffer);
167
+    tempRaw = (((int16_t)buffer[0]) << 8) | buffer[1];
168
+
169
+    return (float)tempRaw / 340.0 + 35.0;
170
+}
171
+
172
+/*
173
+ * **************
174
+ *  private area
175
+ * **************
176
+ */
177
+uint16_t
178
+MPU9150::i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer) {
179
+    int readByte = 0;
180
+    maa_i2c_address(m_i2Ctx, m_i2cAddr);
181
+    maa_i2c_write_byte(m_i2Ctx, reg);
182
+
183
+    maa_i2c_address(m_i2Ctx, m_i2cAddr);
184
+    readByte = maa_i2c_read(m_i2Ctx, buffer, len);
185
+    return readByte;
186
+}
187
+
188
+maa_result_t
189
+MPU9150::i2cWriteReg (uint8_t reg, uint8_t value) {
190
+    maa_result_t error = MAA_SUCCESS;
191
+
192
+    uint8_t data[2] = { reg, value };
193
+    error = maa_i2c_address (m_i2Ctx, m_i2cAddr);
194
+    error = maa_i2c_write (m_i2Ctx, data, 2);
195
+
196
+    return error;
197
+}
198
+
199
+int
200
+MPU9150::updateRegBits (uint8_t reg, uint8_t bitStart, uint8_t length, uint16_t data) {
201
+    uint8_t regData;
202
+
203
+    if (i2cReadReg_N (reg, 0x1, &regData) != 0) {
204
+        uint8_t mask = ((1 << length) - 1) << (bitStart - length + 1);
205
+        data <<= (bitStart - length + 1); // shift data into correct position
206
+        data &= mask; // zero all non-important bits in data
207
+        regData &= ~(mask); // zero all important bits in existing byte
208
+        regData |= data; // combine data with existing byte
209
+        return i2cWriteReg (reg, regData);
210
+    } else {
211
+        return 0x0;
212
+    }
213
+}
214
+
215
+uint8_t
216
+MPU9150::getRegBits (uint8_t reg, uint8_t bitStart, uint8_t length, uint8_t * data) {
217
+    uint8_t count = 0;
218
+    uint8_t regData;
219
+    if (i2cReadReg_N (reg, 0x1, &regData) != 0) {
220
+        uint8_t mask = ((1 << length) - 1) << (bitStart - length + 1);
221
+        regData &= mask;
222
+        regData >>= (bitStart - length + 1);
223
+        *data = regData;
224
+    }
225
+    return count;
226
+}

+ 196
- 0
src/mpu9150/mpu9150.h View File

@@ -0,0 +1,196 @@
1
+/*
2
+ * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3
+ * Copyright (c) 2014 Intel Corporation.
4
+ *
5
+ * Based on InvenSense MPU-6050 register map document rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)
6
+ * 8/24/2011 by Jeff Rowberg <jeff@rowberg.net>
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining
9
+ * a copy of this software and associated documentation files (the
10
+ * "Software"), to deal in the Software without restriction, including
11
+ * without limitation the rights to use, copy, modify, merge, publish,
12
+ * distribute, sublicense, and/or sell copies of the Software, and to
13
+ * permit persons to whom the Software is furnished to do so, subject to
14
+ * the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be
17
+ * included in all copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ */
27
+#pragma once
28
+
29
+#include <string>
30
+#include <maa/i2c.h>
31
+
32
+#define MPU6050_ADDRESS_AD0_LOW             0x68 // address pin low (GND), default for InvenSense evaluation board
33
+#define MPU6050_ADDRESS_AD0_HIGH            0x69 // address pin high (VCC)
34
+#define ADDR                                MPU6050_ADDRESS_AD0_LOW // device address
35
+
36
+// registers address
37
+#define MPU6050_CLOCK_PLL_XGYRO             0x01
38
+#define MPU6050_GYRO_FS_250                 0x00
39
+#define MPU6050_ACCEL_FS_2                  0x00
40
+#define MPU6050_RA_INT_PIN_CFG              0x37
41
+
42
+#define MPU6050_RA_ACCEL_XOUT_H             0x3B
43
+#define MPU6050_RA_ACCEL_XOUT_L             0x3C
44
+#define MPU6050_RA_ACCEL_YOUT_H             0x3D
45
+#define MPU6050_RA_ACCEL_YOUT_L             0x3E
46
+#define MPU6050_RA_ACCEL_ZOUT_H             0x3F
47
+#define MPU6050_RA_ACCEL_ZOUT_L             0x40
48
+#define MPU6050_RA_TEMP_OUT_H               0x41
49
+#define MPU6050_RA_TEMP_OUT_L               0x42
50
+#define MPU6050_RA_GYRO_XOUT_H              0x43
51
+#define MPU6050_RA_GYRO_XOUT_L              0x44
52
+#define MPU6050_RA_GYRO_YOUT_H              0x45
53
+#define MPU6050_RA_GYRO_YOUT_L              0x46
54
+#define MPU6050_RA_GYRO_ZOUT_H              0x47
55
+#define MPU6050_RA_GYRO_ZOUT_L              0x48
56
+
57
+#define MPU6050_RA_CONFIG                   0x1A
58
+#define MPU6050_CFG_DLPF_CFG_BIT            2
59
+#define MPU6050_CFG_DLPF_CFG_LENGTH         3
60
+
61
+#define MPU6050_RA_GYRO_CONFIG              0x1B
62
+#define MPU6050_GCONFIG_FS_SEL_BIT          4
63
+#define MPU6050_GCONFIG_FS_SEL_LENGTH       2
64
+
65
+#define MPU6050_RA_ACCEL_CONFIG             0x1C
66
+#define MPU6050_ACONFIG_AFS_SEL_BIT         4
67
+#define MPU6050_ACONFIG_AFS_SEL_LENGTH      2
68
+
69
+// magnotometer
70
+#define MPU9150_RA_MAG_ADDRESS              0x0C
71
+#define MPU9150_RA_MAG_XOUT_L               0x03
72
+
73
+#define MPU6050_RA_PWR_MGMT_1               0x6B
74
+#define MPU6050_PWR1_CLKSEL_BIT             2
75
+#define MPU6050_PWR1_CLKSEL_LENGTH          3
76
+#define MPU6050_PWR1_SLEEP_BIT              6
77
+
78
+#define MPU6050_RA_INT_PIN_CFG              0x37
79
+
80
+// temperature
81
+#define MPU6050_PWR1_TEMP_DIS_BIT           3
82
+#define MPU6050_RA_WHO_AM_I                 0x75
83
+#define MPU6050_WHO_AM_I_BIT                6
84
+#define MPU6050_WHO_AM_I_LENGTH             6
85
+
86
+#define SMOOTH_TIMES                        10.0
87
+
88
+#define HIGH               1
89
+#define LOW                0
90
+
91
+namespace upm {
92
+
93
+struct Vector3DRaw {
94
+    uint16_t axisX;
95
+    uint16_t axisY;
96
+    uint16_t axisZ;
97
+};
98
+
99
+struct Vector3D {
100
+    double axisX;
101
+    double axisY;
102
+    double axisZ;
103
+};
104
+
105
+struct AxisData {
106
+    Vector3DRaw rawData;
107
+    Vector3D    sumData;
108
+    Vector3D    data;
109
+};
110
+
111
+/**
112
+ * @brief C++ API for MPU9150 chip (Accelrometer, Gyro and Magnometer Sensor)
113
+ *
114
+ * This file defines the MPU9150 C++ interface for libmpu9150
115
+ *
116
+ * @snippet mpu9150-example.cxx Interesting
117
+ */
118
+class MPU9150 {
119
+    public:
120
+        /**
121
+         * Instanciates a MPU9150 object
122
+         *
123
+         * @param bus number of used bus
124
+         * @param devAddr addres of used i2c device
125
+         */
126
+        MPU9150 (int bus, int devAddr);
127
+
128
+        /**
129
+         * MPU9150 object destructor, basicaly it close i2c connection.
130
+         */
131
+        ~MPU9150 ();
132
+
133
+        /**
134
+         * Initiate MPU9150 chips
135
+         */
136
+        maa_result_t initSensor ();
137
+
138
+        /**
139
+         * Get identity of the device
140
+         */
141
+        uint8_t getDeviceID ();
142
+
143
+        /**
144
+         * Get the Accelerometer, Gyro and Compass data from the chip and
145
+         * save it in private section.
146
+         */
147
+        maa_result_t getData ();
148
+
149
+        /**
150
+         * @param data structure with 3 axis (x,y,z)
151
+         */
152
+        maa_result_t getAcceleromter (Vector3D * data);
153
+
154
+        /**
155
+         * @param data structure with 3 axis (x,y,z)
156
+         */
157
+        maa_result_t getGyro (Vector3D * data);
158
+
159
+        /**
160
+         * @param data structure with 3 axis (x,y,z)
161
+         */
162
+        maa_result_t getMagnometer (Vector3D * data);
163
+
164
+        /**
165
+         * Read on die temperature from the chip
166
+         */
167
+        float getTemperature ();
168
+
169
+        /**
170
+         * Return name of the component
171
+         */
172
+        std::string name()
173
+        {
174
+            return m_name;
175
+        }
176
+
177
+    private:
178
+        std::string m_name;
179
+
180
+        int m_i2cAddr;
181
+        int m_bus;
182
+        maa_i2c_context m_i2Ctx;
183
+
184
+        AxisData axisMagnetomer;
185
+        AxisData axisAcceleromter;
186
+        AxisData axisGyroscope;
187
+
188
+        uint16_t i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer);
189
+        maa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
190
+        int updateRegBits (uint8_t reg, uint8_t bitStart,
191
+                                    uint8_t length, uint16_t data);
192
+        uint8_t getRegBits (uint8_t reg, uint8_t bitStart,
193
+                                    uint8_t length, uint8_t * data);
194
+};
195
+
196
+}

+ 10
- 0
src/mpu9150/pyupm_mpu9150.i View File

@@ -0,0 +1,10 @@
1
+%module pyupm_mpu9150
2
+
3
+%include "stdint.i"
4
+
5
+%feature("autodoc", "3");
6
+
7
+%include "mpu9150.h"
8
+%{
9
+    #include "mpu9150.h"
10
+%}