GSoC 24: All in one system identification toolkit for ardupilot

Greetings everyone. My name is Astik Srivastava, and I’m an undergraduate engineering student from Delhi Technological University, India. I’ve been selected as a contributor for ArduPilot, for this year’s Google Summer of Code, with @iampete and @bnsgeyer as my mentors. I’m working on developing a system identification library for ardupilot vehicles, which allows identification of linear parametric models for the dynamics of these vehicles. These models can be used for certification purposes, controller gain optimization, performance evaluation, etc.

The project can be majorly divided into two parts:

  1. Library for model estimation: Currently, ArduCopter provides a system identification mode, which can insert frequency sweep chirps as inputs, in various location along the control loop. My job is to provide code that can analyze this input and resulting outputs (like body rates, accelerations) to estimate a model.
  • Progress made so far: We looked at multiple open source packages written in python, that can be used for system identification. I’ll be focusing the development on top of this repository: pyAircraftIden, which provides frequency domain estimation and allows us to define custom model structures, which can be taken from literature.
  1. Lua script for frequency sweep generation for ArduPlane: Unlike Copter, Plane does not have a dedicated mode for frequency chirp input. Hence, I’ve created a lua script that can be used to excite control surfaces in both open loop and closed loop settings (manual mode for open loop, stabilize/fbwa mode for closed loop).
  • Progress made so far: The pr for frequency sweep lua script can be found here: Even though basic script is working, modifications need to be done to ensure smooth transition, pilot controllability and safety of maneuvers.
  1. Web tool development for system identification: To ensure that users with varying technical backgrounds can use the library, I’m working with my mentors to build a web tool similar to UAVlogviewer, based on the work done by us on the system identification library
  • Progress made so far: We are trying to get the code working with pyodide, to allow python code to run in browser, completely on the client side.

I’ll be regularly updating my progress here. I request the community to provide suggestions on how we can make this project better.

Thank You!

10 Likes

Hi @Astik_Srivastava,

Welcome and thanks so much for the explanation of your project!

I hope you don’t mind but I’ve added an image to the top to make it more attractive when viewed from ardupilot.org. This is the output from feeding your blog into dall-e. Feel free to replace it with something else!

1 Like

To be honest I find this image quite bad due to various AI artifacts such as “bent” props, inconsistent landing gear and GNDN wires.

If I saw article with such image on the website I would likely skip it assuming the author didn’t put more effort into the content of the article than into the image.

Hi @LupusTheCanine,

well, you know… it’s just an image Dall-e came up with in a few seconds. Feel free to provide a better one!

An ArduPilot dev posted a nice system identification paper that he was working on with some colleages.
I can not find the post nor any links to it. Is there a place were such “ArduPilot relevant” papers are collected and kept?

Academic Works Involving ArduPilot — Dev documentation seams to not have been updated in a long time :frowning:

Here’s a link to @Astik_Srivastava final update for his GSOC project.

This is a huge step forward in providing a widely available system identification toolkit. Many thanks to Astik for his impressive work on this tool. Thanks to Pete Hall(@iampete) for co-mentoring this project.

1 Like

Greetings devs. In this post I attempt to make a tutorial/guide for how to use the system identification toolkit for transfer function and state space model estimation.

Since the toolkit is part of ardupilot webtools, it can be locally run on the system. The sysID toolkit is in the dev section of the webtool

Upon loading, the output screen looks as follows:


The model type that needs to be estimated can be selected from here and then after inputting the identification parameters, log file can be submitted.

State Space Identification
Upon clicking the statespace model a window as shown below appears:


The functions of parameters visible above are as follows:

  • Outputs: Number of output data fields that need to be taken from the log
  • Matrix A order: Order of matrix A. Order of state space matrix should be equal to number of states in your state space, with shape of A matrix being n X n. The matrix B will always have a shape n X 1, where n is the order of A.
  • Number of params: Number of unknown parameters in the state space matrices that need to be identified.
  • Number of constraints: Number of equality constraints required by the user. These constraints enforce the condition of two unknown params either always being equal to each other or negative of each other.
  • Start and End time: These are for specifying the start and end time of sysID experiment in the log. Only data between these times will be considered while estimation of the model.
  • Start and End frequency: Since current webtool relies on frequency response to estimate the system, the start and end frequency specify the region of frequency spectrum from which data will be considered. This should be chosen carefully to capture both short term and long term dynamics of the system.
  • LPF cutoff frequency: Before identification, the input and output data is passed through a low-pass-filter to remove noise. The desired cutoff frequency is inputted here.

Once these parameters are submitted, further parameters can be set:


This image shows an example value of parameters filled for identifying the roll state-space model of an x8 configuration UAV.
Upon submission, following parameters pop out:

The functions of parameters visible above are as follows:

  • Input: Msg name and field of input data
  • Output(n): Msg name and field for nth output
  • Multiplier: This is an optional field which can be used to multiply the data with a constant. This can be used for unit changes (for eg: SI to imperial)
  • Gravity Compensation: This is a special field for IMU acceleration data along roll and pitch axis. Since IMUs do not measure gravity, the effect of gravity component g*cos(angle) does not get reflected in imu data. To counter this, gravity compensation adds a gravity dependent term (g x theta x multiplier for roll axis or -g x theta x multiplier for pitch axis) to the acceleration data.
  • Param(n): Symbolic name to be assigned to nth unknown param
  • Bounds(n): The min and max value that the nth unknown parameter can take
  • Matrix A: System matrix with shape n X n, with n being the number of states. The known elements of matrices are given there respective values and unknown elements are given there respective symbolic names as inputs.
  • Matrix B: Control matrix with shape n X 1. Same principal as A for inputs
  • H0 and H1 matrices: These denote the relationship between frequency response variables and the states of the system. In above example, the statespace has four states [velocity_y (Uy), roll rate(p), roll angle(phi), motor lag(w)]. The H0 matrix denotes the states for which data is available. H1 matrix denotes the states whose first derivative data is available

After these parameters are set, the log can be uploaded and submitted.

Since we are currently using a python code running on browser using pyodide, a lot of capabilities of pyAircraftIden are limited, leading to very long solution times for large systems. This is something that I hope to change in future.

Once the processing is complete, the plots become available for comparing the original data and identified system:


The plot shows phase and amplitude fit for both the output values. The final model and numerical fit are displayed on the output screen.

Transfer function estimation
Transfer function estimation has a relatively simple setup and a less computationally expensive process. The output screen for tfestimation looks like this:


The function of each input block is as follows:

  • Input Msg and field: Msg type and field for input data
  • Output Msg and field: Msg type and field for output data
  • Start and End time: Denote the start and end time of the sysID experiment
  • Start and End frequency: Denote the region of frequency spectrum in which response is calculated
  • LPF cutoff frequency: Cutoff frequency of low pass filter
  • Numerator and Denominator polynomial: Since polynomial structure can be dynamic, users need to input the numerator and denominator polynomials, with s being the ‘S’ domain variable and other strings as coefficients. The polynomials need to be written in sympy polynomial syntax.
  • Symbolic params: Names of symbolic coefficients in the polynomials described above.

Upon setting these parameters, the transfer function estimation can be started by uploading the log file. TF estimation is still slower than MATLAB, but considerably faster than state space estimation and promises good results for good data. The output and plot window is same as for statespace estimation.

There is still a lot of work that can be done in this toolkit. I request the community to try it and share feedbacks, so we can work out the kinks and also focus on better solvers. Better solvers will enable the users to deal with nonlinear systems and MIMO systems, which is crucial for control engineers. I would like to thank @bnsgeyer and @iampete for there guidance and support during this project. I hope my work proves to be beneficial for ardupilot community. Looking forward to responses and feedbacks.

1 Like

Hello,it’s really a nice tool and I am trying to use it.But now I meet some problem.I run it as your guide , but when all parameters was setted I enter Submit.Output didn’t have any message shown.

Hello @LinXiangyu. You need to wait for 4-5 minutes for the transfer function solver to solve the identification problem. This is slow as we are running python code on browser, without multithreading support. Please let me know if you encounter any other problems

I’m pleased to report @Astik_Srivastava’s system ID tool is now live, it can be found here:

https://firmware.ardupilot.org/Tools/WebTools/SysID/

May thanks to @Astik_Srivastava for the work put in over the GSoC project, it was great having you as a student. Thanks also to @bnsgeyer for bringing his guidance and input on all things system ID.

Hopefully the tool will continue to evolve and improve in the future. If anyone wants to get stuck in the development setup documented here: GitHub - ArduPilot/WebTools

2 Likes

Thanks for you help, I have get my roll Axis by your tool. But Now I get a new problem ,when I use the model verification mode of the official ardupilot simulink model, the roll axis model I identify is completely inaccurate. Is it because I did not operate it properly during use? Or is the log I measured unreasonable?
This is my identification result and setting parameters and my test log. Thank you again.


Hi @LinXiangyu, thanks for trying out this new Web tool. I have a few questions to verify your set up to ensure that it is correct. What was the start (SID_F_START_HZ) and stop (SID_F_STOP_HZ) frequency of your system ID mode. Just remember that the frequencies you use in the system ID mode setup are in Hz and the frequencies requested in the webtool are in rad/s.

Also it would be better to use SIDD.Gx for the measured roll rate as it is not affected by any filtering by the INS or the PIDs.

Last, be sure that the start time and end time are within the Sydtem ID mode run time. If not you could get an error. you can open the log file in mission planner and look at the SIDS message which will have the start time in microseconds. Just convert that to seconds and add the length of the run to it to get the stop time.

In your case, the cost function given in the text that you have outlined in red is shown by “Solution: 2372”. Keep in mind when using this tool is that if your cost function is not less than 100 then the solution is poor. Generally a cost function less than 100 indicates a good solution and less than 50 indicates an excellent solution.

2 Likes

Here is a more detailed video that explains how to use the system identification web tool.

2 Likes

This is a great guide Bill. It’ll definitely make the tool more accessible👍

1 Like