-
Notifications
You must be signed in to change notification settings - Fork 462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate Linear Model from XML Script #227
Comments
Your request is too vague. What do you mean by "generate a linear model" ? |
No response from the issuer for 3 weeks: issue closed. |
@bcoconni Sorry for the delay, i was not notified of a comment on this ticket. I thought generating a linear model is pretty standard, and I believe it is a part of the source code already. It is implemented in JSBSim Advanced Triming Branch by calling into FGLinearization.cpp. The output should be something like this: u0=.. sys = syslin('c',.. tfm = ss2tf(sys); ` Please let me know if more information is needed. Generation a linear model at a flight condition is a commonly needed output in modern autopilot development processes. |
Taking a quick look I see |
Also searching for |
I confirm. This code comes from the great work by James Goppert, back in 2012. |
Well they were at some point during JSBSim history (commits listed below with their messages because they are quite enlightening):
and then at some point Jon decided to remove all the code altogether:
Interestingly, the linearization code was supposed to be run by setting a Line 157 in d724427
and the linearization was made by calling FGLinearization Lines 1203 to 1211 in d724427
Another interesting point is that the documentation of DoLinearization stipulated that it should be called after the aircraft was trimmedLines 470 to 473 in d724427
The good news are that we are not starting from a blank sheet. The bad news are that Jon's comment made it clear in the commit 0c73960 (the one that removed James Goppert's code) that there were some problems with the code and I infer from that that we'd better know what we are doing before reintroducing this code in the current code base. |
I am not surprised that you should trim the aircraft before running the linearization routine. This is a common stipulation, as linearization is only valid at a stable trim point. |
@jonsberndt can you shed any light on what the problems were in the code when you removed it via commit 0c73960? In particular I guess if you remember any particular issues with the linearization code. If the issue was only/mainly with the trim code then maybe the linearization code could be used with the current trim code? |
I have come across automatic differentiation which should also allow to generate a linear model with much more flexibility than what was done by The concept is quite simple, you need to implement a new class for dual numbers and replace most of, if not all, occurrences of Any thoughts ? |
Very interested in bringing this feature back. Along with more control of trim options. The two features go hand in hand, relying on generation of jacobians, etc. One issue will be dealing with certain classes of nonlinearities in the actuator and sensor models. Disabling freeplay, deadband, error models, noise in the subsystems makes the results more representative of the desired system. I'd like to help if help is needed. |
@rega0051 what additional control of the trim options are you looking for? In terms of freeplay, deadband etc. if you don't want them included while generated the linearized model are you suggesting that the linearizing process automatically detect them and exclude them as opposed to you removing them from the model during the linearization process? |
@seanmcleod As far as I know there isn't a means of either programmatically detecting or removing the presence of nonlinearities. I've had many issues with the trim routines being hardcoded, I'm hopeful these issues won't propagate to the Linearization. A few of the issues off the top of my head: Trimming a flying wing without yaw control: can't use tFull, but tLongitudinal doesn't trim yaw at all (the desire is to have yaw trimmed with sideslip). The other recent issue I ran into is trimming a quad copter model in hover. The tCustom trim type would likely be useful, but there is no means of setting it up through a script or Python binding. Goppert's Simplex linearization was also hardcoded if I recall (at least some of the parameters anyway, I think the GUI interface had ability to modify). The real difference with FGTrim is that the simplex algorithm will attempt to simultaneously minimize the objectives simultaneously. |
@agodemar I'm trying to remember/figure out the relationship between your paper - 'A General Solution to the Aircraft Trim Problem' - http://wpage.unina.it/agodemar/DSV-DQV/AIAA-2007-6703-905_DeMarco_Duke_Berndt.pdf and the trim code you mention in the paper to James Goppert's trimming code in - https://github.com/arktools/jsbsim Was James's code an updated/improved version of what you describe in the paper? And do you remember why @jonsberndt removed it in 2015? Had something changed between 2013 and 2015 with lack of maintenance etc. to stop it working? |
Of course, help is always very appreciated 😄 You're very welcome to submit proposals. Just make sure that we are on the same page before writing too much code. First things first, I would like to clarify what you are volunteering for ? Is it bringing back James Goppert's
Well, it might not be possible to detect non linearities in general but we can detect the usage of |
@seanmcleod Legacy trim routinesThese are the older (and the last still active) trim routines. They were designed by Tony Peden. The algorithm is quite simple: it trims one axis at the time. Of course this fails when local axis minima do not match the global minimum, hence the development of algorithms that targeted the global minimum by trying to minimize all axes simultaneously. Files: De Marco/Durke/Berndt's trim algorithmThese are implementing the algorithms described in the paper 'A General Solution to the Aircraft Trim Problem'. Even though its source code is still in JSBSim repository, it is no longer compiled and linked with JSBSim making it dead, unmaintained code. Files: Goppert's trim routinesAs @rega0051 mentioned, these are using the Simplex algorithm to optimize all the axis simultaneously. The differentiation (aka linearization) is indeed hardcoded in Files: In the case where some or all of these routines would be brought back to JSBSim, keep in mind that they also need some "glue" code in |
@bcoconni thanks for the good summary. I'm interested in trim routines that can potentially handle more cases than the current trim routines in JSBSim so I'll spend some time in a local branch adding Goppert's trim routines back in and testing them. |
Sure. That would be most interesting. For the record, James Goppert has documented his algorithm in a document that is still accessible from the internet: On Some Trim Strategies for Nonlinear Aircraft Flight Dynamics Models with the Open Source Software JSBSim Also note that James Goppert (@jgoppert) is on GitHub, no doubt he has some recollections about the algorithm he wrote almost 10 years ago 😃 |
When I was searching yesterday I also came across a couple of YouTube videos he posted demonstrating the trim functionality via a GUI he produced and also generating linearized models and loading them up in Scicoslab. |
I got sick of hidden states in the c++ code. For instance trying to track down states in a jet engine model. I would push you toward automatic differentiation. I was using numerical differentiation with a Nelder Mead Simplex for trimming. Also being able to obtain a human readable state name would be useful. Using AD and getting a 20 state model and not knowing why can be annoying. I found the Modelica language is a bit friendlier in this regard as it maps directly to a differential algebraic equation and supports AD, also see pymoca and casadi which supports AD. Casadi is a C++ AD library and maybe you could leverage it. Let me know how I can help. |
For the record, that's a presentation I gave of a paper that @jgoppert and me co-authored quite a few years ago ;-) |
Oops ! Sorry. And for the sake of completeness there was also a third author: Inseok Hwang 😉 |
After some more archeological unearthing, I found the following 2 discussions threads in the mailing list archives:
|
Are you sure? Naming it matrix kinda implies it can be used for matrix calculations, but it's nothing more than an std::vector. |
Well, use whatever name you like which make the whole expression shorter ! |
@aarondewindt's patch has just been committed to the branch At the moment,the easiest way to run the feature is with Python: import jsbsim
fdm = jsbsim.FGFDMExec('.') # The path supplied to FGFDMExec is the location of the folders "aircraft", "engines" and "systems"
fdm.load_model('737') # Load the aircraft 737
fdm.load_ic('cruise_init.xml', True) # Load the initial conditions
fdm.run_ic() # Initialize the aircraft with initial conditions
# Set engines running
fdm['propulsion/engine[0]/set-running'] = 1
fdm['propulsion/engine[1]/set-running'] = 1
fdm.run()
# Trim
fdm['simulation/do_simple_trim'] = 1
# Linearization
linearization = jsbsim.FGLinearization(fdm)
print(linearization.system_matrix)
print(linearization.input_matrix)
print(linearization.output_matrix)
print(linearization.feedforward_matrix) |
That's great news. Thanks |
Hi,
Do I have to do anything different to include the correct code? I'm running JSBSim 1.1.6. |
When and how did you install the python module for JSBSim? Maybe you've downloaded and built JSBSim 1.1.6 but you've previously done a |
Yes, I have done a |
My spring is at a very different time to your spring 😉 But I just double-checked and I can confirm that I see this issue after pip installing 1.1.6. (base) C:\Users\Sean>pip install jsbsim
Collecting jsbsim
Downloading JSBSim-1.1.6-320-cp37-cp37m-win_amd64.whl (767 kB)
|████████████████████████████████| 767 kB 6.8 MB/s
Requirement already satisfied: numpy in c:\users\sean\anaconda3\lib\site-packages (from jsbsim) (1.18.1)
Installing collected packages: jsbsim
Successfully installed jsbsim-1.1.6
(base) C:\Users\Sean> Trying to use >>> import jsbsim
>>> fdm = jsbsim.FGFDMExec('.')
JSBSim Flight Dynamics Model v1.1.6 [GitHub build 320/commit b477f6312bee2fd3af4c4e5ba1a3e732ed2b99d4] Apr 30 2021 12:00:59
[JSBSim-ML v2.0]
JSBSim startup beginning ...
>>> linearization = jsbsim.FGLinearization(fdm)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'jsbsim' has no attribute 'FGLinearization'
>>> It looks to me @bcoconni something went awry with the tagging of v1.1.6? The https://github.com/JSBSim-Team/jsbsim/blob/master/python/jsbsim.pyx.in However if you look at |
Hmm, I assumed based on the build date of Apr 30 2021 and the following comment on https://github.com/JSBSim-Team/jsbsim/releases/tag/v1.1.6 that 1.1.6 was based on code in master on Apr 30.
However looking at the link to the 164 commits since - v1.1.6...master it looks like v1.1.6 is based on code from the beginning of Oct 2020, which would explain why it doesn't have any support for the linearization. |
@sthelia @seanmcleod I'm pretty sure the code currently in master is scheduled to be released with 1.2.0. If you look at the PROJECT_VERSION in the project root |
@aarondewindt Alright, uninstalling with pip seemed to work! Thanks. |
Yes, correct. Releases @sthelia if you want to save yourself the burden of compiling JSBSim, you can download a Python wheel package from our Rolling Release and pick the file > pip install jsbsim --no-index -f /path/to/the/wheel/file.whl |
I've been looking at linear models for a few days too, and I saw a problem with this 12-state system matrix A. First three states of twelve are normally positions and they should have no effect on each other, sometimes last three states are positions but here for both conditions, position states are dependent to other positions which is seems inaccurate. Here I would like to know the order of the state variable or state variables column. Maybe the order of the states are different? |
Looking at the order here it does look like the last 3 states are positions (lat, lon, alt). jsbsim/src/initialization/FGLinearization.cpp Lines 28 to 58 in c943e78
|
I tried doing the linearization but the trim failed. Could anyone help fdm['simulation/do_simple_trim'] = 1 Trim failed |
You haven't specified what aircraft you're using and what your initial conditions are. For example maybe you're trying to trim the 737 at 50kts, well you're never going to be able to generate a trim solution for that combination. |
I have used f16. I'm doing this for first time. I gave Initial conditions as 'reset00', correct if i'm wrong. Thank you |
Have you looked at (base) C:\source\jsbsim\aircraft\f16>type .\reset00.xml
<?xml version="1.0"?>
<initialize name="reset00">
<!--
This file sets up the aircraft to start off
from the runway in preparation for takeoff.
-->
<ubody unit="FT/SEC"> 0.0 </ubody>
<vbody unit="FT/SEC"> 0.0 </vbody>
<wbody unit="FT/SEC"> 0.0 </wbody>
<latitude unit="DEG"> 47.0 </latitude>
<longitude unit="DEG"> 122.0 </longitude>
<phi unit="DEG"> 0.0 </phi>
<theta unit="DEG"> 0.0 </theta>
<psi unit="DEG"> 180.0 </psi>
<altitude unit="FT"> 5.5 </altitude>
</initialize>
(base) C:\source\jsbsim\aircraft\f16> So it's sitting on the ground with no airspeed. So the only trim option that would make sense would be Secondly the trim isn't going to work with an aircraft which has a FBW command law like the F-16 has. So try it with an aircraft without a FBW command law, e.g. the 737 model or the C172, A4 models for example. |
ok understood. But i want to compute for f-16, how can i do it? Thanks |
@pd3a are you trying to generate a linear model as per this discussion? If not, and you're just trying to trim the F-16 model then rather start a separate discussion dedicated to trimming FBW aircraft. |
I'm trying to generate a linear model for f-16, yes. |
Okay, if your aim is to generate a linear model for the F-16 around some trim point then I suggest you edit the F-16 model and remove the FBW command law implementation and replace it with a basic FCS like you see in the non-FBW aircraft. JSBSim should then be able to generate a trim solution, assuming you have valid initial conditions, and then you can get a linear model as per above. |
Even after removing FBW command law i'm getting same error. I gave initial conditions of speed 420 ft/s and 15000ft. |
Post/attach a copy of your updated F-16 FDM and initial conditions file. |
I attached the zip file here |
The reset/initial conditions file is identical to the one in the repo, i.e. still stationary on the ground. Also you haven't removed the FBW command law and replaced it with a basic "direct mechanical" style FCS that you see in the 737, C-172, A4 etc. |
could you guide me how to replace the FBW with the FCS |
Basically take a look at the 737's implementation and use that with the F-16. |
Does anyone have any experience with, or is it possible to generate a linear model via XML scripting? Looking to call into FGStateSpace to get x0, u0, A, B, C, D vectors. Thanks!
The text was updated successfully, but these errors were encountered: