From: Michael.McCarthy <Mic...@ul...> - 2010-06-22 11:54:13
|
Hi Agostino Thank you VERY much for the detailed reply. I will be looking into this in more detail in the coming weeks and no doubt will have some questions. I will start with your website below. Thanks again Regards Michael ________________________________ From: Agostino De Marco [mailto:ago...@un...] Sent: Tue 22/06/2010 11:39 To: jsb...@li... Subject: Re: [Jsbsim-matlab] S-function Hi Michael, just some more words about the idea of having JSBSim available in Matlab. I started thinking about this when I realized that Matlab became a standard tool for aerospace engineers and students. As a teacher, my purpose is to show my students the three possibilities: a) Using FlightGear with the JSBSim as the default FDM (This is the easiest way of playing around with simulations; you need a joystick and a good graphic card). b) Using JSBSim as a standalone application for making scripted simulations (This requires users to have a basic/medium knowledge of some essential system tools, such as a command shell--DOS, bash, etc--, command line tools, an editor, a plotting utility). c) Using JSBSim from within the Matlab environment and take advantage of all the built-in functions and additional library blocksets. I focused on this last point. My very first idea was this: What if we could have a MEX-function that could enable us to access JSBSim capabilities from the Matlab command window? As you may know, MEX-functions (or "MEX-files") can be run from within Matlab in the same way as Matlab M-files or built-in functions. So I implemented my own MEX-function in C++ and named it 'MexJSBSim'. I took all JSBSim source files (except JSBSim.cpp) and compiled them as a static library (JSBSim.lib). Then I developed a C++ class named JSBSimInterface that makes the job of making most of JSBSim internal objects accessible by Matlab. More technically: I conceived this interface with the purpose of establishing a sort of standardized way of using a JSBSim::FGFDMExec object from the Matlab command line. The first version of MexJSBSim provided some experimental functionalities to transfer data between a JSBSim instance and Matlab. This was going to be the first attempt to provide control engineers a direct access to a well established, high fidelity, flight dynamics model like JSBSim, enabling them to concentrate their work on automatic control logic and autopilot design. A very basic example of usage is this: >> MexJSBSim('open','c172r'); The above command starts out JSBSim from the Matlab prompt and loads the c172r aircraft model. You may find more details on MexJSBSim here: http://www.dias.unina.it/demarco/Work/JSBSim_Matlab/ Evolving from the MexJSBSim code, Brian Mills developed a JSBSim S-function. Matlab S-functions provide a powerful mechanism for extending the capabilities of the Simulink environment, which is the tool of choice for control engineers. An S-function is a computer language description of a Simulink block written in Matlab, C, C++, Ada, or Fortran. C, C++, Ada, and Fortran. S-functions are compiled as MEX-files. As with other MEX-files, S-functions are dynamically linked subroutines that the Matlab interpreter can automatically load and execute. S-functions use a special calling syntax called the S-function API, that enables users to interact with the Simulink engine. This interaction is very similar to the interaction that takes place between the Matlab engine and built-in Simulink blocks. In practice, the JSBSim S-function is a custom made Simulink block and is usable as other built-in blocks. MexJSBSim, and the S-function developed by Brian represent two effective examples of integration of a complex C++ code with the Matlab application. These allow the JSBSim users that have access to Matlab to bring all the advantages offered by JSBSim into that sophisticated and powerful computing environment. Please do not hesitate to give us your feedback. Suggestions are welcome in order to make this little toy useful for aerospace students and engineers. Regards, Agostino ------------------------------------------------------- Agostino De Marco, PhD Assistant Professor Università degli Studi di Napoli Federico II / University of Naples Federico II / Dipartimento di Ingegneria Aerospaziale / Department of Aerospace Engineering / http://jsbsim.sourceforge.net/about.html http://www.dias.unina.it/demarco http://www.dias.unina.it/adag ------------------------------------------------------- Quoting "Michael.McCarthy" <Mic...@ul...>: > Hi Brian > > Many thanks for the detailed response. That is indeed a powerful > facility. I did not realise the entire JSBSim program was available > in the S-Function. As you say that opens up using all the different > JSBSim aircraft within matlab, which is very exciting. > > I will be working on getting familiar with all this over the coming > weeks, so no doubt will have some follow up questions and feedback. > > Thanks for this great initiative. > > Regards > Michael > > ________________________________ > > From: b mills [mailto:bri...@in...] > Sent: Sun 20/06/2010 06:10 > To: jsb...@li... > Subject: Re: [Jsbsim-matlab] S-function > > > > > Hello Michael! > > Your question is not dumb at all, and in fact it is very reasonable > that JSBSim and Simulink could be a bit overwhelming to a new > user...or a seasoned user as well. > > Let me first say that I'm excited that my project may find its way > into a college classroom, as that was one of the intended uses ;). > That said, I know that my current documentation for the project > leaves much to be desired. I'm working on something of a white > paper/user doc currently, but it will be a few more weeks before > anything is ready for release. > > OK, let me attempt to put all this together so that it makes sense > and you can get started.... > > JSBSim is the default non-linear flight dynamic model used in the > FlightGear flight simulator project. The JSBSim S Function takes the > JSBSim code and compiles it into a matlab compatible executable > file that is called a MEX file. An S Function is a user-defined > Simulink function that can be written in M, ADA, C etc, and can be > in the form of a MEX file. What is nice about a MEX S Function is > that it can be a rather complex external program (like JSBSim), but > is treated as a simple Simulink block. Now, all the power of JSBSim > flight modeling software is available in any Simulink model. > > > > > With the JSBSim Sfunction, any JSBSim compatible aircraft FDM/engine > file that is located in the JSBSimData/aircraft or .../engine > folder can be run in any Simulink simulation. This is quite > powerful as there are many decent FDMs already available to start > out with. The S Function can then be used for many different > teaching scenarios such as: > > * > > > * > how to trim an aircraft using the built-in trim utility > * > linearizing non-linear models and analyzing the decoupled > state-space matrices > * > flight model validation and construction > * > control system and autopilot system design with the JSBSim S > Function acting as the plant > * > using an events driven tool like StateFlow to script a flight > > > The flight scripting that you mention is something that I would be > interested in working with you on as it is a capability that I have > not really explored as of yet, but would like to implement better in > the future. > > To get started using the S Function, simply type "jsbsimgui_start" > at the Matlab command line- this will launch the JSBSim GUI > application. The JSBSim GUI is just a convenient way to initialize > all of the Sfunction parameters such as the Simulink model (use the > default choice), the delta time, the JSBSim multiplier (allows you > run simulations much faster), the trim utility, and all of the > aircraft control inputs and states. > > Please read the README text file and use the Help button on the GUI > for further explanation. Also please keep in mind that this is still > a developing project with much further development work needed so > there may be some bugs :). Also, I will attach my incomplete paper > that I am working on (it is a rough draft so please bear with me...) > which will explain things in more detail, like the trim script and > the different MEX files used. > > So to sum it up, the JSBSim S Function would be a great tool to > teach your students as it brings a well-established non-linear > flight dynamic modeling engine directly into Simulink as a single > block. Any control system can be built around it and all the > states, propulsion parameters, control parameters, state derivatives > etc are made available as outputs from the S Function block. Any > JSBSim compatible flight model file available can be run and > analyzed in a way not previously available. > > Best of luck and please keep in touch with me as I am interested in > getting feedback from users on how the project is being used. Also > keep an eye out for updates as some may be coming soon. > > Best Regards, > > Brian Mills > > > > ----- Original Message ----- > From: "Michael.McCarthy" <Mic...@ul...> > Date: Thursday, June 17, 2010 19:14 > Subject: [Jsbsim-matlab] S-function > To: jsb...@li... > >> Hi Brian >> >> This is going to sound like a really dumb question, but I was >> just wondering if you could post something that explains in a >> nutshell what the S-function does and how it can be used. I have >> downloaded it and played with it a little but am still not too sure. >> >> To put my question in context, I am new to JSBSim, and pretty >> new to Simulink too. I've obtained the matlab aerospace toolbox >> and blockset, and am trying to make sense of it all. My main >> motivation is obtaining tools that will help me in teaching >> Stability and Control of Aircraft in an exciting way. The >> aerospace blockset looks too complex for that. >> >> Currently my thinking is to use Datcom, Matlab, JSBSim and >> (possibly) Flightgear. Our students generally aren't able to fly >> aircraft in Flightgear so I am thinking more in terms of >> scripted flights, for which we can then apply different control >> system approaches. >> >> If you could advise on how your S-function could assist with >> that it would be great. >> >> Many thanks >> Michael >> >> >> > ------------------------------------------------------------------------------ ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo _______________________________________________ Jsbsim-matlab mailing list Jsb...@li... https://lists.sourceforge.net/lists/listinfo/jsbsim-matlab |