-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathdance_template.py
63 lines (56 loc) · 1.81 KB
/
dance_template.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
from motor_test import test_motor
import time
from pymavlink import mavutil
def arm_rov(mav_connection):
"""
Arm the ROV, wait for confirmation
"""
mav_connection.arducopter_arm()
print("Waiting for the vehicle to arm")
mav_connection.motors_armed_wait()
print("Armed!")
def disarm_rov(mav_connection):
"""
Disarm the ROV, wait for confirmation
"""
mav_connection.arducopter_disarm()
print("Waiting for the vehicle to disarm")
mav_connection.motors_disarmed_wait()
print("Disarmed!")
def run_motors_timed(mav_connection, seconds: int, motor_settings: list) -> None:
"""
Run the motors for a set time
:param mav_connection: The mavlink connection
:param time: The time to run the motors
:param motor_settings: The motor settings, a list of 6 values -100 to 100
:return: None
"""
step = 0
while step < seconds:
for i in range(len(motor_settings)):
test_motor(mav_connection=mav_connection, motor_id=i, power=motor_settings[i])
time.sleep(0.2)
step += 0.2
if __name__ == "__main__":
####
# Initialize ROV
####
mav_connection = mavutil.mavlink_connection('udpin:0.0.0.0:14550')
mav_connection.wait_heartbeat()
# Arm the ROV and wait for confirmation
arm_rov(mav_connection)
####
# Run choreography
####
"""
Call sequence of calls to run_timed_motors to execute choreography
Motors power ranges from -100 to 100
"""
run_motors_timed(mav_connection, seconds=5, motor_settings=[100,-100 ,100 ,-100, 0, 0])
run_motors_timed(mav_connection, seconds=5, motor_settings=[-100,100 ,-100 ,100, 0, 0])
# stop
run_motors_timed(mav_connection, seconds=5, motor_settings=[0, 0, 0, 0, 0, 0])
####
# Disarm ROV and exit
####
disarm_rov(mav_connection)