Skip to content

Commit

Permalink
fix mavlink on pi
Browse files Browse the repository at this point in the history
  • Loading branch information
misko committed Mar 4, 2024
1 parent adf5d28 commit ebb6b98
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[Unit]
Type=simple
Description=Run mavlink controller
After=multi-user.target

[Service]
WorkingDirectory=/home/pi/
User=pi
Group=pi
Environment=PYTHONPATH=/home/pi/spf/
ExecStart=/home/pi/spf-virtualenv/bin/python3 /home/pi/spf/spf/mavlink/mavlink_controller.py --serial /dev/ttyACM2
ExecStart=/home/pi/spf-virtualenv/bin/python3 /home/pi/spf/spf/mavlink/mavlink_controller.py --serial /dev/serial/by-id/usb-ArduPilot*

[Install]
WantedBy=multi-user.target
8 changes: 8 additions & 0 deletions spf/mavlink/mavlink_controller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Import mavutil
import argparse
import glob
import logging
import math
import signal
Expand Down Expand Up @@ -578,6 +579,13 @@ def set_mode(self, mode):
print("WTF")
# Create the connection
# Need to provide the serial port and baudrate
if args.serial == "" and args.ip == "":
available_pilots = glob.glob("/dev/serial/by-id/usb-ArduPilot*")
if len(available_pilots) != 1:
logging.error(f"Strange number of autopilots found {len(available_pilots)}")
sys.exit(1)
args.serial = available_pilots[0]

logging.info("Connecting...")
if args.serial != "":
connection = mavutil.mavlink_connection(args.serial, baud=115200)
Expand Down

0 comments on commit ebb6b98

Please sign in to comment.