Skip to content

AdityaMulgundkar/rrc_fault_tolerant_control

Repository files navigation

Fault Tolerant Control of Unmanned Aerial Vehicles (UAVs)

Table of Contents:

What this repository contains?

  • Python code
  • MATLAB code
  • 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)

Getting started with code

Pre-requisites

  • 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)

  • Ground Station software

  • MAVExplorer.py - Install guide (MAVExplorer can be used for generating graphs from log files)

Setting up

  • 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),
    or pip3 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 the sim_vehicle.py file. Alternatively, to run the simulation, you can cd to this directory and run the sim_vehicle.py file whenever needed.

Run a sample code

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 to 127.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
  • 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 to 127.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
  • 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:

  1. Opens relevant dataset such as m1.mat
  2. 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.
  3. Searches the last occourence of our override code, in the PARM array inside the dataset.
  4. Stores the Timestamp (TimeUS) in microseconds, for receipt of the last override packet found in the dataset.
  5. Now, the code selects the dataset array to be studied. Barometer altitude, in this case.
  6. Finds the Timestamp in Barometer array, which is nearest to the Timestamp of the override.
  7. Stores Timestamp key and value for Barometer array
  8. 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 the dist 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

Custom MAVLINK builds

pip3 uninstall pymavlink cd PX4-Autopilot/src/modules/mavlink/mavlink/pymavlink python setup.py install --user

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published