This report instructs how to make the connection between a Pixhawk (all versions) and a Raspberry Pi 4 using the MAVLink Protocol to control the drone remotely and see it information.
The information below is valid only to the OS: Linux (recommend Ubuntu 20.04 or later).
SERIAL2_PROTOCOL = 1 (Mavlink 1 = 1 or Mavlink 2 = 2)
SERIAL2_BAUD = 921 (baud rate = 921600)
EKF2_AID_MASK = use optical flow only
CBRK_SUPPLY_CHK = no check
CBRK_USB_CHK = no check
MAV_0_CONFIG = TELEM 2
MAV_0_MODE = Onboard
MAV_0_RATE = 1200 B/s
COM_OBL_ACT = land
COM_OBL_RC_ACT = land
CBRK_IO_SAFETY = no check
Using jumpers, connect the TELEM 2 (Pixhawk) via USB-Serial adapter to an USB on the Raspberry Pi4. See the link below for more information:
https://dev.px4.io/master/en/companion_computer/pixhawk_companion.html#hardware-setup
3. Run the code below to see which USB port the Pixhawk is connected: $ lsusb
The device ID is important to the next step (the ID number is likely to change);
$ sudo nano /etc/udev/rules.d/99-pixhawk.rules
$ SUBSYSTEM=="tty", ATTRS{idVendor}=="HERE", ATTRS{idProduct}=="HERE", SYMLINK+="ttyPix4"
$ sudo apt-get install screen python-wxgtk3.0 python-matplotlib python-opencv python-pip python-numpy python-dev libxml2-dev libxslt-dev
$ sudo pip3 install future
$ sudo pip3 install pymavlink
$ sudo pip3 install mavproxy
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo reboot now (This step is necessary to compile all the changes)
$ sudo su
$ mavproxy.py --master=/dev/ttyPix4 --baudrate 921600 --out=udp:0.0.0.0:14550 --out=udp:0.0.0.0:14551 --aircraft MyCopter
("--aircraft" will be the folder to store the log files.)
$ sudo apt-get install ssh
or
$ sudo apt-get install openssh-client
$ raspi-config
$ sudo reboot now
$ sudo -H pip3 install mavproxy
$ sudo -H pip3 install dronekit
$ sudo -H pip3 install pymavlink
$ git clone https://github.com/dronekit/dronekit-python.git
13. Use the code magnetometer.py in the folder Examples/ to take the values of the magnetometer sensor as an example.
$ python3 mag_pix4.py --connect "0.0.0.0:14551"
https://docs.px4.io/v1.9.0/en/advanced_config/parameter_reference.html
https://dev.px4.io/master/en/companion_computer/pixhawk_companion.html#hardware-setup