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 ------------------------------------------------------- |