|
26 | 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 | 27 | """
|
28 | 28 |
|
29 |
| -import spidev |
30 | 29 | import time
|
31 | 30 | import argparse
|
32 | 31 | import sys
|
33 |
| -import navio.mpu9250 |
34 |
| -import navio.util |
35 | 32 |
|
36 |
| -navio.util.check_apm() |
| 33 | +import navio.Common.mpu9250 |
| 34 | +import navio.Common.util |
| 35 | +import navio.Navio2.lsm9ds1 |
37 | 36 |
|
38 |
| -parser = argparse.ArgumentParser() |
39 |
| -parser.add_argument("-i", help = "Sensor selection: -i [sensor name]. Sensors names: mpu is MPU9250, lsm is LSM9DS1") |
| 37 | +navio.Common.util.check_apm() |
40 | 38 |
|
41 |
| -if len(sys.argv) == 1: |
42 |
| - print "Enter parameter" |
43 |
| - parser.print_help() |
44 |
| - sys.exit(1) |
45 |
| -elif len(sys.argv) == 2: |
46 |
| - sys.exit("Enter sensor name: mpu or lsm") |
| 39 | +def get_inertial_sensor(): |
47 | 40 |
|
48 |
| -args = parser.parse_args() |
| 41 | + if (navio.Common.util.get_navio_version() == "NAVIO2"): |
49 | 42 |
|
50 |
| -if args.i == 'mpu': |
51 |
| - print "Selected: MPU9250" |
52 |
| - imu = navio.mpu9250.MPU9250() |
53 |
| -elif args.i == 'lsm': |
54 |
| - print "Selected: LSM9DS1" |
55 |
| - imu = navio.lsm9ds1.LSM9DS1() |
56 |
| -else: |
57 |
| - print "Wrong sensor name. Select: mpu or lsm" |
58 |
| - sys.exit(1) |
| 43 | + parser = argparse.ArgumentParser() |
| 44 | + parser.add_argument("-i", help = "Sensor selection: -i [sensor name]. Sensors names: mpu is MPU9250, lsm is LSM9DS1") |
| 45 | + |
| 46 | + if len(sys.argv) == 1: |
| 47 | + print "Enter parameter" |
| 48 | + parser.print_help() |
| 49 | + sys.exit(1) |
| 50 | + elif len(sys.argv) == 2: |
| 51 | + sys.exit("Enter sensor name: mpu or lsm") |
| 52 | + |
| 53 | + args = parser.parse_args() |
| 54 | + |
| 55 | + if args.i == 'mpu': |
| 56 | + print "Selected: MPU9250" |
| 57 | + return navio.Common.mpu9250.MPU9250() |
| 58 | + elif args.i == 'lsm': |
| 59 | + print "Selected: LSM9DS1" |
| 60 | + return navio.Navio2.lsm9ds1.LSM9DS1() |
| 61 | + else: |
| 62 | + print "Wrong sensor name. Select: mpu or lsm" |
| 63 | + sys.exit(1) |
| 64 | + else: |
| 65 | + print "Selected: MPU9250" |
| 66 | + return navio.Common.mpu9250.MPU9250() |
59 | 67 |
|
60 | 68 |
|
| 69 | +imu = get_inertial_sensor(); |
61 | 70 |
|
62 | 71 | if imu.testConnection():
|
63 | 72 | print "Connection established: True"
|
|
69 | 78 | time.sleep(1)
|
70 | 79 |
|
71 | 80 | while True:
|
72 |
| - # imu.read_all() |
73 |
| - # imu.read_gyro() |
74 |
| - # imu.read_acc() |
75 |
| - # imu.read_temp() |
76 |
| - # imu.read_mag() |
| 81 | + # imu.read_all() |
| 82 | + # imu.read_gyro() |
| 83 | + # imu.read_acc() |
| 84 | + # imu.read_temp() |
| 85 | + # imu.read_mag() |
77 | 86 |
|
78 |
| - # print "Accelerometer: ", imu.accelerometer_data |
79 |
| - # print "Gyroscope: ", imu.gyroscope_data |
80 |
| - # print "Temperature: ", imu.temperature |
81 |
| - # print "Magnetometer: ", imu.magnetometer_data |
| 87 | + # print "Accelerometer: ", imu.accelerometer_data |
| 88 | + # print "Gyroscope: ", imu.gyroscope_data |
| 89 | + # print "Temperature: ", imu.temperature |
| 90 | + # print "Magnetometer: ", imu.magnetometer_data |
82 | 91 |
|
83 |
| - # time.sleep(0.1) |
| 92 | + # time.sleep(0.1) |
84 | 93 |
|
85 |
| - m9a, m9g, m9m = imu.getMotion9() |
| 94 | + m9a, m9g, m9m = imu.getMotion9() |
86 | 95 |
|
87 |
| - print "Acc:", "{:+7.3f}".format(m9a[0]), "{:+7.3f}".format(m9a[1]), "{:+7.3f}".format(m9a[2]), |
88 |
| - print " Gyr:", "{:+8.3f}".format(m9g[0]), "{:+8.3f}".format(m9g[1]), "{:+8.3f}".format(m9g[2]), |
89 |
| - print " Mag:", "{:+7.3f}".format(m9m[0]), "{:+7.3f}".format(m9m[1]), "{:+7.3f}".format(m9m[2]) |
| 96 | + print "Acc:", "{:+7.3f}".format(m9a[0]), "{:+7.3f}".format(m9a[1]), "{:+7.3f}".format(m9a[2]), |
| 97 | + print " Gyr:", "{:+8.3f}".format(m9g[0]), "{:+8.3f}".format(m9g[1]), "{:+8.3f}".format(m9g[2]), |
| 98 | + print " Mag:", "{:+7.3f}".format(m9m[0]), "{:+7.3f}".format(m9m[1]), "{:+7.3f}".format(m9m[2]) |
90 | 99 |
|
91 |
| - time.sleep(0.5) |
| 100 | + time.sleep(0.5) |
0 commit comments