-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_propulsion.py
108 lines (74 loc) · 2.98 KB
/
test_propulsion.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
from propulsion import Propulsion
from propulsion import PropulsionParams
def test_move_fwd(prop, **kwargs):
"""
Test Scenario: Application starts the propulsion system in the forward direction.
"""
print("Move FWD test...")
prop.forward(speed=100, **kwargs)
prop.stop()
def test_move_bwd(prop, **kwargs):
"""
Test Scenario: Application starts the propulsion system in the backward direction.
"""
print("Move BWD test...")
prop.backward(speed=100, **kwargs)
prop.stop()
def test_move_right(prop, **kwargs):
"""
Test Scenario: Application starts the propulsion system by generating right turn motion.
"""
print("Move Right test...")
prop.right(speed=100, **kwargs)
prop.stop()
def test_move_left(prop, **kwargs):
"""
Test Scenario: Application starts the propulsion system by generating left turn motion.
"""
print("Move Left test...")
prop.left(speed=100, **kwargs)
prop.stop()
def test(odisseus_configuration):
try:
print("============================")
print("Executing Propulsion Tests")
if odisseus_configuration.ON_RASP_PI:
import RPi.GPIO as GPIO
else:
from gpio_mock import GPIOMock as GPIO
# need to set the board mode before doing anything with the pins
GPIO.setmode(GPIO.BCM)
kwargs = {'time': 2}
params = PropulsionParams(in_pin_1_motor_1=odisseus_configuration.IN_PIN_1_MOTOR_1,
in_pin_2_motor_1=odisseus_configuration.IN_PIN_2_MOTOR_1,
en_pin_motor_1=odisseus_configuration.ENA_MOTOR_1_PIN_ID,
in_pin_1_motor_2=odisseus_configuration.IN_PIN_1_MOTOR_2,
in_pin_2_motor_2=odisseus_configuration.IN_PIN_2_MOTOR_2,
en_pin_motor_2=odisseus_configuration.ENA_MOTOR_2_PIN_ID)
prop = Propulsion(odisseus_config=odisseus_configuration, params=params)
test_move_fwd(prop=prop, **kwargs)
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
# since we called cleanup above we need to setup the pins again
prop.setup()
test_move_bwd(prop=prop, **kwargs)
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
# since we called cleanup above we need to setup the pins again
prop.setup()
test_move_right(prop=prop, **kwargs)
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
# since we called cleanup above we need to setup the pins again
prop.setup()
test_move_left(prop=prop, **kwargs)
print("Done Executing Propulsion Tests")
print("============================")
except Exception as e:
print("An exception occurred whilst running the test..." + str(e))
finally:
print("Cleaning up GPIO")
GPIO.cleanup()
if __name__ == '__main__':
from odisseus_config import odisseus_config_obj
test(odisseus_config_obj)