-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbluerov_interface.py
91 lines (75 loc) · 3.1 KB
/
bluerov_interface.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
from pymavlink import mavutil
import numpy as np
class BlueROV:
state = None
def __init__(self, mav_connection):
self.mav_connection = mav_connection
self.mav_connection.wait_heartbeat()
self.mav_connection.set_mode("MANUAL")
self.mav_connection.arducopter_arm()
self.mav_connection.motors_armed_wait()
self.state = "armed"
def disarm(self):
"""Disarm the ROV, wait for confirmation"""
self.mav_connection.arducopter_disarm()
self.mav_connection.motors_disarmed_wait()
self.state = "disarmed"
def arm(self):
"""Arm the ROV, wait for confirmation"""
self.mav_connection.arducopter_arm()
self.mav_connection.motors_armed_wait()
self.state = "armed"
def set_rc_channel(self, channel, pwm):
"""Set a single RC channel"""
rc_channel_values = [65535 for _ in range(18)]
rc_channel_values[channel - 1] = pwm
self.mav_connection.mav.rc_channels_override_send(
self.mav_connection.target_system,
self.mav_connection.target_component,
*rc_channel_values
)
def set_rc_channels(self, channels):
"""Set multiple RC channels at once
Args:
channels (dict): Dictionary of channel_id: pwm_value
"""
for channel, value in channels.items():
pwm_value = 1500 + value * 4
self.set_rc_channel(channel, pwm_value)
def set_rc_channels_to_neutral(self):
"""Set all RC channels to neutral (1500)"""
# set channels 0 to 18 to 1500 (neutral)
for i in range(0, 18):
self.set_rc_channel(i, 1500)
def set_longitudinal_power(self, value):
"""Set the longitudinal power channel"""
if value > 100 or value < -100:
print("Longitudinal power must be between -100 and 100")
print("Cliping value to -100 or 100")
value = np.clip(value, -100, 100)
pwm_value = 1500 + value * 4
self.set_rc_channel(5, pwm_value)
def set_lateral_power(self, value):
"""Set the lateral power channel"""
if value > 100 or value < -100:
print("Lateral power must be between -100 and 100")
print("Cliping value to -100 or 100")
value = np.clip(value, -100, 100)
pwm_value = 1500 + value * 4
self.set_rc_channel(6, pwm_value)
def set_vertical_power(self, value):
"""Set the vertical power channel"""
if value > 100 or value < -100:
print("Vertical power must be between -100 and 100")
print("Cliping value to -100 or 100")
value = np.clip(value, -100, 100)
pwm_value = 1500 + value * 4
self.set_rc_channel(4, pwm_value)
def set_yaw_rate_power(self, value):
"""Set the yaw rate power channel"""
if value > 100 or value < -100:
print("Yaw rate power must be between -100 and 100")
print("Cliping value to -100 or 100")
value = np.clip(value, -100, 100)
pwm_value = 1500 + value * 4
self.set_rc_channel(3, pwm_value)