UAV Flight Model Validation, Trim and Linearization using Matlab

In case anyone here is using Matlab and Simulink to test or develop UAVs and UAV autopilots I am posting a link to a new flight dynamic model SFunction for use with Simulink-


The project enables any JSBSim flight dynamic model to be run within Simulink.  It also has a trim utility as well as a linearization utility that prints formatted, de-coupled state space matrices to the command window.  This makes it extremely useful for flight control or autopilot design. An eigenvalue analysis is also performed after the linearization.


The project is open-source and all the source code is included with the project download.  It has been tested with Matlab R2008b and R2010a.  Currently there is an issue with R2010a that causes the resulting trimmed control inputs to be slightly off- hopefully we can get this fixed soon.  Pre-compiled MEX files exist for win64/32 currently, with Mac OS and hopefully Linux versions in hte near future.


Happy downloading!

Views: 4862

Reply to This

Replies to This Discussion

great Mills!
Thanks for ur happy downloading. I wanna to suggest for coupling control(lateral and longitudinal control) and do u use AeroSim software.

May I know how to consider the inertia effect for airplane.Please let's me know about that.

I have used Aerosim and it is a good product - in fact. the trim and linearization utility in the project is a lightly modified version of the very same one found in Aerosim (with the permission of U-Dynamics of course.)
thanks for ur information.May I know ur AeroSim experinces and the permission of U-Dynamics of course more.
Hy Brian,

great job!what you are creating is very intersting and useful.
Unfortunatly i tried your JSBSimSFunction on different plane and i am not very sure that it works. Probably i do some mistakes but the button perform initial trim doesn't seem to be good. I mean it gives uncorrect result if I change the plane (cessna172x,p,r) instead of use f16. Besides if I use f16 perform initial trim gives a result but if I try to do the simulation in simulink (60 seconds) the plane crashes.
Hi Niki,

Thanks for giving the project a try! To address your problem with the trim, let me first tell you what someone more knowledgeable of the subject than I has said on more than one occasion- "trimming an aircraft is a non-trivial task." What he means is that even with the help of programs like Matlab, trimming a non-linear flight model for a specific aircraft is not supposed to be easy- though it is our goal to eventually make it easy :). The Matlab default trim function used by the trim routine requires initial controlo inputs and states that are very close to a trimmed condition for the particular aircraft you are trying to trim. So basically, in order to get a good trim output, you almost need to know what the trimmed control inputs are in order to initialize it....frustrating I know. In all fairness, the current state of the trim routine is pretty beta and it is expected that the user will need to tinker with some of the m-code settings. This "tuning" process was to be outlined in a white paper that I am working and on ;). However, more recently it has been decided to really try to overhaul the trim function (and the GUI for that matter) and attempt to make it much easier to trim any given aircraft model without needing to spend hours (or days) trying different control settings, pre-trim gain settings etc.

Please be patient and tinker with the SFunction in its current state because the changes that are planned are pretty exciting!

Brian Mills
OK thank you for your reply.
I know all that you said because two o three years ago i did something similar for my little simulator in matlab. I supposed that at least the initial values of the f16 were good but i see that this is not true. The strange thing is that if i utilize for the c172p the values that you ad Agostino wrote in a paper of 2007 the simulation is pretty good. Instead if I put those value at the beginning in GUI interface and push initial perform the resuts doesn't work (i am reading now that maybe it is because i use matlab 2009a).
I will wait and I try to do something by myself.

Thaks for your is really good and useful!
Hi Nikki,

Well, for me the initial values for the F16 (the modified F16 that comes with the project) trim the aircraft to 925 fps @ 30k feet. Once the trim is run and the trimmed values are loaded into the GUI, the F16 model is pretty close to a trimmed state. Perhaps there is something else going on?

Would you mind giving me the initial control values and states for hte c172p model so that I could try to duplicate your results?

Sorry for the late reply.

Of course that I can. These first values are what I found after I push Ininitialize trim once:
States: [ 906.874 0.37529 11.158 -4.4318e-017 1.342e-017 4.7166e-018 29999.3867 12.0683 44.1143 0.0011081 0.012304 2.0182 ]
Input :[ 0.4695 -0.039858 -0.047884 -0.01571 0.8 1 0 0 ]
With these results the f16 crashes ina simulation of 100 s.
The first thing is that when I push the button once I can't come back...the results are the new states.

For the Cessna I don't push the button Inizialize trim button and I use the coefficents that you and De Marco found in an article of 2007.
Stases:[ 148.977 0 0 0 0 0 5500 12.0683 44.1952 0 0.0254 0 ]
Input: [ 0.693 0 0.145 0 0 1 0 0 ]

In this case the behavior of the plant it's pretty good but it starts having a roll angle in a simulation of 100 s. INstaead if from that values I push the initialize trim condition (and I thought that I was near a solution of trim from your article) the results are outside the bar range.

I use Matlab 2009a and Visio express 2008.
Hi Nikki,

OK, I found an error in the simulink model used for the trim- not sure how that version made it into the release but it only trims the 'f16' model, no matter what model you select. This would explain why the C172 model will not trim. I will be updating the project release very soon and will definitely fix this.

Check this thread soon and I will have a link to a new download with some of the most pressing changes....
Hi Nikki,

Something I wanted to point out (for accuracy) is that the report you referenced is not my work, but very likely is Agostino DeMarcos. If it is Agostino's work I trust that the numbers given are accurate.

Just wanted to make sure credit is given to the proper people. :)


Hi. Excellent work! Thank you for sharing this.

I have Matlab 7.1 (R14) and Visual Studio Express Edition 2010. Will I be able to use your files with the tools I currently have? My machine is running Win XP, but I plan on moving to my Win7 (32 bit) machine soon.
By the way, decided to try. Followed the installation instructions in readme.txt and renamed / copied the JSBSim file tree etc. Issued the jsbsimgui_start cmd.

Got a "Segmentation violation detected at Thu Jul 22 13:42:23 2010"

Stack trace xxxxx (details deleted for clarity)

Looks like there are some hints here:
Error in ==> gui_mainfcn>local_openfig at 216
gui_hFigure = openfig(name, singleton, 'auto');

Error in ==> gui_mainfcn at 94
gui_hFigure = local_openfig(gui_State.gui_Name, gui_SingletonOpt);

Error in ==> JSBSimGUI at 42
gui_mainfcn(gui_State, varargin{:});

Error in ==> JSBSimGUI_Start at 3

Reply to Discussion


© 2017   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service