Table of Contents:
- Fault Tolerant Control of Unmanned Aerial Vehicles (UAVs)
- Python code
- trajectory-healthy.py - For a normal trajectory
- trajectory-faulty.py - For a motor fault induced during normal trajectory
- print_save_gps.py - For reading GPS sensor data during a flight
- MATLAB code
- read_dataset.m - For reading a dataset file and making sense of it
- Generated datasets
- prototype-set-1 - (Prototyped) Propellor fault data is logged for 2 different use-cases (hover and go in a straight line) with multiple props (5mm, 10mm, 20mm, 25mm, 40mm). This dataset also contains the compressed flight testing videos of each scenario.
- simulation-set-1 - (Simulated) Motor fault data is logged for 4 different drone frames (Quad+, QuadX, Hexa+, HexaX)
-
Python 3.8
-
SITL (preferred) OR Actual drone
(This needs to have the SERVOn_FUNCTION parameters; which are missing in the PX4 firmware, but available on the ArduPilot firmware)
- Pixhawk hardware running ArduPilot (and not PX4) firmware. Should also contain SERVOn_FUNCTION params.
- OR the official ArduPilot SITL. You can read more about setting up SITL here.
-
Ground Station software
- APM Planner - Install guide
- OR QGroundControl - Install guide
-
MAVExplorer.py - Install guide (MAVExplorer can be used for generating graphs from log files)
- Clone this repository
- Open the repository project in your IDE, or cd your command prompt to the directory
- Run
pip install -r requirements.txt
(Python 2),
orpip3 install -r requirements.txt
(Python 3)
in the command prompt - (Optional for Windows) You need the
<Your Drive>/ArduPilot/Tools/autotest/
folder in your $PATH Environment Variable. This folder contains thesim_vehicle.py
file. Alternatively, to run the simulation, you can cd to this directory and run thesim_vehicle.py
file whenever needed.
Drone simulation without any faults (trajectory-healthy.py)
- Run the SITL simulator
sim_vehicle.py -v ArduCopter
- Run the ground station software (APM/QGC) (if it already isn't running)
- Wait for a few seconds for SITL to connect to the ground station
In case the ground station does not directly connect to the SITL, you can manually try connecting to127.0.0.1
on ports 14450, 14451, 5760 over UDP. - Open
trajectory-healthy.py
in case you want to edit; or directly run it
python trajectory-healthy.py
- (Optional) In case your code does not connect to the SITL, you might want to change the connection_string value. This can be done by passing an argument, or by modifying the value in code.
- Code will automatically exit on completion
- You can download the log file from SITL as mentioned here
- (Optional) You can generate graphs from this log file by running
MAVExplorer.py <path-to-log-file>.log
Drone simulation with faulty motor(s) (trajectory-faulty.py)
- Run the SITL simulator
sim_vehicle.py -v ArduCopter
- Run the ground station software (APM/QGC) (if it already isn't running)
- Wait for a few seconds for SITL to connect to the ground station
In case the ground station does not directly connect to the SITL, you can manually try connecting to127.0.0.1
on ports 14450, 14451, 5760 over UDP. - Open
trajectory-faulty.py
in case you want modify which motors should stop working:- Line 99 - In case of QuadCopter simualtion, keep the next two lines commented. In case of HexaCopter simualtion, uncomment the next two lines.
- Line 146 - Use
set_motor_mode(MOTOR_NUMBER, FUNCTION)
function to set a value of 1 for all the motors you wish to override (in flight, by overtaking control from the AutoPilot code) - Line 149 - Use
set_servo(MOTOR_NUMBER, PWM_VALUE)
function to send a PWM signal to one of the overridden (in previous step) motors. This will not work if the motor is still in control with the AutoPilot. (i.e. if previous step is skipped)
- Run
python trajectory-faulty.py
- (Optional) In case your code does not connect to the SITL, you might want to change the connection_string value. This can be done by passing an argument, or by modifying the value in code.
- Code will automatically exit on completion
- You can download the log file from SITL as mentioned here
- (Optional) You can generate graphs from this log file by running
MAVExplorer.py <path-to-log-file>.log
Read a Dataset in MATLAB (read_dataset.m)
Logic for the MATLAB file is as follows:
- Opens relevant dataset such as
m1.mat
- Sets which variables (log outputs) are to be read from the file. e.g.
{AHR2,PARM}
. Note that log outputs are priority based and each module (gyro, baro, ekf, ...) has its own update frequency for generating a log entry. - Searches the last occourence of our override code, in the
PARM
array inside the dataset. - Stores the Timestamp (TimeUS) in microseconds, for receipt of the last override packet found in the dataset.
- Now, the code selects the dataset array to be studied. Barometer altitude, in this case.
- Finds the Timestamp in Barometer array, which is nearest to the Timestamp of the override.
- Stores Timestamp key and value for Barometer array
- Plots graph of the Barometer Altitude values, starting from the Timestamp chosen in last step.
Steps to run:
- Open the
read_dataset.m
file in MATLAB - Make sure the
read_dataset.m
file and thedist
folder are added to the MATLAB current path- You can do this by simply right-clicking on the file/folder in the file manager (on left side panel) and selecting Add to Path > Selected Folders and Subfolders
- You can modify the required parameters in file
- filename - Path to the dataset file, dist/set-1/quad-x/m1.mat in the example
- varsToRead - Array of modules to read from dataset. You can directly load the .mat file in your workspace in order to see all possible combinations of dataset arrays you can choose here/ import here.
- searchParam - Parameter to search. In our case, the fault is introduced using SERVO1_FUNCTION. This will be SERVO2_FUNCTION, SERVO3_... and so on for other motors. searchParam variable is used and the last use occurence is found, for the param.
- selectedArray - Your choice of array (from varsToRead), on which you want to work/ play around.
- Run the
read_dataset.m
file
Read GPS data during flight (print_save_gps.py)
- Start by going to ardupilot/ArduCopter and running sim_vehicle.py --map
- Then in other termininal going to myexamples and running print_gps.py
- Python print_gps.py –connect 127.0.0.1:14551
- Wait for sitl drone to stop/ get in RTL mode
- Data will be printed in terminal as well as in the gps_data.csv
pip3 uninstall pymavlink cd PX4-Autopilot/src/modules/mavlink/mavlink/pymavlink python setup.py install --user