Skip to content

Commit 44705fc

Browse files
author
jack_yang
committed
添加陀螺factor ,
1 parent cbfd7ae commit 44705fc

File tree

5 files changed

+35
-19
lines changed

5 files changed

+35
-19
lines changed

com_d.py

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def com_init():
1818
com= serial.Serial('COM3',115200,timeout=0)
1919
return com
2020

21+
2122

2223
def get_num(input):
2324
val=0
@@ -79,6 +80,7 @@ def get_data(com):
7980
time.sleep(0.0005)
8081
# time.sleep(0.001)
8182
data = com.readall()
83+
8284
#return
8385
#return hexShow(data)
8486
return np.append(decode_acc(data),[decode_gyro(data),decode_erula(data)])

ekf_filter.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __init__(self):
7474
self.measure_dm =6
7575
self.init_flag = 0
7676

77-
self.qq=0.045 ##
77+
self.qq=0.0045 ##
7878
self.qw=0.025
7979

8080

@@ -121,6 +121,7 @@ def __init__(self):
121121
self.X=np.zeros(self.status_dm)
122122
self.Y=np.zeros(self.measure_dm)
123123
self.K=np.zeros((self.status_dm,self.measure_dm))
124+
self.factor = 16.4*180.0/np.pi
124125
def filter_init(self,gyro,accel):
125126
nedVector = np.array([0, 0 , -1.0])
126127
accelVector=np.zeros(3)
@@ -166,9 +167,9 @@ def filter_update(self,gyro,accel,dt=0.002):
166167
halfdt =dt*0.5
167168
### 0.5*t(w - wbias)
168169
##self.X[4:6]存储的是w的
169-
halfdx = halfdt * (gyro[0] - self.X[4])
170-
halfdy = halfdt * (gyro[1] - self.X[5])
171-
halfdz = halfdt * (gyro[2] - self.X[6])
170+
halfdx = halfdt * (gyro[0]/self.factor - self.X[4])
171+
halfdy = halfdt * (gyro[1]/self.factor - self.X[5])
172+
halfdz = halfdt * (gyro[2]/self.factor - self.X[6])
172173

173174
neghalfdx = -halfdx
174175
neghalfdy = -halfdy

madgwick_filter.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# -*- coding: utf-8 -*-
33
from math import sqrt,atan2,asin
4-
from numpy import pi
4+
from numpy import pi,array
55

66
def Sqr(x):
77
return x**2
@@ -17,7 +17,7 @@ def qa_to_erula_angle(q):
1717
num=1.0
1818
PitchAngle = asin(num)
1919
YawAngle = atan2(2.0*q1*q2 - 2.0*q0*q3, 2.0*Sqr(q0) + 2.0*Sqr(q1) - 1.0);
20-
return [PitchAngle,RollAngle,YawAngle]
20+
return array([PitchAngle,RollAngle,YawAngle])
2121
###def madgwick_filter
2222
class madgwick_filter(object):
2323
"""docstring for ClassName"""

main.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,50 @@
1212
filter =mdf.madgwick_filter(0.4)
1313
'''
1414
import ekf_filter as ekf
15-
filter =ekf.ekf_filter()
15+
filter1 = ekf.ekf_filter()
16+
17+
import madgwick_filter as mdf
18+
filter2 =mdf.madgwick_filter(0.1)
1619

1720

1821
import time as tm
1922
time_str = tm.strftime('%Y-%m-%d-%H-%M-%S',tm.localtime(tm.time()))
2023
file_name='arhs-'+time_str+'.txt'
2124

22-
#fo = open(file_name, "wb")
25+
fo = open(file_name, "wb")
2326
while 1:
2427
data = ser.get_data(com_port)
2528
acc=data[:3]
2629
gyro=data[3:6]
2730
erula_cal=data[6:]
2831
#print acc,gyro
2932
#tm.sleep (1)
30-
if (filter.init_flag ==0):
31-
filter.filter_init(gyro,acc)
32-
filter.init_flag=1
33+
if (filter1.init_flag ==0):
34+
filter1.filter_init(gyro,acc)
35+
filter1.init_flag=1
3336
else:
34-
data=filter.filter_update(gyro,acc,0.001)
35-
37+
data=filter1.filter_update(gyro,acc,0.001)
38+
3639
erual =data*180/np.pi
3740
stra=' '
3841
stra+=str(erual[0]) +' '
3942
stra+=str(erual[1]) +' '
4043
stra+=str(erual[2]) +' '
4144

45+
46+
47+
data=filter2.filter_update(gyro,acc)
48+
erual =data*180/np.pi
49+
stra+=str(erual[0]) +' '
50+
stra+=str(erual[1]) +' '
51+
stra+=str(erual[2]) +' '
52+
4253
stra+=str(erula_cal[0]) +' '
4354
stra+=str(erula_cal[1]) +' '
4455
stra+=str(erula_cal[2]) +' '
4556
stra+='\n'
4657
print stra
47-
#fo.write(stra);
58+
fo.write(stra);
4859

4960

5061

test.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
# norm2 = normalize(x[:,np.newaxis], axis=0).ravel()
1919
# print np.all(norm1 == norm2)
2020

21-
2221
import numpy as np
23-
b=np.ones((7,6))
24-
c =np.ones((6,7))
25-
a = np.dot(b,c)
26-
print a.shape
22+
# b=np.ones((7,6))
23+
# c =np.ones((6,7))
24+
# a = np.dot(b,c)
25+
# print a.shape
26+
stra ="-0.094727,0.008301,1.003906,0.011706,-0.006385,0.007449"
27+
a=np.fromstring(stra, dtype=float, sep=', ')
28+
print a

0 commit comments

Comments
 (0)