-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtest_power_distribution.py
210 lines (159 loc) · 5.39 KB
/
test_power_distribution.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env python
import cffirmware
def test_power_distribution_legacy_for_hover():
# Fixture
control = cffirmware.control_t()
control.thrust = 10
control.roll = 0
control.pitch = 0
control.yaw = 0
control.controlMode = cffirmware.controlModeLegacy
actual = cffirmware.motors_thrust_uncapped_t()
# Test
cffirmware.powerDistribution(control, actual)
# Assert
assert actual.motors.m1 == control.thrust
assert actual.motors.m2 == control.thrust
assert actual.motors.m3 == control.thrust
assert actual.motors.m4 == control.thrust
def test_power_distribution_legacy_for_roll():
# Fixture
control = cffirmware.control_t()
control.thrust = 0
control.roll = 10
control.pitch = 0
control.yaw = 0
control.controlMode = cffirmware.controlModeLegacy
actual = cffirmware.motors_thrust_uncapped_t()
# Test
cffirmware.powerDistribution(control, actual)
# Assert
assert actual.motors.m1 == -control.roll / 2
assert actual.motors.m2 == -control.roll / 2
assert actual.motors.m3 == control.roll / 2
assert actual.motors.m4 == control.roll / 2
def test_power_distribution_legacy_for_pitch():
# Fixture
control = cffirmware.control_t()
control.thrust = 0
control.roll = 0
control.pitch = 12
control.yaw = 0
control.controlMode = cffirmware.controlModeLegacy
actual = cffirmware.motors_thrust_uncapped_t()
# Test
cffirmware.powerDistribution(control, actual)
# Assert
assert actual.motors.m1 == control.pitch / 2
assert actual.motors.m2 == -control.pitch / 2
assert actual.motors.m3 == -control.pitch / 2
assert actual.motors.m4 == control.pitch / 2
def test_power_distribution_legacy_for_yaw():
# Fixture
control = cffirmware.control_t()
control.thrust = 0
control.roll = 0
control.pitch = 0
control.yaw = 20
control.controlMode = cffirmware.controlModeLegacy
actual = cffirmware.motors_thrust_uncapped_t()
# Test
cffirmware.powerDistribution(control, actual)
# Assert
assert actual.motors.m1 == control.yaw
assert actual.motors.m2 == -control.yaw
assert actual.motors.m3 == control.yaw
assert actual.motors.m4 == -control.yaw
def test_power_distribution_force_torque():
# Fixture
control = cffirmware.control_t()
control.thrustSi = 0.1
control.torqueX = 0
control.torqueY = 0
control.torqueZ = 0
control.controlMode = cffirmware.controlModeForceTorque
actual = cffirmware.motors_thrust_uncapped_t()
# Test
cffirmware.powerDistribution(control, actual)
# Assert
# For now only check that we get a non zero output
assert actual.motors.m1 > 0
assert actual.motors.m2 > 0
assert actual.motors.m3 > 0
assert actual.motors.m4 > 0
def test_power_distribution_cap_when_in_range():
# Fixture
input = cffirmware.motors_thrust_uncapped_t()
input.motors.m1 = 1000
input.motors.m2 = 2000
input.motors.m3 = 3000
input.motors.m4 = 4000
actual = cffirmware.motors_thrust_pwm_t()
# Test
cffirmware.powerDistributionCap(input, actual)
# Assert
# control.thrust will be at a (tuned) hover-state
assert actual.motors.m1 == input.motors.m1
assert actual.motors.m2 == input.motors.m2
assert actual.motors.m3 == input.motors.m3
assert actual.motors.m4 == input.motors.m4
def test_power_distribution_cap_when_all_negative():
# Fixture
input = cffirmware.motors_thrust_uncapped_t()
input.motors.m1 = -1000
input.motors.m2 = -2000
input.motors.m3 = -3000
input.motors.m4 = -4000
actual = cffirmware.motors_thrust_pwm_t()
# Test
cffirmware.powerDistributionCap(input, actual)
# Assert
assert actual.motors.m1 == 0
assert actual.motors.m2 == 0
assert actual.motors.m3 == 0
assert actual.motors.m4 == 0
def test_power_distribution_cap_when_all_above_range():
# Fixture
input = cffirmware.motors_thrust_uncapped_t()
input.motors.m1 = 0xffff + 1
input.motors.m2 = 0xffff + 1
input.motors.m3 = 0xffff + 1
input.motors.m4 = 0xffff + 1
actual = cffirmware.motors_thrust_pwm_t()
# Test
cffirmware.powerDistributionCap(input, actual)
# Assert
assert actual.motors.m1 == 0xffff
assert actual.motors.m2 == 0xffff
assert actual.motors.m3 == 0xffff
assert actual.motors.m4 == 0xffff
def test_power_distribution_cap_reduces_thrust_equally_much():
# Fixture
input = cffirmware.motors_thrust_uncapped_t()
input.motors.m1 = 0xffff + 1
input.motors.m2 = 0xffff + 5
input.motors.m3 = 0xffff + 10
input.motors.m4 = 0xffff + 15
actual = cffirmware.motors_thrust_pwm_t()
# Test
cffirmware.powerDistributionCap(input, actual)
# Assert
assert actual.motors.m1 == 0xffff - 14
assert actual.motors.m2 == 0xffff - 10
assert actual.motors.m3 == 0xffff - 5
assert actual.motors.m4 == 0xffff - 0
def test_power_distribution_cap_reduces_thrust_equally_much_with_lower_cap():
# Fixture
input = cffirmware.motors_thrust_uncapped_t()
input.motors.m1 = 0
input.motors.m2 = 5
input.motors.m3 = 1000
input.motors.m4 = 0xffff + 10
actual = cffirmware.motors_thrust_pwm_t()
# Test
cffirmware.powerDistributionCap(input, actual)
# Assert
assert actual.motors.m1 == 0
assert actual.motors.m2 == 0
assert actual.motors.m3 == 1000 - 10
assert actual.motors.m4 == 0xffff