Jetpack sd card image. Linux 18.04 LTS.
SSH using MobaXterm
Linux commands from Command Line Interface (CLI)
PyCharm IDE and Python 3 programming.
Mission Planner and Pixhawk connection established.
Download the github using the link below….
(not available yet)
Create an operating system (OS)
Follow the link below to flash a micro sd with the nano image.
Connect your Nano to your wi-fi and get your IP address.
We’ll connect remotely to the Nano with SSH.
Update your Operating System packages. Enter the following command from the Linux command Line interface.
sudo apt-get update -y && sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y
Connect Pixhawk to Nano.
The pinouts for the Nano are exactly the same for the raspberry pi as shown below.
The pinouts are the same, remember the nano pins are located in a different rotation on the board.
The ‘jst’ plastic connectors are very flimsy. Always make sure the connections are working. They are usually the source of most hardware and software connection issues.
(Add pinout table)
SMOKE GENIE WARNING
With regards to powering the Pixhawk and Nano. We found that if power is supplied from the pixhawk only, the nano will shutdown after a few seconds. There is probably a power supply issue.
At present we ONLY power the Nano using the barrell port from mains power.
The pixhawk power is delivered via the hardwired connection as shown above. We DO NOT supply power to the pixhawk AND Nano, just the Nano.
Check Mission Planner Settings.
In Mission planner, go to ‘Config/Tuning’ screen and select ‘Standard Params’.
Now press ‘Ctrl + F’ and search for ‘serial2’.
Set the Serial2_BAUD to ‘57600’ and set the SERIAL2_PROTOCOL to ‘Mavlink2’.
The baud rate set here must be the same as the baud rate used later when using Maxproxy and Dronekit.
Check the connection is successful.
Now test to see if data is coming thru from the Pixhawk. Power up the system via the Nano.
SSH into the Nano and enter the following command in linux.
sudo cat /dev/ttyTHS1
You will need to use sudo every time you access the ttyTHS1 file as it needs root permission.
If your connection is working you should see encrypted data streaming on your screen. (To stop, press Ctrl + C)
If a linux command prompt has returned immediately, you’re connection is not working.
Check all of your connections, especially the jst connections into the Pixhawk.
Check all of the lights on your devices are working. Check your mission planner software is working to ensure the pixhawk is functioning.
Now install pip3 to install the python 3 packages.
sudo apt install python3-pip
MavProxy is used to translate data received by the Nano from the PixHawk.
MavProxy and DroneKit DO NOT run at the same time.
The adrupilot instructions create an autorun script to start MavProxy on startup. We see no need for this.
However you may choose to create an autorun script for your final python 3 code using dronekit.
There are two methods to install MavProxy. If Method A does not work try Method B.
Install mavproxy – method A.
Click the link below for the MavProxy PyPi home page. Follow the instructions there. (Use pip3 to install for python3 and not pip.)
pip3 install MAVProxy
Install mavproxy – method B. (if method A fails)
sudo apt-get update sudo apt-get install screen python-matplotlib python-opencv python-numpy python-dev libxml2-dev libxslt1-dev python-lxml sudo pip3 install future sudo pip3 install pymavlink sudo pip3 install mavproxy
Open Mission Planner and connect to your vehicle.
Run MavProxy from the Linux CLI.
The master argument must be exactly as shown.
The baudrate must be the same as your baudrate in Mission planner (Serial 2 settings, not the COM settings on the main screen.).
NOTE: For Pixhawk 4 cube, try a baud rate of 115200.
The aircraft argument can be anything you choose. This is a folder created to store the files.
sudo mavproxy.py --master=/dev/ttyTHS1 --baudrate 57600 --aircraft RoverMaxx
If successful, you should see the following. (Be patient, it takes time to connect and retrieve data.)
Test Mavproxy connection
If your Mavproxy connection is working you should be able to send commands between Mavproxy and Mission Planner and see a change on both programs.
In Mavproxy type ‘mode manual’ or ‘mode hold’. The mode in Mission Planner should change.
There is no prompt in Mavproxy, just a square cursor. Just enter your command.
Change the Mode in Mission Planner from ‘Manual’ to ‘Hold’. Mavproxy should show the change.
We followed the instructions in the following link.
Dronekit-sitl is a simulator. If you are connected to a Pixhawk you do not need to run the simulation package.
Dronekit is a standalone library, it does not need Mavlink or Dronekit-sitl to be operating at the same time.
Enter the following Linux commands to install Dronekit for Python 3.
sudo apt-get install libxml2-dev libxslt1-dev
pip3 install dronekit pip3 install dronekit-sitl
Test the installation worked.
pip3 freeze | grep dronekit
Run Dronekit in Python 3
We followed the instruction in the following link. The code on their page is for Python 2. You may need to make some syntax changes for Python 3.
Open a Python 3 editor. We use PyCharm IDE and execute the program from the linux command line interface.
from dronekit import connect # Connect to the Vehicle vehicle = connect('/dev/ttyTHS1', wait_ready=True, baud=57600) # vehicle is an instance of the Vehicle class print('Autopilot Firmware version: %s' % vehicle.version) print('Autopilot capabilities (supports ftp): %s' % vehicle.capabilities.ftp) print('Global Location: %s' % vehicle.location.global_frame) print('Global Location (relative altitude): %s' % vehicle.location.global_relative_frame) print('Local Location: %s' % vehicle.location.local_frame) #NED print('Attitude: %s' % vehicle.attitude) print('Velocity: %s' % vehicle.velocity) print('GPS: %s' % vehicle.gps_0) print('Groundspeed: %s' % vehicle.groundspeed) print('Airspeed: %s' % vehicle.airspeed) print('Gimbal status: %s' % vehicle.gimbal) print('Battery: %s' % vehicle.battery) print('EKF OK?: %s' % vehicle.ekf_ok) print('Last Heartbeat: %s' % vehicle.last_heartbeat) print('Rangefinder: %s' % vehicle.rangefinder) print('Rangefinder distance: %s' % vehicle.rangefinder.distance) print('Rangefinder voltage: %s' % vehicle.rangefinder.voltage) print('Heading: %s' % vehicle.heading) print('Is Armable?: %s' % vehicle.is_armable) print('System status: %s' % vehicle.system_status.state) print('Mode: %s' % vehicle.mode.name) # settable print('Armed: %s' % vehicle.armed) # settable
We saved the Python 3 file as Xmaxx.py
To execute the python 3 code, Enter the following in Linux.
sudo python3 Xmaxx.py
Congratulations! You can now control your vehicle with Python 3.
This is the end of the tutorial, you should be able to follow the instructions on the Dronekit site now.
Control your vehicle with Dronekit.
Now that you can control your vehicle with Python3, you can now follow the commands in the Dronekit site. Just remember to convert the code for Python 3 compatibility.
Did it work for you?
If this tutorial didnt work for you, please let us know what didn’t work and we’ll try to help you.