forked from shubhamdawkhar/Sparton-AHRS-8
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathahrs.py
150 lines (141 loc) · 4.34 KB
/
ahrs.py
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import serial
import datetime
import time as tim
import globalv
cmd_yaw = "yaw di.\r\n"
cmd_roll = "roll di.\r\n"
cmd_pitch = "pitch di.\r\n"
cmd_accelero = "accelp di.\r\n"
cmd_gyro = "gyrop di.\r\n"
cmd_temp = "temperature di.\r\n"
def time():
t = datetime.datetime.now()
t = str(t)
t = t[17:]
t = float(t)
return t
def yaw():
serimu = globalv.serimu()
flag = 0
serimu.flush()
while flag == 0:
serimu.write(cmd_yaw)
t = time()
while abs(t-time() < 0.01) and flag == 0 :
read = serimu.readline()
for line in read.split('\r') :
if line.startswith ("yaw ="):
yaw = line.split("=")
yaw = float(yaw[1])
#print "yaw : "+str(yaw)
flag = 1
return yaw
def roll():
serimu = globalv.serimu()
flag = 0
serimu.flush()
while flag == 0:
serimu.write(cmd_roll)
t = time()
while abs(t-time() < 0.01) and flag == 0:
read = serimu.readline()
for line in read.split('\r') :
if line.startswith ("roll ="):
roll = line.split("=")
roll = float(roll[1])
#print "roll : "+str(roll)
flag = 1
return roll
def pitch():
serimu = globalv.serimu()
flag = 0
serimu.flush()
while flag == 0:
serimu.write(cmd_pitch)
t = time()
while abs(t-time() < 0.01) and flag == 0 :
read = serimu.readline()
for line in read.split('\r') :
if line.startswith ("pitch ="):
pitch = line.split("=")
pitch = float(pitch[1])
#print "pitch : "+str(pitch)
flag = 1
return pitch
def gyro():
serimu = globalv.serimu()
flagx = 0
flagy = 0
flagz = 0
serimu.flush()
while flagx == 0 or flagy == 0 or flagz == 0:
serimu.write(cmd_gyro)
t = time()
while abs(t-time() < 0.01) and (flagx == 0 or flagy == 0 or flagz == 0) :
read = serimu.readline()
for line in read.split('\r') :
if line.startswith ("gyrop = 00--"):
gx = line.split("--")
gx = float(gx[1])
#print "gx : "+str(gx)
flagx = 1
if line.startswith ("01--"):
gy = line.split("--")
gy = float(gy[1])
#print "gy : "+str(gy)
flagy = 1
if line.startswith ("02--"):
gz = line.split("--")
gz = float(gz[1])
#print "gz : "+str(gz)
flagz = 1
g = [gx,gy,gz]
return g
def accelerometer():
serimu = globalv.serimu()
flagx = 0
flagy = 0
flagz = 0
serimu.flush()
while flagx == 0 or flagy == 0 or flagz == 0:
serimu.write(cmd_accelero)
t = time()
while abs(t-time() < 0.01) and (flagx == 0 or flagy == 0 or flagz == 0) :
read = serimu.readline()
for line in read.split('\r') :
if line.startswith ("accelp = 00--"):
ax = line.split("--")
ax = float(ax[1])
#print "ax : "+str(ax)
flagx = 1
if line.startswith ("01--"):
ay = line.split("--")
ay = float(ay[1])
#print "ay : "+str(ay)
flagy = 1
if line.startswith ("02--"):
az = line.split("--")
az = float(az[1])
#print "az : "+str(az)
flagz = 1
a = [ax,ay,az]
return a
def temperature():
serimu = globalv.serimu()
flag = 0
serimu.flush()
while flag == 0:
serimu.write(cmd_temp)
t = time()
while abs(t-time() < 0.01) and flag == 0 :
read = serimu.readline()
for line in read.split('\r') :
if line.startswith ("temperature ="):
temp = line.split("=")
temp = float(temp[1])
#print "temperature : "+str(temp)
flag = 1
return temp
print pitch()
print yaw()
print accelerometer