python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt- Create a
MAVDeviceobject to connect to the drone
from mavcore import MAVDevice
udp_device = MAVDevice("udp:127.0.0.1:14550")
serial_device = MAVDevice("/dev/ttyACM0")- Add listeners to monitor telemetry
from mavcore.messages import Heartbeat, LocalPositionNED
# Monitors heartbeat and local position
heartbeat = device.add_listener(Heartbeat())
local_pos = device.add_listener(LocalPositionNED())
while True:
print(heartbeat)
print(local_pos.vx)- Run protocols
from mavcore.protocols import HeartbeatProtocol, SetModeProtocol
from mavcore.messages import FlightMode
# Sends periodic heartbeats from device and sets mode
hb_protocol = device.run_protocol(HeartbeatProtocol()) # will auto send at 1 hz
set_guided = device.run_protocol(SetModeProtocol(FlightMode.GUIDED))- Create a class for your message in the
messagesfolder - Inherit from the
MAVMessageclass - In the
super().__init__make sure to pass in the name of the message that is the same it appears in the mavlink documentation all caps seperated by _ - If you want this message to be able to be recieved from the flight controller, override the
decodefunction - If you want this message to be able to be sent to the flight controller, override the
encodefunction - (Optional) Override the
__repr__function to assist in debugging
Not necessary if you are only receiving a particular message, but neccessary if you want to send something
- Create a class for your protocol in the
protocolsfolder. For convention append "Protocol" to the end of the name. - Override the
runfunction usingsender.send_msgandreceiver.wait_for_msgwithMAVMessageto build your protocol
After you have installed the SITL
- In one terminal launch the SITL. The coords below launch at the ARC main field west. Give this 2 minutes to load, it should begin listening on UDP Port 14550.
cd simcore
./sitl_setup.sh 33.64293210548397 -117.82628818855002- In order to connect your script, instantiate your
MAVDeviceas follows
device = MAVDevice("udp:127.0.0.1:14550")- If you want to perform commands on the drone thats not in your script go back to the terminal you started up the sitl in. It is interactive and you can issue mavproxy commands to it.
Just press
entera couple times on the terminal to see the mavproxy vehicle mode prefix.
NOTE: When running on the SITL, mavproxy automatically sends message interval requests for several messages. This means you may see messages published during your script in the SITL that don't appear when testing in person on a real flight controller. Remember to double check your message requests.