|
@@ -1,6 +1,7 @@
|
1
|
|
-#!/usr/bin/env python
|
|
1
|
+#!/usr/bin/python
|
2
|
2
|
|
3
|
3
|
# Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
|
4
|
+# Contributions: Zion Orent <zorent@ics.com>
|
4
|
5
|
# Copyright (c) 2014 Intel Corporation.
|
5
|
6
|
#
|
6
|
7
|
# Permission is hereby granted, free of charge, to any person obtaining
|
|
@@ -22,8 +23,65 @@
|
22
|
23
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
24
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
24
|
25
|
|
|
26
|
+import time, sys, signal, atexit
|
25
|
27
|
import pyupm_lsm303 as lsm303
|
26
|
28
|
|
27
|
|
-x = lsm303.LSM303(0)
|
28
|
|
-x.getCoordinates()
|
29
|
|
-x.getHeading()
|
|
29
|
+# Instantiate LSM303 compass on I2C
|
|
30
|
+myAccelrCompass = lsm303.LSM303(0)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+## Exit handlers ##
|
|
34
|
+# This stops python from printing a stacktrace when you hit control-C
|
|
35
|
+def SIGINTHandler(signum, frame):
|
|
36
|
+ raise SystemExit
|
|
37
|
+
|
|
38
|
+# This lets you run code on exit,
|
|
39
|
+# including functions from myAccelrCompass
|
|
40
|
+def exitHandler():
|
|
41
|
+ print "Exiting"
|
|
42
|
+ sys.exit(0)
|
|
43
|
+
|
|
44
|
+# Register exit handlers
|
|
45
|
+atexit.register(exitHandler)
|
|
46
|
+signal.signal(signal.SIGINT, SIGINTHandler)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+while(1):
|
|
50
|
+ # Load coordinates into LSM303 object
|
|
51
|
+ successFail = myAccelrCompass.getCoordinates()
|
|
52
|
+ # in XYZ order. The sensor returns XZY,
|
|
53
|
+ # but the driver compensates and makes it XYZ
|
|
54
|
+ coords = myAccelrCompass.getRawCoorData()
|
|
55
|
+
|
|
56
|
+ # Print out the X, Y, and Z coordinate data
|
|
57
|
+ # using two different methods
|
|
58
|
+ outputStr = "coor: rX {0} - rY {1} - rZ {2}".format(
|
|
59
|
+ coords.__getitem__(0), coords.__getitem__(1),
|
|
60
|
+ coords.__getitem__(2))
|
|
61
|
+ print outputStr
|
|
62
|
+
|
|
63
|
+ outputStr = "coor: gX {0} - gY {1} - gZ {2}".format(
|
|
64
|
+ myAccelrCompass.getCoorX(), myAccelrCompass.getCoorY(),
|
|
65
|
+ myAccelrCompass.getCoorZ())
|
|
66
|
+ print outputStr
|
|
67
|
+
|
|
68
|
+ # Get and print out the heading
|
|
69
|
+ print "heading:", myAccelrCompass.getHeading()
|
|
70
|
+
|
|
71
|
+ # Get the acceleration
|
|
72
|
+ myAccelrCompass.getAcceleration();
|
|
73
|
+ accel = myAccelrCompass.getRawAccelData();
|
|
74
|
+
|
|
75
|
+ # Print out the X, Y, and Z acceleration data
|
|
76
|
+ # using two different methods
|
|
77
|
+ outputStr = "acc: rX {0} - rY {1} - Z {2}".format(
|
|
78
|
+ accel.__getitem__(0), accel.__getitem__(1), accel.__getitem__(2))
|
|
79
|
+ print outputStr
|
|
80
|
+
|
|
81
|
+ outputStr = "acc: gX {0} - gY {1} - gZ {2}".format(
|
|
82
|
+ myAccelrCompass.getAccelX(), myAccelrCompass.getAccelY(),
|
|
83
|
+ myAccelrCompass.getAccelZ())
|
|
84
|
+ print outputStr
|
|
85
|
+
|
|
86
|
+ print " "
|
|
87
|
+ time.sleep(1)
|