Browse Source

mpu9250: Initial implementation

This driver was implemented using a Grove IMU 9DOF V2.0 (mpu9250).

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: sisinty sasmita patra <sisinty.s.patra@intel.com>
Jon Trulson 9 years ago
parent
commit
76f7abb112

+ 2
- 0
examples/c++/CMakeLists.txt View File

@@ -133,6 +133,7 @@ add_executable (mpu60x0-example mpu60x0.cxx)
133 133
 add_executable (ak8975-example ak8975.cxx)
134 134
 add_executable (lsm9ds0-example lsm9ds0.cxx)
135 135
 add_executable (eboled-example eboled.cxx)
136
+add_executable (mpu9250-example mpu9250.cxx)
136 137
 add_executable (hyld9767-example hyld9767.cxx)
137 138
 add_executable (mg811-example mg811.cxx)
138 139
 add_executable (wheelencoder-example wheelencoder.cxx)
@@ -379,6 +380,7 @@ target_link_libraries (mpu60x0-example mpu9150 ${CMAKE_THREAD_LIBS_INIT})
379 380
 target_link_libraries (ak8975-example mpu9150 ${CMAKE_THREAD_LIBS_INIT})
380 381
 target_link_libraries (lsm9ds0-example lsm9ds0 ${CMAKE_THREAD_LIBS_INIT})
381 382
 target_link_libraries (eboled-example i2clcd ${CMAKE_THREAD_LIBS_INIT})
383
+target_link_libraries (mpu9250-example mpu9150 ${CMAKE_THREAD_LIBS_INIT})
382 384
 target_link_libraries (hyld9767-example hyld9767 ${CMAKE_THREAD_LIBS_INIT})
383 385
 target_link_libraries (mg811-example mg811 ${CMAKE_THREAD_LIBS_INIT})
384 386
 target_link_libraries (wheelencoder-example wheelencoder ${CMAKE_THREAD_LIBS_INIT})

+ 81
- 0
examples/c++/mpu9250.cxx View File

@@ -0,0 +1,81 @@
1
+/*
2
+ * Author: Jon Trulson <jtrulson@ics.com>
3
+ * Copyright (c) 2015 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 <signal.h>
28
+#include "mpu9250.h"
29
+
30
+using namespace std;
31
+
32
+int shouldRun = true;
33
+
34
+void sig_handler(int signo)
35
+{
36
+  if (signo == SIGINT)
37
+    shouldRun = false;
38
+}
39
+
40
+
41
+int main(int argc, char **argv)
42
+{
43
+  signal(SIGINT, sig_handler);
44
+//! [Interesting]
45
+
46
+  upm::MPU9250 *sensor = new upm::MPU9250();
47
+
48
+  sensor->init();
49
+
50
+  while (shouldRun)
51
+    {
52
+      sensor->update();
53
+      
54
+      float x, y, z;
55
+      
56
+      sensor->getAccelerometer(&x, &y, &z);
57
+      cout << "Accelerometer: ";
58
+      cout << "AX: " << x << " AY: " << y << " AZ: " << z << endl;
59
+
60
+      sensor->getGyroscope(&x, &y, &z);
61
+      cout << "Gryoscope:     ";
62
+      cout << "GX: " << x << " GY: " << y << " GZ: " << z << endl;
63
+      
64
+      sensor->getMagnetometer(&x, &y, &z);
65
+      cout << "Magnetometer:  ";
66
+      cout << "MX = " << x << " MY = " << y << " MZ = " << z << endl;
67
+
68
+      cout << "Temperature:   " << sensor->getTemperature() << endl;
69
+      cout << endl;
70
+
71
+      usleep(500000);
72
+    }
73
+
74
+//! [Interesting]
75
+
76
+  cout << "Exiting..." << endl;
77
+  
78
+  delete sensor;
79
+  
80
+  return 0;
81
+}

+ 76
- 0
examples/javascript/mpu9250.js View File

@@ -0,0 +1,76 @@
1
+/*jslint node:true, vars:true, bitwise:true, unparam:true */
2
+/*jshint unused:true */
3
+
4
+/*
5
+ * Author: Jon Trulson <jtrulson@ics.com>
6
+ * Copyright (c) 2015 Intel Corporation.
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
+
29
+var sensorObj = require('jsupm_mpu9150');
30
+
31
+// Instantiate an MPU9105 on default I2C bus and address
32
+var sensor = new sensorObj.MPU9250();
33
+
34
+// Initialize the device with default values
35
+sensor.init();
36
+
37
+var x = new sensorObj.new_floatp();
38
+var y = new sensorObj.new_floatp();
39
+var z = new sensorObj.new_floatp();
40
+
41
+// Output data every half second until interrupted
42
+setInterval(function()
43
+{
44
+    sensor.update();
45
+    
46
+    sensor.getAccelerometer(x, y, z);
47
+    console.log("Accelerometer: AX: " + sensorObj.floatp_value(x) + 
48
+                " AY: " + sensorObj.floatp_value(y) + 
49
+                " AZ: " + sensorObj.floatp_value(z));
50
+
51
+    sensor.getGyroscope(x, y, z);
52
+    console.log("Gyroscope:     GX: " + sensorObj.floatp_value(x) + 
53
+                " AY: " + sensorObj.floatp_value(y) + 
54
+                " AZ: " + sensorObj.floatp_value(z));
55
+ 
56
+    sensor.getMagnetometer(x, y, z);
57
+    console.log("Magnetometer:  MX: " + sensorObj.floatp_value(x) + 
58
+                " MY: " + sensorObj.floatp_value(y) + 
59
+                " MZ: " + sensorObj.floatp_value(z));
60
+
61
+    console.log("Temperature:   " + sensor.getTemperature());
62
+ 
63
+    console.log();
64
+
65
+}, 500);
66
+
67
+// exit on ^C
68
+process.on('SIGINT', function()
69
+{
70
+    sensor = null;
71
+    sensorObj.cleanUp();
72
+    sensorObj = null;
73
+    console.log("Exiting.");
74
+    process.exit(0);
75
+});
76
+

+ 70
- 0
examples/python/mpu9250.py View File

@@ -0,0 +1,70 @@
1
+#!/usr/bin/python
2
+# Author: Jon Trulson <jtrulson@ics.com>
3
+# Copyright (c) 2015 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
+import time, sys, signal, atexit
25
+import pyupm_mpu9150 as sensorObj
26
+
27
+# Instantiate an MPU9250 on I2C bus 0
28
+sensor = sensorObj.MPU9250()
29
+
30
+## Exit handlers ##
31
+# This function stops python from printing a stacktrace when you hit control-C
32
+def SIGINTHandler(signum, frame):
33
+	raise SystemExit
34
+
35
+# This function lets you run code on exit
36
+def exitHandler():
37
+	print "Exiting"
38
+	sys.exit(0)
39
+
40
+# Register exit handlers
41
+atexit.register(exitHandler)
42
+signal.signal(signal.SIGINT, SIGINTHandler)
43
+
44
+sensor.init()
45
+
46
+x = sensorObj.new_floatp()
47
+y = sensorObj.new_floatp()
48
+z = sensorObj.new_floatp()
49
+
50
+while (1):
51
+        sensor.update()
52
+        sensor.getAccelerometer(x, y, z)
53
+        print "Accelerometer: AX: ", sensorObj.floatp_value(x), 
54
+        print " AY: ", sensorObj.floatp_value(y),
55
+        print " AZ: ", sensorObj.floatp_value(z)
56
+
57
+        sensor.getGyroscope(x, y, z)
58
+        print "Gyroscope:     GX: ", sensorObj.floatp_value(x), 
59
+        print " GY: ", sensorObj.floatp_value(y),
60
+        print " GZ: ", sensorObj.floatp_value(z)
61
+
62
+        sensor.getMagnetometer(x, y, z)
63
+        print "Magnetometer:  MX: ", sensorObj.floatp_value(x), 
64
+        print " MY: ", sensorObj.floatp_value(y),
65
+        print " MZ: ", sensorObj.floatp_value(z)
66
+
67
+        print "Temperature:  ", sensor.getTemperature()
68
+        print
69
+
70
+	time.sleep(.5)

+ 2
- 2
src/mpu9150/CMakeLists.txt View File

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

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

@@ -23,3 +23,8 @@
23 23
     #include "mpu9150.h"
24 24
 %}
25 25
 
26
+%include "mpu9250.h"
27
+%{
28
+    #include "mpu9250.h"
29
+%}
30
+

+ 1
- 1
src/mpu9150/mpu60x0.h View File

@@ -830,7 +830,7 @@ namespace upm {
830 830
      *
831 831
      * @return the temperature value in degrees Celcius
832 832
      */
833
-    float getTemperature();
833
+    virtual float getTemperature();
834 834
 
835 835
     /**
836 836
      * enable onboard temperature measurement sensor

+ 50
- 0
src/mpu9150/mpu9250.cxx View File

@@ -0,0 +1,50 @@
1
+/*
2
+ * Author: Jon Trulson <jtrulson@ics.com>
3
+ * Copyright (c) 2015 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 <iostream>
26
+#include <unistd.h>
27
+#include <stdlib.h>
28
+
29
+#include "mpu9250.h"
30
+
31
+using namespace upm;
32
+using namespace std;
33
+
34
+MPU9250::MPU9250 (int bus, int address, int magAddress) :
35
+  MPU9150(bus, address, magAddress)
36
+{
37
+}
38
+
39
+MPU9250::~MPU9250()
40
+{
41
+}
42
+
43
+float MPU9250::getTemperature()
44
+{
45
+  // this equation is taken from the datasheet.  The 333.87 value was
46
+  // taken from the adafruit code (it is referenced as
47
+  // Temp_Sensitivity in the datasheet, but no value is provided there).
48
+  return (m_temp / 333.87) + 21.0;
49
+}
50
+

+ 82
- 0
src/mpu9150/mpu9250.h View File

@@ -0,0 +1,82 @@
1
+/*
2
+ * Author: Jon Trulson <jtrulson@ics.com>
3
+ * Copyright (c) 2015 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
+#pragma once
26
+
27
+#include "mpu9150.h"
28
+
29
+#define MPU9250_I2C_BUS 0
30
+#define MPU9250_DEFAULT_I2C_ADDR  MPU9150_DEFAULT_I2C_ADDR
31
+
32
+
33
+namespace upm {
34
+
35
+  /**
36
+   * @library mpu9150
37
+   * @sensor mpu9250
38
+   * @comname MPU9250 Inertial Measurement Unit
39
+   * @altname Grove IMU 9DOF V2
40
+   * @type accelerometer compass
41
+   * @man seeed
42
+   * @web http://www.seeedstudio.com/wiki/Grove_-_IMU_9DOF_v2.0
43
+   * @con i2c gpio
44
+   *
45
+   * @brief API for MPU9250 chip (Accelerometer, Gyro and Magnometer Sensor)
46
+   *
47
+   * This file defines the MPU9250 interface for libmpu9150
48
+   *
49
+   * @snippet mpu9250.cxx Interesting
50
+   */
51
+
52
+  class MPU9250: public MPU9150
53
+  {
54
+  public:
55
+    /**
56
+     * MPU9250 constructor
57
+     *
58
+     * @param bus I2C bus to use
59
+     * @param address The address for this device
60
+     * @param magAddress The address of the connected magnetometer
61
+     */
62
+    MPU9250 (int bus=MPU9250_I2C_BUS, int address=MPU9250_DEFAULT_I2C_ADDR,
63
+             int magAddress=AK8975_DEFAULT_I2C_ADDR);
64
+
65
+    /**
66
+     * MPU9250 destructor
67
+     */
68
+    ~MPU9250 ();
69
+
70
+    /**
71
+     * get the temperature value
72
+     *
73
+     * @return the temperature value in degrees Celcius
74
+     */
75
+    float getTemperature();
76
+
77
+  protected:
78
+
79
+  private:
80
+  };
81
+
82
+}

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

@@ -23,3 +23,8 @@
23 23
     #include "mpu9150.h"
24 24
 %}
25 25
 
26
+%include "mpu9250.h"
27
+%{
28
+    #include "mpu9250.h"
29
+%}
30
+