-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcalculations.py
78 lines (64 loc) · 2.53 KB
/
calculations.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
# BAD_MOTOR_LIMIT is how much off a motor can be compared to
# the rest, in percentage. Default is 15%.
BAD_MOTOR_LIMIT = 15
class Calculate:
""" Has all basic arithmetic calculations and conversions """
@staticmethod
def motor_fill(motor_values):
"""
The pwm callback from the motors is a value from 0-65535.
This now maps it to a value corresponding to 0-60, which
is needed to fill the visual canvas item object.
"""
return [ int((val / 65535) * 60) for val in motor_values ]
@staticmethod
def motor_text(motor_values):
"""
The pwm callback from the motors is a value from 0-65535.
This is mapped to 0-100, which corresponds to the percentage thrust
"""
return [ int((val / 65535) * 100) for val in motor_values ]
@staticmethod
def battery(battery):
"""
The battery TOC is mapped to fill its corresponding voltage,
in a green rectangle, and to a 1-decimal text string.
"""
b_text = round((battery / 1000), 1)
b_fill = int(battery / 4200 * 215)
return b_text, b_fill
@staticmethod
def row_and_col(uris):
""" Calculates row and columns, given all the uris """
row = int(len(uris) / 3)
column = len(uris) % 3
return row, column
@staticmethod
def propeller_result(motorlog):
""" Returns results in readable form from the propeller test """
binary = '{0:04b}'.format(motorlog)
motors = [binary[3], binary[2], binary[1], binary[0]]
results = ["GOOD" if motor=="1" else "BAD" for motor in motors]
colors = ['green' if result=='GOOD' else 'red' for result in results]
return results, colors
@staticmethod
def new_placements(i):
""" Returns new row and column """
return int(i / 3), i % 3
@staticmethod
def is_mean_ok(means):
"""
Returns results from the Hover test. If the motorthrust if under
20% off from the rest, they are considered good.
"""
means = [((mean / 65535) * 100) for mean in means]
average = (sum(means) / 4)
motor_results = []
for mean in means:
if abs(mean - average) > BAD_MOTOR_LIMIT:
motor_results.append('0')
else:
motor_results.append('1')
results = ["GOOD" if motor=="1" else "BAD" for motor in motor_results]
colors = ['green' if result=='1' else 'red' for result in motor_results]
return results, colors