From: Agostino De M. <ago...@un...> - 2009-02-03 12:32:24
|
Hi all, I've been working at the Matlab mex-function "MexJSBSim". You'll find all the archived stuff here: http://www.dias.unina.it/demarco/Work/JSBSim_Matlab/JSBSim_Matlab.zip or you can browse the sources here: http://www.dias.unina.it/demarco/Work/JSBSim_Matlab/ I was able to compile and debug the mex-function with Visual Studio 2008. To compile, just use the solution file MexJSBSim.sln, adjusting the include and lib directories as necessary. For example, I use Matlab 2008b installed in N:\MATLAB\R2008b\ so, in the MexJSBSim project I need to set the dirs: N:\MATLAB\R2008b\extern\include\ and N:\MATLAB\R2008b\extern\lib\win32\microsoft\ to link the Matlab libs: libmx.lib libmex.lib libmat.lib The mex-function is also linked to the static library "JSBSimLib.lib", which I made out of the latest JSBSim distribution (this project is also included in the solution). The mex-function MexJSBSim is an attempt to establish a sort of standardized way of using a JSBSim::FGFDMExec object from Matlab command line. Every suggestion or criticism is welcomed. ----------------------------------------------------------------- This is an example of output of the command: MexJSBSim('help') ----------------------------------------------------------------- >> MexJSBSim('help') function usage: result = MexJSBSim( string_directive [, string, value] ) Examples: res = MexJSBSim('help'); Prints this help text. returns 1 (always) res = MexJSBSim('open','c172r'); returns 1 if success, 0 otherwise res = MexJSBSim('get','fcs/elevator-cmd-norm') returns the value of the property, or -9999 if property not found res = MexJSBSim('set','fcs/elevator-cmd-norm',-0.5) returns 1 if success, 0 otherwise res = MexJSBSim('set','elevator-cmd-norm',-0.5) res = MexJSBSim('set','u-fps',80.5) same as above, but it scans a set of predefined, and commonly used variable names: 'u-fps', 'v-fps', 'w-fps' 'p-rad_sec', 'q-rad_sec', 'r-rad_sec' 'h-sl-ft' 'long-gc-deg' 'lat-gc-deg' 'phi-rad', 'theta-rad', 'psi-rad' 'elevator-cmd-norm' 'aileron-cmd-norm' 'rudder-cmd-norm' res = MexJSBSim('init',ic) initializes the JSBSim::FGFDMExec by means of the matlab structure ic. The structure ic must have the two fields: name and value. The Matlab user is forced to build such a structure first, then to pass it to the mex-file. Example: >> ic(1).name = 'u-fps'; ic(1).value = 80; >> ic(2).name = 'v-fps'; ic(2).value = 0; >> ic(3).name = 'w-fps'; ic(3).value = 0; >> ic(4).name = 'p-rad_sec'; ic(4).value = 0; >> MexJSBSim('init', ic); >> ----------------------------------------------------------------- This is the output of the Matlab script: test_1.m ----------------------------------------------------------------- Setting up JSBSim with standard 'aircraft', 'engine', and 'system' paths. Loading aircraft 'c172r' ... Model c172r loaded. ans = 1 Property name: 'u-fps'; Property value: 80.000000 Easy-set: true flight speed (ft/s) = 80.000000 Property name: 'v-fps'; Property value: 20.000000 Easy-set: true flight speed (ft/s) = 82.462113 Property name: 'w-fps'; Property value: 10.000000 Easy-set: true flight speed (ft/s) = 83.066239 Property name: 'p-rad_sec'; Property value: 0.100000 Easy-set: roll rate (rad/s) = 0.100000 Property name: 'q-rad_sec'; Property value: 0.200000 Easy-set: pitch rate (rad/s) = 0.200000 Property name: 'r-rad_sec'; Property value: 0.300000 Easy-set: yaw rate (rad/s) = 0.300000 Property name: 'h-sl-ft'; Property value: 3000.000000 Easy-set: altitude over sea level (mt) = 914.400000 Property name: 'long-gc-deg'; Property value: 122.000000 Easy-set: geocentric longitude (deg) = 121.999983 Property name: 'lat-gc-deg'; Property value: 47.000000 Easy-set: geocentric latitude (deg) = 46.999994 Property name: 'phi-rad'; Property value: 0.000000 Easy-set: phi -> quaternion = (1.000000,0.000000,0.000000,0.000000) Easy-set: alpha (deg) = 7.125016, beta (deg) = 13.932092, gamma (deg) = -6.914372 Property name: 'theta-rad'; Property value: 0.034907 Easy-set: phi -> quaternion = (0.999848,0.000000,0.017452,0.000000) Easy-set: alpha (deg) = 7.125016, beta (deg) = 13.932092, gamma (deg) = -4.973862 Property name: 'psi-rad'; Property value: 0.000000 Easy-set: phi -> quaternion = (0.999848,0.000000,0.017452,0.000000) Easy-set: alpha (deg) = 7.125016, beta (deg) = 13.932092, gamma (deg) = -4.973862 Property name: 'aileron-cmd-norm'; Property value: 1.000000 Easy-set: right aileron pos (deg) = -14.997170 Property name: 'elevator-cmd-norm'; Property value: -0.400000 Easy-set: elevator pos (deg) = -11.197887 Property name: 'rudder-cmd-norm'; Property value: 1.000000 Easy-set: rudder pos (deg) = 15.996982 Property name: 'fcs/throttle-cmd-norm'; Property value: 1.000000 Property name: 'fcs/mixture-cmd-norm'; Property value: 0.700000 Property name: 'set-running'; Property value: 1.000000 Easy-set: engine(s) running = 1 Vt = 83.066239 State derivatives calculated. V true 83.066239 (ft/s) [u_dot, v_dot, w_dot] = [2.450673,-24.558555,28.438848] (ft/s/s) [p_dot, q_dot, r_dot] = [1.037838,0.046871,-0.037094] (ft/s/s) [x_dot,y_dot,z_dot] = [16.762871,-64.567836,49.497482] (ft/s/s) [phi_dot,theta_dot,psi_dot] = [0.110476,0.200000,0.300183] (ft/s/s) ans = 1 ----------------------------------------------------------------- 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 / Web: www.dpa.unina.it/demarco ------------------------------------------------------- |
From: Jon S. B. <jon...@co...> - 2009-02-03 16:59:54
|
One thing I've wondered is if it would be helpful to make the FGFCS (flight control manager) code "virtual" so that perhaps a different Run() method could be built that would somehow "call" Matlab/Simulink, so that control code generated there could drive JSBSim instead of the normal FGFCS::Run() method. It wouldn't even have to me Matlab that was "called" (which I don't know if that's even possible), but instead perhaps some autogenerated code could be in the derived ::Run() method. Just a thought. Jon |
From: Bowman, D. S. <sb...@mi...> - 2009-02-04 13:34:27
|
Jon, the only way that I know of for Matlab to interact with C/C++ code is for that code to be compiled into a DLL (called a mex-file in Mathworks parlance) that gets called from Matlab. Basically, The Mathworks provides a header file that prototypes the interface and then the user writes the actual code to implement the interface. Then, one compiles it (gcc, vc, or Mathwork's lcc) and calls it from Matlab. For smaller codes, the interface is simple and easy to create. For JSBSim, I think it would be more complicated. (I've wanted to do it with JSBSim, but nothing is pushing it for me right now which means it just won't get done. :) ) The other option, of course, is one that you wrote about in an old issue of "Back of the Envelope" in which one would use network interfaces to accomplish the data transfer. >From the perspective of compiling JSBSim into a Matlab-capable DLL, I think that making the Run method virtual would help. But, I should point out that I'm no expert in this area! -sb -----Original Message----- From: Jon S. Berndt [mailto:jon...@co...] Sent: Tuesday, February 03, 2009 12:00 PM To: jsb...@li... Subject: [Jsbsim-matlab] Flight Control code One thing I've wondered is if it would be helpful to make the FGFCS (flight control manager) code "virtual" so that perhaps a different Run() method could be built that would somehow "call" Matlab/Simulink, so that control code generated there could drive JSBSim instead of the normal FGFCS::Run() method. It wouldn't even have to me Matlab that was "called" (which I don't know if that's even possible), but instead perhaps some autogenerated code could be in the derived ::Run() method. Just a thought. Jon ------------------------------------------------------------------------------ Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) software. With Adobe AIR, Ajax developers can use existing skills and code to build responsive, highly engaging applications that combine the power of local resources and data with the reach of the web. Download the Adobe AIR SDK and Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com _______________________________________________ Jsbsim-matlab mailing list Jsb...@li... https://lists.sourceforge.net/lists/listinfo/jsbsim-matlab |
From: Agostino De M. <ago...@un...> - 2009-02-04 14:14:25
|
as I said in another thread, look here: http://www.dias.unina.it/demarco/Work/JSBSim_Matlab/JSBSim_Matlab.zip or you can browse the sources here: http://www.dias.unina.it/demarco/Work/JSBSim_Matlab/ Agostino Quoting "Bowman, D. Stuart" <sb...@mi...>: > Jon, the only way that I know of for Matlab to interact with C/C++ > code is for that code to be compiled into a DLL (called a mex-file > in Mathworks parlance) that gets called from Matlab. Basically, The > Mathworks provides a header file that prototypes the interface and > then the user writes the actual code to implement the interface. > Then, one compiles it (gcc, vc, or Mathwork's lcc) and calls it from > Matlab. For smaller codes, the interface is simple and easy to > create. For JSBSim, I think it would be more complicated. (I've > wanted to do it with JSBSim, but nothing is pushing it for me right > now which means it just won't get done. :) ) The other option, of > course, is one that you wrote about in an old issue of "Back of the > Envelope" in which one would use network interfaces to accomplish > the data transfer. > >> From the perspective of compiling JSBSim into a Matlab-capable DLL, >> I think that making the Run method virtual would help. But, I >> should point out that I'm no expert in this area! > > -sb > -----Original Message----- > From: Jon S. Berndt [mailto:jon...@co...] > Sent: Tuesday, February 03, 2009 12:00 PM > To: jsb...@li... > Subject: [Jsbsim-matlab] Flight Control code > > One thing I've wondered is if it would be helpful to make the FGFCS (flight > control manager) code "virtual" so that perhaps a different Run() method > could be built that would somehow "call" Matlab/Simulink, so that control > code generated there could drive JSBSim instead of the normal FGFCS::Run() > method. It wouldn't even have to me Matlab that was "called" (which I don't > know if that's even possible), but instead perhaps some autogenerated code > could be in the derived ::Run() method. > > Just a thought. > > Jon > > > > ------------------------------------------------------------------------------ > Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) > software. With Adobe AIR, Ajax developers can use existing skills and code to > build responsive, highly engaging applications that combine the > power of local > resources and data with the reach of the web. Download the Adobe AIR SDK and > Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com > _______________________________________________ > Jsbsim-matlab mailing list > Jsb...@li... > https://lists.sourceforge.net/lists/listinfo/jsbsim-matlab > > ------------------------------------------------------------------------------ > Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) > software. With Adobe AIR, Ajax developers can use existing skills and code to > build responsive, highly engaging applications that combine the > power of local > resources and data with the reach of the web. Download the Adobe AIR SDK and > Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com > _______________________________________________ > Jsbsim-matlab mailing list > Jsb...@li... > https://lists.sourceforge.net/lists/listinfo/jsbsim-matlab > ------------------------------------------------------- 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 / via Claudio 21, 80125 Napoli - Italy Tel.: +39 0817683323 Fax: +39 0817683622 Email: ago...@un... Web 1: www.dpa.unina.it/adag Web 2: www.dpa.unina.it/demarco ------------------------------------------------------- |
From: Bowman, D. S. <sb...@mi...> - 2009-02-04 15:28:59
|
I completely forgot about your work along these lines. Thanks, Agostino! -sb -----Original Message----- From: Agostino De Marco [mailto:ago...@un...] Sent: Wednesday, February 04, 2009 9:14 AM To: jsb...@li... Subject: Re: [Jsbsim-matlab] Flight Control code as I said in another thread, look here: http://www.dias.unina.it/demarco/Work/JSBSim_Matlab/JSBSim_Matlab.zip or you can browse the sources here: http://www.dias.unina.it/demarco/Work/JSBSim_Matlab/ Agostino Quoting "Bowman, D. Stuart" <sb...@mi...>: > Jon, the only way that I know of for Matlab to interact with C/C++ > code is for that code to be compiled into a DLL (called a mex-file > in Mathworks parlance) that gets called from Matlab. Basically, The > Mathworks provides a header file that prototypes the interface and > then the user writes the actual code to implement the interface. > Then, one compiles it (gcc, vc, or Mathwork's lcc) and calls it from > Matlab. For smaller codes, the interface is simple and easy to > create. For JSBSim, I think it would be more complicated. (I've > wanted to do it with JSBSim, but nothing is pushing it for me right > now which means it just won't get done. :) ) The other option, of > course, is one that you wrote about in an old issue of "Back of the > Envelope" in which one would use network interfaces to accomplish > the data transfer. > >> From the perspective of compiling JSBSim into a Matlab-capable DLL, >> I think that making the Run method virtual would help. But, I >> should point out that I'm no expert in this area! > > -sb > -----Original Message----- > From: Jon S. Berndt [mailto:jon...@co...] > Sent: Tuesday, February 03, 2009 12:00 PM > To: jsb...@li... > Subject: [Jsbsim-matlab] Flight Control code > > One thing I've wondered is if it would be helpful to make the FGFCS (flight > control manager) code "virtual" so that perhaps a different Run() method > could be built that would somehow "call" Matlab/Simulink, so that control > code generated there could drive JSBSim instead of the normal FGFCS::Run() > method. It wouldn't even have to me Matlab that was "called" (which I don't > know if that's even possible), but instead perhaps some autogenerated code > could be in the derived ::Run() method. > > Just a thought. > > Jon > > > > ------------------------------------------------------------------------------ > Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) > software. With Adobe AIR, Ajax developers can use existing skills and code to > build responsive, highly engaging applications that combine the > power of local > resources and data with the reach of the web. Download the Adobe AIR SDK and > Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com > _______________________________________________ > Jsbsim-matlab mailing list > Jsb...@li... > https://lists.sourceforge.net/lists/listinfo/jsbsim-matlab > > ------------------------------------------------------------------------------ > Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) > software. With Adobe AIR, Ajax developers can use existing skills and code to > build responsive, highly engaging applications that combine the > power of local > resources and data with the reach of the web. Download the Adobe AIR SDK and > Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com > _______________________________________________ > Jsbsim-matlab mailing list > Jsb...@li... > https://lists.sourceforge.net/lists/listinfo/jsbsim-matlab > ------------------------------------------------------- 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 / via Claudio 21, 80125 Napoli - Italy Tel.: +39 0817683323 Fax: +39 0817683622 Email: ago...@un... Web 1: www.dpa.unina.it/adag Web 2: www.dpa.unina.it/demarco ------------------------------------------------------- ------------------------------------------------------------------------------ Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) software. With Adobe AIR, Ajax developers can use existing skills and code to build responsive, highly engaging applications that combine the power of local resources and data with the reach of the web. Download the Adobe AIR SDK and Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com _______________________________________________ Jsbsim-matlab mailing list Jsb...@li... https://lists.sourceforge.net/lists/listinfo/jsbsim-matlab |