-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_trivial_model.py
61 lines (47 loc) · 1.96 KB
/
test_trivial_model.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
from math import atan
import unittest
import mavlink_all as mavlink
from utils.model_utils import STD_G
from trivial_model import Controls, simulate, MAX_ANGLE
# pyright: reportUntypedBaseClass=false
class TestSimulate(unittest.TestCase):
def default_state(_):
return mavlink.MAVLink_sim_state_message(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0 ,0 ,0 ,0 ,0, 0, 0, 0, 0)
def test_zero(self):
previous_state = self.default_state()
state = simulate(previous_state, Controls(), 0.1)
self.assertEqual(state.xacc, 0.0)
self.assertEqual(state.yacc, 0.0)
self.assertEqual(state.zacc, -STD_G)
def test_forward(self):
"""
Lean the vehicle forward (nose down)
"""
previous_state = self.default_state()
controls = Controls()
controls.pitch = 1.0
state = simulate(previous_state, controls, 0.1)
# controls is positive for stick forward, pitch is positive for nose up
self.assertEqual(state.pitch, -MAX_ANGLE)
# with nose down, the gravity is like accelerating up and back
self.assertLess(state.xacc, 0)
self.assertEqual(state.yacc, 0)
self.assertLess(state.zacc, 0)
# maximum tilt was used
self.assertAlmostEqual(atan(state.xacc / state.zacc), MAX_ANGLE, 2)
def test_right(self):
"""
Lean the vehicle to the right
"""
previous_state = self.default_state()
controls = Controls()
controls.roll = 1.0
state = simulate(previous_state, controls, 0.1)
# controls is positive for stick right, roll is positive to right
self.assertEqual(state.roll, MAX_ANGLE)
# with right wing down, the gravity is like accelerating up and left
self.assertEqual(state.xacc, 0)
self.assertLess(state.yacc, 0)
self.assertLess(state.zacc, 0)
# maximum tilt was used
self.assertAlmostEqual(atan(state.yacc / state.zacc), MAX_ANGLE, 2)