Showing
2 changed files
with
79 additions
and
2 deletions
source/DroneControl/PairInfo
0 → 100644
1 | +9513 | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | import CoDrone | 1 | import CoDrone |
2 | +import math | ||
3 | + | ||
4 | +ac_x = 0 | ||
5 | +ac_y = 0 | ||
6 | +ac_z = 0 | ||
7 | +normal_x = 0 | ||
8 | +normal_y = 0 | ||
9 | +normal_z = 0 | ||
10 | +deltha_x = [0,0,0] | ||
11 | +deltha_y = [0,0,0] | ||
12 | +deltha_z = [0,0,0] | ||
13 | +deltha = 0 | ||
14 | + | ||
15 | +def map(x,input_min,input_max,output_min,output_max): | ||
16 | + return (x-input_min)*(output_max-output_min)/(input_max-input_min)+output_min | ||
17 | + | ||
18 | + | ||
2 | 19 | ||
3 | def main(): | 20 | def main(): |
4 | drone = CoDrone.CoDrone() | 21 | drone = CoDrone.CoDrone() |
... | @@ -6,8 +23,67 @@ def main(): | ... | @@ -6,8 +23,67 @@ def main(): |
6 | 23 | ||
7 | # print the acceleration of drone | 24 | # print the acceleration of drone |
8 | while 1: | 25 | while 1: |
9 | - acceleration = drone.get_accelerometer() | 26 | + normal_x = 0 |
10 | - print(acceleration.X, acceleration.Y, acceleration.Z) | 27 | + normal_y = 0 |
28 | + normal_z = 0 | ||
29 | + | ||
30 | + for i in range(3): | ||
31 | + deltha_x[i] = 0 | ||
32 | + deltha_y[i] = 0 | ||
33 | + deltha_z[i] = 0 | ||
34 | + angle = 0 | ||
35 | + angle_value = 0 | ||
36 | + | ||
37 | + | ||
38 | + | ||
39 | + for i in range(4): | ||
40 | + acceleration = drone.get_accelerometer() | ||
41 | + normal_x = 0 | ||
42 | + normal_y = 0 | ||
43 | + normal_z = 0 | ||
44 | + ac_x = acceleration.X | ||
45 | + ac_y = acceleration.Y | ||
46 | + ac_z = acceleration.Z | ||
47 | + | ||
48 | + normal_x = map(ac_x, -32768,32767,-5000,5000) | ||
49 | + normal_y = map(ac_y, -32768,32767,-5000,5000) | ||
50 | + normal_z = map(ac_z, -32768,32767,-5000,5000) | ||
51 | + deltha_x[1] = deltha_x[1]+(normal_x) | ||
52 | + deltha_y[1] = deltha_y[1]+(normal_y) | ||
53 | + deltha_z[1] = deltha_z[1]+(normal_z) | ||
54 | + | ||
55 | + deltha_x[1] = int(deltha_x[1]/4) | ||
56 | + deltha_y[1] = int(deltha_y[1]/4) | ||
57 | + deltha_z[1] = int(deltha_z[1]/4) | ||
58 | + | ||
59 | + | ||
60 | + | ||
61 | + for i in range(4): | ||
62 | + acceleration = drone.get_accelerometer() | ||
63 | + normal_x = 0 | ||
64 | + normal_y = 0 | ||
65 | + normal_z = 0 | ||
66 | + ac_x = acceleration.X | ||
67 | + ac_y = acceleration.Y | ||
68 | + ac_z = acceleration.Z | ||
69 | + | ||
70 | + normal_x = map(ac_x, -32768,32767,-5000,5000) | ||
71 | + normal_y = map(ac_y, -32768,32767,-5000,5000) | ||
72 | + normal_z = map(ac_z, -32768,32767,-5000,5000) | ||
73 | + deltha_x[2] = deltha_x[2]+(normal_x) | ||
74 | + deltha_y[2] = deltha_y[2]+(normal_y) | ||
75 | + deltha_z[2] = deltha_z[2]+(normal_z) | ||
76 | + | ||
77 | + deltha_x[2] = int(deltha_x[2]/4) | ||
78 | + deltha_y[2] = int(deltha_y[2]/4) | ||
79 | + deltha_z[2] = int(deltha_z[2]/4) | ||
80 | + | ||
81 | + deltha_x[0] = abs(deltha_x[1]-deltha_x[2]) | ||
82 | + deltha_y[0] = abs(deltha_y[1]-deltha_y[2]) | ||
83 | + deltha_z[0] = abs(deltha_z[1]-deltha_z[2]) | ||
84 | + deltha = deltha_x[0] + deltha_y[0] + deltha_z[0] | ||
85 | + print("AcX : ", deltha_x[0], "AcY : ", deltha_y[0], "AcZ : ", deltha_z[0] - 230, "Total : ", deltha) | ||
11 | 86 | ||
87 | + | ||
12 | if __name__ == '__main__': | 88 | if __name__ == '__main__': |
13 | main() | 89 | main() | ... | ... |
-
Please register or login to post a comment