-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmavlink.py
More file actions
39 lines (31 loc) · 1011 Bytes
/
mavlink.py
File metadata and controls
39 lines (31 loc) · 1011 Bytes
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
"""
Pipe MAVLink telemetry into Plexus.
Prereq:
pip install plexus-python pymavlink
export PLEXUS_API_KEY=plx_xxx
Run:
python mavlink.py udpin:0.0.0.0:14550
"""
import sys
from pymavlink import mavutil
from plexus import Plexus
conn_str = sys.argv[1] if len(sys.argv) > 1 else "udpin:0.0.0.0:14550"
px = Plexus(source_id="drone-001")
conn = mavutil.mavlink_connection(conn_str)
conn.wait_heartbeat()
while True:
msg = conn.recv_match(blocking=True)
if msg is None:
continue
t = msg.get_type()
if t == "ATTITUDE":
px.send("attitude.roll", msg.roll)
px.send("attitude.pitch", msg.pitch)
px.send("attitude.yaw", msg.yaw)
elif t == "GLOBAL_POSITION_INT":
px.send("gps.lat", msg.lat / 1e7)
px.send("gps.lon", msg.lon / 1e7)
px.send("gps.alt_m", msg.alt / 1000.0)
elif t == "SYS_STATUS":
px.send("battery.voltage", msg.voltage_battery / 1000.0)
px.send("battery.current", msg.current_battery / 100.0)