-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmavControlTel_single.py
67 lines (58 loc) · 2.08 KB
/
mavControlTel_single.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
import asyncio
from mavsdk import System
from mavsdk.offboard import OffboardError, ActuatorControl
async def send_proof_of_life(drone):
print("Sending proof of life signal")
try:
await drone.offboard.set_actuator_control(ActuatorControl([0.0] * 8))
except OffboardError as error:
print(f"Error: {error}")
except Exception as e:
print(f"Unexpected error: {e}")
async def send_command(drone):
throttle = 0.5
roll = 0.5
pitch = 0.5
yaw = 0.5
try:
print(f"Sending throttle: {throttle}, roll: {roll}, pitch: {pitch}, yaw: {yaw}")
await drone.offboard.set_actuator_control(
ActuatorControl([
throttle, # Channel 1, RC_MAP_THROTTLE
roll, # Channel 2, RC_MAP_ROLL
pitch, # Channel 3, RC_MAP_PITCH
yaw, # Channel 4, RC_MAP_YAW
0.0, # Channel 5 -- auxiliary
0.0, # Channel 6 -- auxiliary, RC_MAP_FLTMODE
1.0, # Channel 7 -- auxiliary, RC_MAP_OFFB_SW
0.0 # Channel 8 -- auxiliary
])
)
except OffboardError as error:
print(f"Error: {error}")
except Exception as e:
print(f"Unexpected error: {e}")
async def request_sensor_data(drone):
async for health in drone.telemetry.health():
print(f"Health: {health}")
break
async def run():
drone = System()
# Connect to the Pixhawk via telemetry radio on /dev/ttyUSB0
await drone.connect(system_address="serial:///dev/ttyUSB0:57600")
print("Waiting for drone to connect...")
async for state in drone.core.connection_state():
if state.is_connected:
print("Drone connected!")
break
try:
# Start offboard mode
await drone.offboard.start()
except OffboardError as error:
print(f"Error starting offboard mode: {error}")
return
await send_proof_of_life(drone)
await send_command(drone)
await request_sensor_data(drone)
if __name__ == "__main__":
asyncio.run(run())