Skip to content
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

Setting up the JSBSim interface to Matlab on Windows #491

Closed
agodemar opened this issue Aug 4, 2021 · 41 comments
Closed

Setting up the JSBSim interface to Matlab on Windows #491

agodemar opened this issue Aug 4, 2021 · 41 comments
Assignees
Labels
bug MATLAB Topics linked to the MATLAB S-Function Support request

Comments

@agodemar
Copy link
Contributor

agodemar commented Aug 4, 2021

Hello JSBSimmers!

I have managed to download and install on Windows the JSBSim release v1.1.8 that includes the newly released interface to Matlab.
Yet, the interface doesn't work right out of the box on Windows unless you add some headers and do some extra work on Matlab side.
Here's what you can do to make it work:

  1. Download the installer and set up JSBSim in the following local directory tree:
<JSBSim root>/
   aeromatic++/
   aircraft/
   data_output/
   engine/
   include/
   lib/
   matlab/
   scripts/
   systems/
   JSBSim.exe
   msvcp140.dll

The exact location <JSBSim root>/ on your system depends on where you choose to install JSBSim.

  1. There are some header files missing in the current distribution, namely all *.hxx files related to simgear. You have to copy all those missing header files, including their directory structure, from the source tree to the following local installation tree:
<JSBSim root>/
   ...
   include/
      simgear/
         io/
            iostreams/
         magvar/
         misc/
         props/
         structure/
         xml/

@bcoconni This is an important step that should be fixed in next releases when packaging the JSBSim setup executable on Windows.

  1. Now, let's see the extra work you have to do on the Matlab side.

The following steps are tested for Matlab v2020b, which I have installed on my system.

To compile the file <JSBSim root>/matlab/JSBSim_SFunction.cpp and get the MEX-File JSBSim_SFunction.mexw64 on Windows, you need a working C++ compiler. Among the available options, I suggest you to go for Visual Studio 2019 Community Edition.

Once you have a working C++ development environment, from Matlab command line you need to tell the MEX utility what is the default C++ compiler. You do this with the following command:

[Matlab prompt]>> mex -setup CPP

MEX will detect your C++ compiler and will be configured to build your *.mexw64 files.

  1. Adjusting the Matlab script <JSBSim root>/matlab/JSBSimSimulinkCompile.m to build your own MEX-file.

First of all, copy the script <JSBSim root>/matlab/JSBSimSimulinkCompile.m to your own version <JSBSim root>/myJSBSimSimulinkCompile.m in the root of your JSBSim installation directory. This makes sense, because we want a Matlab EXecutable (MEX) that lives besides <JSBSim root>/JSBSim.exe, and must reach all input files in the directories aircraft, engine, scripts, and systems.

This is how the script <JSBSim root>/myJSBSimSimulinkCompile.m should look like:

disp('Compiling S-function from JSBSim...');
mex -v -R2017b COMPFLAGS='$COMPFLAGS' ./matlab/JSBSim_SFunction.cpp ./matlab/JSBSimInterface.cpp -I".\include" -L".\lib" -lJSBSim  wsock32.lib ws2_32.lib
disp('Finished.')

If you point the current Matlab Working Directory to <JSBSim root>/ and run the above M-file from the Matlab editor or from the command line:

[Matlab prompt]>> myJSBSimSimulinkCompile

you'll get the MEX-file <JSBSim root>/JSBSim_SFunction.mexw64.

  1. Testing your MEX-file <JSBSim root>/JSBSim_SFunction.mexw64.

Download from the sources the following files: TestJSBSim.m and ex737cruise.slx and save them in <JSBSim root>/, besides <JSBSim root>/JSBSim_SFunction.mexw64.

@bcoconni These two files are missing from those packaged in the JSBSim setup executable on Windows. Probably this is fine, but we'll have to adjust our readme files to tell users how to start working with them on Matlab.

This is how <JSBSim root>/TestJSBSim.m will look like:

disp('Run 737 example');
fprintf('Current directory: %s', pwd)
sim('ex737cruise');
clear functions;
clear all;
disp('JSBSim S-Function Reset');

and this is a screenshot of Simulink when you open the file <JSBSim root>/ex737cruise.slx:

image

In particular, this is how the Simulink block named JSBSim_SFunction appears when you double-click on it:

image

When you run the test script you'll have this output in Matlab command window:

>> TestJSBSim
Run 737 example
Current directory: C:\Users\agodemar\JSBSim
Warning: 'Output Port 3' of 'ex737cruise/S-Function' is not connected. 
> In TestJSBSim (line 3) 


     JSBSim Flight Dynamics Model v1.1.8 [GitHub build 588/commit c943f83deeb3e14bed7939ac65dfac789a7a0181] Jul 24 2021 16:18:42
            [JSBSim-ML v2.0]

JSBSim startup beginning ...

Simulation dt set to 0.008333
Script input: scripts/737_cruise 
Reset file: 'cruise_init' .

JSBSim S-Function is initializing...

Note: For Aircraft with integrators in the FCS, please type 'clearSF' to completely reset S-Function.

	Setting up JSBSim with standard 'aircraft', 'engine', and 'system' paths.
	Loading aircraft '737' ...
Reading Aircraft Configuration File: 737
                            Version: 2.0


This aircraft model is a BETA release!!!

This aircraft model probably will not fly as expected.

Use this model for development purposes ONLY!!!

  Description:   Models a Boeing 737.
  Model Author:  Dave Culp
  Creation Date: 2006-01-04
  Version:       $Revision: 1.43 $

  Aircraft Metrics:
    WingArea: 1171
    WingSpan: 94.7
    Incidence: 0
    Chord: 12.31
    H. Tail Area: 348
    H. Tail Arm: 48.04
    V. Tail Area: 297
    V. Tail Arm: 44.5
    Eyepoint (x, y, z): 80 , -30 , 70
    Ref Pt (x, y, z): 625 , 0 , 24
    Visual Ref Pt (x, y, z): 0 , 0 , 0

  Mass and Balance:
    baseIxx: 562000 slug-ft2
    baseIyy: 1.473e+06 slug-ft2
    baseIzz: 1.894e+06 slug-ft2
    baseIxy: -0 slug-ft2
    baseIxz: 8000 slug-ft2
    baseIyz: -0 slug-ft2
    Empty Weight: 83000 lbm
    CG (x, y, z): 639 , 0 , -40

  Ground Reactions: 
    BOGEY Nose Gear
      Location: 158 , 0 , -84
      Spring Constant:  90000
      Damping Constant: 4000 (linear)
      Rebound Damping Constant: 8000 (linear)
      Dynamic Friction: 0.5
      Static Friction:  0.8
      Rolling Friction: 0.02
      Steering Type:    STEERABLE
      Grouping:         NONE
      Max Steer Angle:  35
      Retractable:      1
    BOGEY Left Main Gear
      Location: 648 , -100 , -84
      Spring Constant:  120000
      Damping Constant: 10000 (linear)
      Rebound Damping Constant: 20000 (linear)
      Dynamic Friction: 0.5
      Static Friction:  0.8
      Rolling Friction: 0.02
      Steering Type:    FIXED
      Grouping:         LEFT
      Max Steer Angle:  0
      Retractable:      1
    BOGEY Right Main Gear
      Location: 648 , 100 , -84
      Spring Constant:  120000
      Damping Constant: 10000 (linear)
      Rebound Damping Constant: 20000 (linear)
      Dynamic Friction: 0.5
      Static Friction:  0.8
      Rolling Friction: 0.02
      Steering Type:    FIXED
      Grouping:         RIGHT
      Max Steer Angle:  0
      Retractable:      1

  Propulsion:
      FUEL tank holds 10200 lbs. FUEL
      currently at 98.0392% of maximum capacity
      Tank location (X, Y, Z): 520, -80, -18
      Effective radius: 0 inches
      Initial temperature: -9999 Fahrenheit
      Priority: 1
      FUEL tank holds 10200 lbs. FUEL
      currently at 98.0392% of maximum capacity
      Tank location (X, Y, Z): 520, 80, -18
      Effective radius: 0 inches
      Initial temperature: -9999 Fahrenheit
      Priority: 1
      FUEL tank holds 15000 lbs. FUEL
      currently at 26.6667% of maximum capacity
      Tank location (X, Y, Z): 480, 0, -18
      Effective radius: 0 inches
      Initial temperature: -9999 Fahrenheit
      Priority: 1
    2 dimensional table with 6 rows, 8 columns.
		-10000.0000	0.0000	10000.0000	20000.0000	30000.0000	40000.0000	50000.0000	60000.0000	
	0.0000	0.0420	0.0436	0.0528	0.0694	0.0899	0.1183	0.1467	0.0000	
	0.2000	0.0500	0.0501	0.0335	0.0544	0.0797	0.1049	0.1342	0.0000	
	0.4000	0.0040	0.0047	0.0020	0.0272	0.0595	0.0891	0.1203	0.0000	
	0.6000	0.0000	0.0000	0.0000	0.0000	0.0276	0.0718	0.1073	0.0000	
	0.8000	0.0000	0.0000	0.0000	0.0000	0.0174	0.0468	0.0900	0.0000	
	1.0000	0.0000	0.0000	0.0000	0.0000	0.0000	0.0422	0.0700	0.0000	
    Function: propulsion/engine[0]/IdleThrust
    2 dimensional table with 7 rows, 8 columns.
		-10000.0000	0.0000	10000.0000	20000.0000	30000.0000	40000.0000	50000.0000	60000.0000	
	0.0000	1.2600	1.0000	0.7400	0.5340	0.3720	0.2410	0.1490	0.0000	
	0.2000	1.1710	0.9340	0.6970	0.5060	0.3550	0.2310	0.1430	0.0000	
	0.4000	1.1500	0.9210	0.6920	0.5060	0.3570	0.2330	0.1450	0.0000	
	0.6000	1.1810	0.9510	0.7210	0.5320	0.3780	0.2480	0.1540	0.0000	
	0.8000	1.2580	1.0200	0.7820	0.5820	0.4170	0.2750	0.1700	0.0000	
	1.0000	1.3690	1.1200	0.8710	0.6510	0.4750	0.3150	0.1950	0.0000	
	1.2000	0.0000	0.0000	0.0000	0.0000	0.0000	0.0000	0.0000	0.0000	
    Function: propulsion/engine[0]/MilThrust
      X = 540.0000
      Y = -193.0000
      Z = -40.0000
      Pitch = 0.0000 degrees
      Yaw = 0.0000 degrees
    2 dimensional table with 6 rows, 8 columns.
		-10000.0000	0.0000	10000.0000	20000.0000	30000.0000	40000.0000	50000.0000	60000.0000	
	0.0000	0.0420	0.0436	0.0528	0.0694	0.0899	0.1183	0.1467	0.0000	
	0.2000	0.0500	0.0501	0.0335	0.0544	0.0797	0.1049	0.1342	0.0000	
	0.4000	0.0040	0.0047	0.0020	0.0272	0.0595	0.0891	0.1203	0.0000	
	0.6000	0.0000	0.0000	0.0000	0.0000	0.0276	0.0718	0.1073	0.0000	
	0.8000	0.0000	0.0000	0.0000	0.0000	0.0174	0.0468	0.0900	0.0000	
	1.0000	0.0000	0.0000	0.0000	0.0000	0.0000	0.0422	0.0700	0.0000	
    Function: propulsion/engine[1]/IdleThrust
    2 dimensional table with 7 rows, 8 columns.
		-10000.0000	0.0000	10000.0000	20000.0000	30000.0000	40000.0000	50000.0000	60000.0000	
	0.0000	1.2600	1.0000	0.7400	0.5340	0.3720	0.2410	0.1490	0.0000	
	0.2000	1.1710	0.9340	0.6970	0.5060	0.3550	0.2310	0.1430	0.0000	
	0.4000	1.1500	0.9210	0.6920	0.5060	0.3570	0.2330	0.1450	0.0000	
	0.6000	1.1810	0.9510	0.7210	0.5320	0.3780	0.2480	0.1540	0.0000	
	0.8000	1.2580	1.0200	0.7820	0.5820	0.4170	0.2750	0.1700	0.0000	
	1.0000	1.3690	1.1200	0.8710	0.6510	0.4750	0.3150	0.1950	0.0000	
	1.2000	0.0000	0.0000	0.0000	0.0000	0.0000	0.0000	0.0000	0.0000	
    Function: propulsion/engine[1]/MilThrust
      X = 540.0000
      Y = 193.0000
      Z = -40.0000
      Pitch = 0.0000 degrees
      Yaw = 0.0000 degrees

  FCS: FCS: 737

    Channel Pitch

    Loading Component "Pitch Trim Sum" of type: SUMMER
      Minimum limit: -1.000000
      Maximum limit: 1.000000
      INPUTS: 
       elevator-cmd-norm
       pitch-trim-cmd-norm
      OUTPUT: pitch-trim-sum

    Loading Component "Elevator Control" of type: AEROSURFACE_SCALE
      INPUT: pitch-trim-sum
      GAIN: constant value 1.000000
      OUTPUT: elevator-pos-rad
      OUTPUT: elevator-control
      In/Out Mapping:
        Input MIN: -1.0000
        Input MAX: 1.0000
        Output MIN: -0.3000
        Output MAX: 0.3000

    Loading Component "Elevator Normalized" of type: AEROSURFACE_SCALE
      INPUT: elevator-pos-rad
      GAIN: constant value 1.000000
      OUTPUT: elevator-pos-norm
      OUTPUT: elevator-normalized
      In/Out Mapping:
        Input MIN: -0.3000
        Input MAX: 0.3000
        Output MIN: -1.0000
        Output MAX: 1.0000

    Channel Roll

    Loading Component "Roll Trim Sum" of type: SUMMER
      Minimum limit: -1.000000
      Maximum limit: 1.000000
      INPUTS: 
       aileron-cmd-norm
       roll-trim-cmd-norm
      OUTPUT: roll-trim-sum

    Loading Component "Left Aileron Control" of type: AEROSURFACE_SCALE
      INPUT: roll-trim-sum
      GAIN: constant value 1.000000
      OUTPUT: left-aileron-pos-rad
      OUTPUT: left-aileron-control
      In/Out Mapping:
        Input MIN: -1.0000
        Input MAX: 1.0000
        Output MIN: -0.3500
        Output MAX: 0.3500

    Loading Component "Right Aileron Control" of type: AEROSURFACE_SCALE
      INPUT: -roll-trim-sum
      GAIN: constant value 1.000000
      OUTPUT: right-aileron-pos-rad
      OUTPUT: right-aileron-control
      In/Out Mapping:
        Input MIN: -1.0000
        Input MAX: 1.0000
        Output MIN: -0.3500
        Output MAX: 0.3500

    Loading Component "Left aileron Normalized" of type: AEROSURFACE_SCALE
      INPUT: left-aileron-pos-rad
      GAIN: constant value 1.000000
      OUTPUT: left-aileron-pos-norm
      OUTPUT: left-aileron-normalized
      In/Out Mapping:
        Input MIN: -0.3500
        Input MAX: 0.3500
        Output MIN: -1.0000
        Output MAX: 1.0000

    Loading Component "Right aileron Normalized" of type: AEROSURFACE_SCALE
      INPUT: right-aileron-pos-rad
      GAIN: constant value 1.000000
      OUTPUT: right-aileron-pos-norm
      OUTPUT: right-aileron-normalized
      In/Out Mapping:
        Input MIN: -0.3500
        Input MAX: 0.3500
        Output MIN: -1.0000
        Output MAX: 1.0000

    Channel Yaw

    Loading Component "Rudder Command Sum" of type: SUMMER
      Minimum limit: -1.000000
      Maximum limit: 1.000000
      INPUTS: 
       rudder-cmd-norm
       yaw-trim-cmd-norm
      OUTPUT: rudder-command-sum

    Loading Component "Yaw Damper" of type: SCHEDULED_GAIN
    1 dimensional table with 3 rows.
	0.0000	0.0000	
	0.1000	0.0000	
	0.1100	1.0000	
      INPUT: r-aero-rad_sec
      GAIN: constant value 1.000000
      OUTPUT: yaw-damper
      Scheduled by table: 
    1 dimensional table with 3 rows.
	0.0000	0.0000	
	0.1000	0.0000	
	0.1100	1.0000	

    Loading Component "Yaw Damper Final" of type: SCHEDULED_GAIN
    1 dimensional table with 3 rows.
	0.0000	0.0000	
	0.1000	0.0000	
	0.1100	1.0000	
      INPUT: yaw-damper
      GAIN: constant value 1.000000
      OUTPUT: yaw-damper-final
      Scheduled by table: 
    1 dimensional table with 3 rows.
	0.0000	0.0000	
	0.1000	0.0000	
	0.1100	1.0000	

    Loading Component "Rudder Sum" of type: SUMMER
      Minimum limit: -1.000000
      Maximum limit: 1.000000
      INPUTS: 
       rudder-command-sum
       yaw-damper-final
      OUTPUT: rudder-sum

    Loading Component "Rudder Control" of type: AEROSURFACE_SCALE
      INPUT: rudder-sum
      GAIN: constant value 1.000000
      OUTPUT: rudder-pos-rad
      OUTPUT: rudder-control
      In/Out Mapping:
        Input MIN: -1.0000
        Input MAX: 1.0000
        Output MIN: -0.3500
        Output MAX: 0.3500

    Loading Component "Rudder Normalized" of type: AEROSURFACE_SCALE
      INPUT: rudder-pos-rad
      GAIN: constant value 1.000000
      OUTPUT: rudder-pos-norm
      OUTPUT: rudder-normalized
      In/Out Mapping:
        Input MIN: -0.3500
        Input MAX: 0.3500
        Output MIN: -1.0000
        Output MAX: 1.0000

    Channel Flaps

    Loading Component "Flaps Control" of type: KINEMATIC
      INPUT: flap-cmd-norm
      DETENTS: 9
        0.0000 0.0000
        0.1250 5.0000
        0.2500 4.0000
        0.3750 3.0000
        0.5000 2.0000
        0.6250 2.0000
        0.7500 2.0000
        0.8750 2.0000
        1.0000 2.0000
      OUTPUT: flap-pos-norm
      OUTPUT: flaps-control

    Channel Landing Gear

    Loading Component "Gear Control" of type: KINEMATIC
      INPUT: gear-cmd-norm
      DETENTS: 2
        0.0000 0.0000
        1.0000 5.0000
      OUTPUT: gear-pos-norm
      OUTPUT: gear-control

    Channel Flight Spoilers

    Loading Component "Flight Spoilers Control" of type: KINEMATIC
      INPUT: speedbrake-cmd-norm
      DETENTS: 2
        0.0000 0.0000
        1.0000 0.6000
      OUTPUT: speedbrake-pos-norm
      OUTPUT: flight-spoilers-control

    Channel Ground Spoilers

    Loading Component "Ground Spoilers Control" of type: KINEMATIC
      INPUT: spoiler-cmd-norm
      DETENTS: 2
        0.0000 0.0000
        1.0000 0.6000
      OUTPUT: spoiler-pos-norm
      OUTPUT: ground-spoilers-control
    1 dimensional table with 10 rows.
	0.0000	0.0480	
	0.1000	0.5150	
	0.1500	0.6290	
	0.2000	0.7090	
	0.3000	0.8150	
	0.4000	0.8820	
	0.5000	0.9280	
	0.6000	0.9620	
	0.7000	0.9880	
	0.8000	1.0000	
    Function: aero/function/kCDge
    1 dimensional table with 13 rows.
	0.0000	1.2030	
	0.1000	1.1270	
	0.1500	1.0900	
	0.2000	1.0730	
	0.3000	1.0460	
	0.4000	1.0280	
	0.5000	1.0190	
	0.6000	1.0130	
	0.7000	1.0080	
	0.8000	1.0060	
	0.9000	1.0030	
	1.0000	1.0020	
	1.1000	1.0000	
    Function: aero/function/kCLge
    1 dimensional table with 2 rows.
	0.0000	1.0000	
	0.1000	0.8500	
    Function: aero/function/kCLsb
    1 dimensional table with 2 rows.
	0.0000	1.0000	
	0.1000	0.6000	
    Function: aero/function/kCLsp

  Aerodynamics (Lift|Side|Drag axes):

    1 dimensional table with 5 rows.
	-1.5700	1.5000	
	-0.2600	0.0420	
	0.0000	0.0210	
	0.2600	0.0420	
	1.5700	1.5000	
    Function: aero/coefficient/CD0
    Function: aero/coefficient/CDi
    1 dimensional table with 4 rows.
	0.0000	0.0000	
	0.7900	0.0000	
	1.1000	0.0230	
	1.8000	0.0150	
    Function: aero/coefficient/CDmach
    Function: aero/coefficient/CDflap
    Function: aero/coefficient/CDgear
    Function: aero/coefficient/CDsb
    Function: aero/coefficient/CDsp
    1 dimensional table with 5 rows.
	-1.5700	1.2300	
	-0.2600	0.0500	
	0.0000	0.0000	
	0.2600	0.0500	
	1.5700	1.2300	
    Function: aero/coefficient/CDbeta
    Function: aero/coefficient/CDde
    Function: aero/coefficient/CYb
    1 dimensional table with 4 rows.
	-0.2000	-0.6800	
	0.0000	0.2000	
	0.2300	1.2000	
	0.4600	0.2000	
    Function: aero/coefficient/CLalpha
    Function: aero/coefficient/dCLflap
    Function: aero/coefficient/CLde
    Function: aero/coefficient/Clb
    Function: aero/coefficient/Clp
    Function: aero/coefficient/Clr
    1 dimensional table with 2 rows.
	0.0000	0.1000	
	2.0000	0.0330	
    Function: aero/coefficient/Clda
    Function: aero/coefficient/Cldr
    Function: aero/coefficient/Cmalpha
    1 dimensional table with 2 rows.
	0.0000	-1.2000	
	2.0000	-0.3000	
    Function: aero/coefficient/Cmde
    Function: aero/coefficient/Cmq
    Function: aero/coefficient/Cmadot
    Function: aero/coefficient/Cnb
    Function: aero/coefficient/Cnr
    Function: aero/coefficient/Cndr

  Input data set: 0  

  Input data set: 1  

    Declared properties


In file aircraft/737/737.xml: line 911
      Property fcs/aileron-cmd-norm is already defined.

In file aircraft/737/737.xml: line 912
      Property fcs/elevator-cmd-norm is already defined.

In file aircraft/737/737.xml: line 913
      Property fcs/rudder-cmd-norm is already defined.

In file aircraft/737/737.xml: line 914
      Property fcs/throttle-cmd-norm[0] is already defined.

In file aircraft/737/737.xml: line 915
      Property fcs/throttle-cmd-norm[1] is already defined.

In file aircraft/737/737.xml: line 916
      Property simulation/terminate is already defined.
	Model 737 loaded.
'737' Aircraft File has been successfully loaded!
Winsock DLL loaded ...
Creating input TCP socket on port 5137
Successfully bound to TCP input socket on port 5137

Winsock DLL loaded ...
Creating input UDP socket on port 5139
Successfully bound to UDP input socket on port 5139


  Mass Properties Report (English units: lbf, in, slug-ft^2)
                                      Weight    CG-X    CG-Y    CG-Z         Ixx         Iyy         Izz         Ixy         Ixz         Iyz
    Base Vehicle                     83000.0   639.0     0.0   -40.0    562000.0   1473000.0   1894000.0        -0.0      8000.0        -0.0
0   Fuel                               10000     520     -80     -18           0           0           0
1   Fuel                               10000     520      80     -18           0           0           0
2   Fuel                                4000     480       0     -18           0           0           0
                                                                                                                                            
    Total:                          107000.0   610.8     0.0   -35.1    591572.3   1539552.7   1986235.4         0.0     19109.1         0.0

End of vehicle configuration loading.
-------------------------------------------------------------------------------

Simulation completed.
Remember to reset the program by typing clearSF in the matlab command window! 
JSBSim S-Function Reset

and in Simulink you'll have the following outputs:

image

So you just have to try it out and adapt this workflow to your needs.

@huweius
Copy link

huweius commented Aug 4, 2021

Dear Prof. De Marco,

Thanks a lot for the detailed instruction. I followed all the steps and still arrived at some fatal errors:

JSBSimInterface.obj : error LNK2019: unresolved external symbol "public: __cdecl JSBSim::FGFDMExec::FGFDMExec(class JSBSim::FGPropertyManager *,class std::shared_ptr<unsigned int>)"
(??0FGFDMExec@JSBSim@@QEAA@PEAVFGPropertyManager@1@V?$shared_ptr@I@std@@@Z) referenced in function "public: __cdecl JSBSimInterface::JSBSimInterface(double)" (??0JSBSimInterface@@QEAA@N@Z)
JSBSimInterface.obj : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class JSBSim::FGAccelerations> __cdecl JSBSim::FGFDMExec::GetAccelerations(void)const "
(?GetAccelerations@FGFDMExec@JSBSim@@QEBA?AV?$shared_ptr@VFGAccelerations@JSBSim@@@std@@XZ) referenced in function "public: __cdecl JSBSimInterface::JSBSimInterface(double)"
(??0JSBSimInterface@@QEAA@N@Z)
JSBSimInterface.obj : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class JSBSim::FGFCS> __cdecl JSBSim::FGFDMExec::GetFCS(void)const "
(?GetFCS@FGFDMExec@JSBSim@@QEBA?AV?$shared_ptr@VFGFCS@JSBSim@@@std@@XZ) referenced in function "public: __cdecl JSBSimInterface::JSBSimInterface(double)" (??0JSBSimInterface@@QEAA@N@Z)
JSBSimInterface.obj : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class JSBSim::FGPropulsion> __cdecl JSBSim::FGFDMExec::GetPropulsion(void)const "
(?GetPropulsion@FGFDMExec@JSBSim@@QEBA?AV?$shared_ptr@VFGPropulsion@JSBSim@@@std@@XZ) referenced in function "public: __cdecl JSBSimInterface::JSBSimInterface(double)"
(??0JSBSimInterface@@QEAA@N@Z)
JSBSimInterface.obj : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class JSBSim::FGAerodynamics> __cdecl JSBSim::FGFDMExec::GetAerodynamics(void)const "
(?GetAerodynamics@FGFDMExec@JSBSim@@QEBA?AV?$shared_ptr@VFGAerodynamics@JSBSim@@@std@@XZ) referenced in function "public: __cdecl JSBSimInterface::JSBSimInterface(double)"
(??0JSBSimInterface@@QEAA@N@Z)
JSBSimInterface.obj : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class JSBSim::FGAircraft> __cdecl JSBSim::FGFDMExec::GetAircraft(void)const "
(?GetAircraft@FGFDMExec@JSBSim@@QEBA?AV?$shared_ptr@VFGAircraft@JSBSim@@@std@@XZ) referenced in function "public: bool __cdecl JSBSimInterface::Open(class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > const &)" (?Open@JSBSimInterface@@QEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
JSBSimInterface.obj : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class JSBSim::FGPropagate> __cdecl JSBSim::FGFDMExec::GetPropagate(void)const "
(?GetPropagate@FGFDMExec@JSBSim@@QEBA?AV?$shared_ptr@VFGPropagate@JSBSim@@@std@@XZ) referenced in function "public: __cdecl JSBSimInterface::JSBSimInterface(double)"
(??0JSBSimInterface@@QEAA@N@Z)
JSBSimInterface.obj : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class JSBSim::FGAuxiliary> __cdecl JSBSim::FGFDMExec::GetAuxiliary(void)const "
(?GetAuxiliary@FGFDMExec@JSBSim@@QEBA?AV?$shared_ptr@VFGAuxiliary@JSBSim@@@std@@XZ) referenced in function "public: __cdecl JSBSimInterface::JSBSimInterface(double)"
(??0JSBSimInterface@@QEAA@N@Z)
JSBSim_SFunction.mexw64 : fatal error LNK1120: 8 unresolved externals

The environment should be the same as you: JSBSim release 1.1.8 installer, MATLAB R2020b Update 6, Visual C++ 2019 compiler. I copied and replaced everything in the \include directory with everything from \src of the master branch. Is there anything else I've missed?

Thanks a lot for the assistance.

@agodemar
Copy link
Contributor Author

agodemar commented Aug 5, 2021

@huweius it looks like the mex compiler doesn't see the class JSBSim::FGFDMExec, which is declared in the header file <JSBSim root>/include/FGFDMExec.h and packaged in the library file <JSBSim root>/lib/JSBSim.lib.

You should double check the arguments of your mex command. In my system I have this command within the script file <JSBSim root>/myJSBSimSimulinkCompile.m, which is placed in the <JSBSim root>/ directory, one level above the other directories.
The command is the following:

mex -v -R2017b COMPFLAGS='$COMPFLAGS' ./matlab/JSBSim_SFunction.cpp ./matlab/JSBSimInterface.cpp -I".\include" -L".\lib" -lJSBSim  wsock32.lib ws2_32.lib

where

  • the option -I".\include" tells the compiler to search for header files in <JSBSim root>/include
  • the option -L".\lib" tells the linker to search for *.lib files in <JSBSim root>/lib
  • the option -lJSBSim tells the linker to link in the file <JSBSim root>/lib/JSBSim.lib

@Dim1303
Copy link

Dim1303 commented Sep 13, 2021

Hello,
I'm new here and I'm trying to install the JSBsim(v1.1.8) to use with matlab/simulink.
I followed all those steps described above, they really fixed some errors, but it still not working. Other errors are occurring during the compilation process in matlab. The compile are looking for the file "./simgear/props/propertyObject.hxx". I tryied to find it in the JSBSim repository but I didn't found too.
Has anyone had this error?
Thanks in advance.

Below is the copy of matlab command screen, with the error:

Building with 'MinGW64 Compiler (C++)'.
C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\bin\g++ -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2017b -DUSE_MEX_CMD -m64 -DMATLAB_MEX_FILE -I".\include" -I"C:\Program Files\MATLAB\R2018a/extern/include" -I"C:\Program Files\MATLAB\R2018a/simulink/include" -fexceptions -fno-omit-frame-pointer -std=c++11 -O -DNDEBUG "C:\JSBSim\matlab\JSBSim_SFunction.cpp" -o C:\Users\dimit\AppData\Local\Temp\mex_428443625313531_13980\JSBSim_SFunction.obj
Error using mex
In file included from
.\include/input_output/FGPropertyReader.h:44:0,
from .\include/math/FGModelFunctions.h:38,
from .\include/models/FGModel.h:43,
from .\include/models/FGPropagate.h:41,
from .\include/FGFDMExec.h:47,
from C:\JSBSim\matlab\JSBSim_SFunction.cpp:133:
.\include/input_output/FGPropertyManager.h:45:44: fatal error:
simgear/props/propertyObject.hxx: No such file or directory
compilation terminated.
Error in JSBSimSimulinkCompile (line 6)
mex -v -R2017b COMPFLAGS='$COMPFLAGS'
./matlab/JSBSim_SFunction.cpp ./matlab/JSBSimInterface.cpp
-I".\include" -L".\lib" -lJSBSim wsock32.lib ws2_32.lib

@agodemar
Copy link
Contributor Author

@Dim1303 I see that you are using Matlab v2018a. My tests are valid for Matlab v2020a and v2020b. In addition, you are using MinGW64 Compiler (C++); my suggestion is to use Visual Studio 2019 Community Edition.

@Dim1303
Copy link

Dim1303 commented Sep 13, 2021

Professor De Marco, thank you so much for the support.

I have uninstalled and installed the JSBSim to do the modifications step by step (just to check), now I'm using the Matlab v2020a with the MEX configured to use 'Microsoft Visual C++ 2019 (C)' for C language compilation. The error is a little bit different now:

--
Building with 'Microsoft Visual C++ 2019'.
cl /c /Zp8 /GR /W3 /EHs /nologo /MD /O2 /Oy- /DNDEBUG /DMX_COMPAT_64 /DMATLAB_MEXCMD_RELEASE=R2017b /DUSE_MEX_CMD /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE -I".\include" -I"C:\Program Files\Polyspace\R2020a\extern\include" -I"C:\Program Files\Polyspace\R2020a\simulink\include" "C:\JSBSim\matlab\JSBSim_SFunction.cpp" /FoC:\Users\dimit\AppData\Local\Temp\mex_483405025434860_14092\JSBSim_SFunction.obj
Error using mex
JSBSim_SFunction.cpp
C:\JSBSim\include\input_output/FGPropertyManager.h(45): fatal error C1083: NÆo ‚
poss¡vel abrir arquivo incluir: 'simgear/props/propertyObject.hxx': No such file or
directory

Error in myJSBSimSimulinkCompile (line 5)
mex -v -R2017b COMPFLAGS='$COMPFLAGS' ./matlab/JSBSim_SFunction.cpp
./matlab/JSBSimInterface.cpp -I".\include" -L".\lib" -lJSBSim wsock32.lib ws2_32.lib

@agodemar
Copy link
Contributor Author

@Dim1303 you are right, the file propertyObject.hxx was missing in the link that I gave in my original post. I have edited the hyperlink that now points to this zip archive, released as v1.1.8 source code.
Then, follow Step 2 of my original post:

  1. Copy all *.hxx files from the folder simgear, including the whole directory structure, from the path <JSBSim root>/src/simgear to <JSBSim root>/include/simgear and get the following tree:
<JSBSim root>/
   ...
   include/
      simgear/
         io/
            iostreams/
         magvar/
         misc/
         props/
         structure/
         xml/

At this point your compilation should work fine.

@Dim1303
Copy link

Dim1303 commented Sep 14, 2021

Thank you so much @agodemar. It worked perfectly.

@bcoconni
Copy link
Member

There are some header files missing in the current distribution, namely all *.hxx files related to simgear.

That's weird, the following line is supposed to include all files named *.hxx and process recursively all the folders under src/ i.e. including src/simgear

Source: "${CMAKE_SOURCE_DIR}\src\*.hxx"; DestDir: "{app}\include"; Flags: recursesubdirs; Components: devfiles

Download from the sources the following files: TestJSBSim.m and ex737cruise.slx and save them in <JSBSim root>/, besides <JSBSim root>/JSBSim_SFunction.mexw64.

@bcoconni These two files are missing from those packaged in the JSBSim setup executable on Windows. Probably this is fine, but we'll have to adjust our readme files to tell users how to start working with them on Matlab.

OK we could provide them under a new installer category Matlab test files or similar so that they could be installed optionally.

@huweius
Copy link

huweius commented Sep 18, 2021

I'm afraid I'm still getting a different error for building this S-function despite copying all of the required headers and following Prof. de Marco's instructions. Compiler used was MEX with VS 2019. How could this type of type-casting error exist?

Error using mex
JSBSimInterface.cpp
C:\JSBSim\matlab\JSBSimInterface.cpp(41): error C2440: '=': cannot convert from 'std::shared_ptr<JSBSim::FGPropagate>' to 'JSBSim::FGPropagate *'
C:\JSBSim\matlab\JSBSimInterface.cpp(41): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\JSBSim\matlab\JSBSimInterface.cpp(42): error C2440: '=': cannot convert from 'std::shared_ptr<JSBSim::FGAccelerations>' to 'JSBSim::FGAccelerations *'
C:\JSBSim\matlab\JSBSimInterface.cpp(42): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\JSBSim\matlab\JSBSimInterface.cpp(43): error C2440: '=': cannot convert from 'std::shared_ptr<JSBSim::FGAuxiliary>' to 'JSBSim::FGAuxiliary *'
C:\JSBSim\matlab\JSBSimInterface.cpp(43): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\JSBSim\matlab\JSBSimInterface.cpp(44): error C2440: '=': cannot convert from 'std::shared_ptr<JSBSim::FGAerodynamics>' to 'JSBSim::FGAerodynamics *'
C:\JSBSim\matlab\JSBSimInterface.cpp(44): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\JSBSim\matlab\JSBSimInterface.cpp(45): error C2440: '=': cannot convert from 'std::shared_ptr<JSBSim::FGPropulsion>' to 'JSBSim::FGPropulsion *'
C:\JSBSim\matlab\JSBSimInterface.cpp(45): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\JSBSim\matlab\JSBSimInterface.cpp(46): error C2440: '=': cannot convert from 'std::shared_ptr<JSBSim::FGFCS>' to 'JSBSim::FGFCS *'
C:\JSBSim\matlab\JSBSimInterface.cpp(46): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\JSBSim\matlab\JSBSimInterface.cpp(56): error C2440: '=': cannot convert from 'std::shared_ptr<JSBSim::FGPropagate>' to 'JSBSim::FGPropagate *'
C:\JSBSim\matlab\JSBSimInterface.cpp(56): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\JSBSim\matlab\JSBSimInterface.cpp(57): error C2440: '=': cannot convert from 'std::shared_ptr<JSBSim::FGAccelerations>' to 'JSBSim::FGAccelerations *'
C:\JSBSim\matlab\JSBSimInterface.cpp(57): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\JSBSim\matlab\JSBSimInterface.cpp(58): error C2440: '=': cannot convert from 'std::shared_ptr<JSBSim::FGAuxiliary>' to 'JSBSim::FGAuxiliary *'
C:\JSBSim\matlab\JSBSimInterface.cpp(58): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\JSBSim\matlab\JSBSimInterface.cpp(59): error C2440: '=': cannot convert from 'std::shared_ptr<JSBSim::FGAerodynamics>' to 'JSBSim::FGAerodynamics *'
C:\JSBSim\matlab\JSBSimInterface.cpp(59): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\JSBSim\matlab\JSBSimInterface.cpp(60): error C2440: '=': cannot convert from 'std::shared_ptr<JSBSim::FGPropulsion>' to 'JSBSim::FGPropulsion *'
C:\JSBSim\matlab\JSBSimInterface.cpp(60): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\JSBSim\matlab\JSBSimInterface.cpp(61): error C2440: '=': cannot convert from 'std::shared_ptr<JSBSim::FGFCS>' to 'JSBSim::FGFCS *'
C:\JSBSim\matlab\JSBSimInterface.cpp(61): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called



Error in JSBSimSimulinkCompile (line 5)
mex -v -R2017b COMPFLAGS='$COMPFLAGS' ./matlab/JSBSim_SFunction.cpp ./matlab/JSBSimInterface.cpp -I".\include" -L".\lib" -lJSBSim  wsock32.lib ws2_32.lib

@bcoconni
Copy link
Member

bcoconni commented Sep 18, 2021

@huweius you most likely downloaded the header files from the master branch and compiled them along with the library from the version 1.1.8 installer.
Is the problem fixed when you download headers from the 1.1.8 branch (https://github.com/JSBSim-Team/jsbsim/tree/v1.1.8) ?

@huweius
Copy link

huweius commented Sep 20, 2021

@huweius you most likely downloaded the header files from the master branch and compiled them along with the library from the version 1.1.8 installer.
Is the problem fixed when you download headers from the 1.1.8 branch (https://github.com/JSBSim-Team/jsbsim/tree/v1.1.8) ?

Thanks! That does solve it.

@bcoconni
Copy link
Member

That's weird, the following line is supposed to include all files named *.hxx and process recursively all the folders under src/ i.e. including src/simgear [...]

Well, I just realized this line has been modified after 1.1.8 was released... That explains it 😞

@bcoconni
Copy link
Member

bcoconni commented Nov 7, 2021

That's weird, the following line is supposed to include all files named *.hxx and process recursively all the folders under src/ i.e. including src/simgear [...]

Well, I just realized this line has been modified after 1.1.8 was released... That explains it 😞

This should now be fixed in JSBSim version 1.1.9 that has just been released 🎉

@bcoconni bcoconni changed the title Setting up the the JSBSim interface to Matlab on Windows Setting up the JSBSim interface to Matlab on Windows Nov 7, 2021
@bcoconni bcoconni added the bug label Nov 7, 2021
@bcoconni
Copy link
Member

bcoconni commented Nov 8, 2021

Download from the sources the following files: TestJSBSim.m and ex737cruise.slx and save them in <JSBSim root>/, besides <JSBSim root>/JSBSim_SFunction.mexw64.

@bcoconni These two files are missing from those packaged in the JSBSim setup executable on Windows. Probably this is fine, but we'll have to adjust our readme files to tell users how to start working with them on Matlab.

Oh man ! I forgot to include TestJSBSim.m and ex737cruise.slx in the Windows installer 🤦

@bcoconni
Copy link
Member

bcoconni commented Nov 8, 2021

This has been fixed by the commit 131517f. I also took this opportunity to add the license files to the Windows installer by the way.

@agodemar
Copy link
Contributor Author

agodemar commented Nov 9, 2021

@bcoconni thanks
this JSBSim interface to Matlab/Simulink topic is getting hot on LinkedIn.
This video that I've posted has got more than 18k visualizations in less than one week ;-)

@bcoconni
Copy link
Member

Yeah, I noticed a surge in how much JSBSim GitHub project has been starred recently. By the way, there has been another rise last July when you published a post in LinkedIn about JSBSim now having a Simulink interface (this was for release 1.1.8)

Stargazers over time

Stargazers over time

@bcoconni
Copy link
Member

Oh man ! I forgot to include TestJSBSim.m and ex737cruise.slx in the Windows installer 🤦

This is now fixed in release 1.1.10. I checked on my side and could find the files in JSBSim-1.1.10-setup.exe. However I cannot build the S-Function as I do not own a copy of Matlab. Could one of you check that the S-Function can be built from the material included in JSBSim-1.1.10-setup.exe ?

Thanks.

@scienceasdf
Copy link

scienceasdf commented Dec 28, 2021

Hello, I'm new here and I'm trying to install the JSBsim(v1.1.8) to use with matlab/simulink. I followed all those steps described above, they really fixed some errors, but it still not working. Other errors are occurring during the compilation process in matlab. The compile are looking for the file "./simgear/props/propertyObject.hxx". I tryied to find it in the JSBSim repository but I didn't found too. Has anyone had this error? Thanks in advance.

Below is the copy of matlab command screen, with the error:

Building with 'MinGW64 Compiler (C++)'. C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\bin\g++ -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2017b -DUSE_MEX_CMD -m64 -DMATLAB_MEX_FILE -I".\include" -I"C:\Program Files\MATLAB\R2018a/extern/include" -I"C:\Program Files\MATLAB\R2018a/simulink/include" -fexceptions -fno-omit-frame-pointer -std=c++11 -O -DNDEBUG "C:\JSBSim\matlab\JSBSim_SFunction.cpp" -o C:\Users\dimit\AppData\Local\Temp\mex_428443625313531_13980\JSBSim_SFunction.obj Error using mex In file included from .\include/input_output/FGPropertyReader.h:44:0, from .\include/math/FGModelFunctions.h:38, from .\include/models/FGModel.h:43, from .\include/models/FGPropagate.h:41, from .\include/FGFDMExec.h:47, from C:\JSBSim\matlab\JSBSim_SFunction.cpp:133: .\include/input_output/FGPropertyManager.h:45:44: fatal error: simgear/props/propertyObject.hxx: No such file or directory compilation terminated. Error in JSBSimSimulinkCompile (line 6) mex -v -R2017b COMPFLAGS='$COMPFLAGS' ./matlab/JSBSim_SFunction.cpp ./matlab/JSBSimInterface.cpp -I".\include" -L".\lib" -lJSBSim wsock32.lib ws2_32.lib

@Dim1303 See #548. You can follow the instructions to build matlab mex file with MinGW-w64 toolset.

@bcoconni
Copy link
Member

bcoconni commented Jan 6, 2022

FYI, the Matlab guys just announced that Matlab actions for GitHub are now available for Windows and MacOS X. I'll therefore update our CI later this week to check that JSBSim S-Function also builds successfully on Windows and MacOS X (currently only checking on Linux).

@seanmcleod
Copy link
Member

Should be useful in terms of minimizing the number of Matlab build issue requests we get 😉

@bcoconni
Copy link
Member

bcoconni commented Jan 8, 2022

Well matlab-actions/setup-matlab@v1.1.0 does not include the header file mclcppclass.h yet for MacOSX and Windows. I have submitted the issue to matlab-actions/setup-matlab#18. Hopefully that will be fixed.

@bcoconni
Copy link
Member

bcoconni commented Jan 8, 2022

Well matlab-actions/setup-matlab@v1.1.0 does not include the header file mclcppclass.h yet for MacOSX and Windows. I have submitted the issue to matlab-actions/setup-matlab#18. Hopefully that will be fixed.

False alarm, the header file mclcppclass.h is actually not needed. The S-Function now compiles on the 3 platforms Linux, Windows, MacOSX. I still have a couple of details to fix. We are almost there ! 😄

@bcoconni
Copy link
Member

bcoconni commented Jan 9, 2022

MATLAB S-Functions are now built by our CI workflow for the 3 major platforms (Windows, Linux, MacOSX) since the commit db4d967 that I pushed yesterday night.

CMake is now taking care of building the S-Function from the ground up as soon as you set the flag BUILD_MATLAB_SFUNCTION to ON (i.e. cmake -DBUILD_MATLAB_SFUNCTION=ON .. using the command line). May be someone could document how to set this flag to ON on Visual Studio and launch the build with CMake from within Visual Studio ? This procedure would be useful for users who build and compile JSBSim themselves using Visual Studio.

For the users who use the Windows installer to install JSBSim, I guess we should also update matlab/JSBSimSimulinkCompile.m to compile out of the box for a pristine installation of JSBSim using our Windows installer ? This would mainly involve updating the paths to the library and to the headers, wouldn't it ? From the release 1.1.10 and on, the Windows installer is supposed to provide all needed files so there should no longer have a need to download additional files and move them around prior to having a MEX file. Could someone please confirm this last statement ?

@seanmcleod
Copy link
Member

seanmcleod commented Jan 9, 2022

I'll take a look in terms of Visual Studio, although I won't be able to fully test since I don't have a copy of Matlab. Do you know off-hand if the matlab github action setup can be installed locally so that I could at least test building locally. I still wouldn't be able to actually test the s-function DLL in Matlab/Simulink.

@agodemar I'm pretty sure has a Matlab license, so he's probably the best bet in terms of being able to fully test this on Windows with Visual Studio etc.

I am a bit confused about the combination of the CMake build support we now have and JSBSimSimulinkCompile.m. Aren't they basically doing the same thing? Both invoking Matlab's MEX tool to generate the S-Function .mex/.dll?

I guess similar to how we have support for building JSBSim using CMake, the official mechanism, but also provide Visual Studio .sln/.vcxproj files?

@seanmcleod
Copy link
Member

CMake is now taking care of building the S-Function from the ground up as soon as you set the flag BUILD_MATLAB_SFUNCTION to ON (i.e. cmake -DBUILD_MATLAB_SFUNCTION=ON .. using the command line). May be someone could document how to set this flag to ON on Visual Studio

To set BUILD_MATLAB_SFUNCTION select Manage Configurations...

image

Documentation on this can be found at - https://docs.microsoft.com/en-us/cpp/build/customize-cmake-settings?view=msvc-170

@bcoconni
Copy link
Member

bcoconni commented Jan 10, 2022

I am a bit confused about the combination of the CMake build support we now have and JSBSimSimulinkCompile.m. Aren't they basically doing the same thing? Both invoking Matlab's MEX tool to generate the S-Function .mex/.dll?

I agree they are doing the same thing but, in my opinion, there are not targeting the same audience.

CMake is for C++ programmers

CMake takes care of setting automatically the include and library paths as well as the compile flags depending on the user configuration. Especially, if one change the MSVC configuration from Release to Debug then the compilation will take place in a different folder (build/Debug instead of build/Release for that particular example) so you would need to manually update JSBSimSimulinkCompile.m to reflect that change - something that's easy to overlook. So I'd say that a programmer needs CMake to take care of the gory compilation details and focus on the "important" topics.

JSBSimSimulinkCompile.m is for MATLAB users.

In my view (but I may be wrong), a user that downloads our Windows installer to get the S-Function will not be interested in compiling the library and that sort of thing. Instead I guess they expect having a MATLAB script that automagically compiles the S-Function using a simple command line in MATLAB. That's where JSBSimSimulinkCompile.m shines especially since the relative paths are imposed by the installer so the library and include paths can be hardcoded in JSBSimSimulinkCompile.m.

@seanmcleod
Copy link
Member

My wild guess, could be way off 😉 is that 90+% of Matlab users simply want a pre-built binary of the S-Function when downloading the Windows installer so that they can incorporate it into their larger Simulink setup with no need or desire to compile the S-function code.

...to get the S-Function will not be interested in compiling the library and that sort of thing.

My guess is they don't really want to compile either the JSBSim lib or the S-Function.

So I guess I was wondering whether it makes sense in terms of catering to the ~10% (wild guess) of Matlab users who want to make source code changes and then compile to offer both the CMake option as well as the JSBSimSimulinkCompile.m option.

@bcoconni
Copy link
Member

bcoconni commented Jan 11, 2022

My wild guess, could be way off 😉 is that 90+% of Matlab users simply want a pre-built binary of the S-Function when downloading the Windows installer so that they can incorporate it into their larger Simulink setup with no need or desire to compile the S-function code.

...to get the S-Function will not be interested in compiling the library and that sort of thing.

My guess is they don't really want to compile either the JSBSim lib or the S-Function.

So I guess I was wondering whether it makes sense in terms of catering to the ~10% (wild guess) of Matlab users who want to make source code changes and then compile to offer both the CMake option as well as the JSBSimSimulinkCompile.m option.

I would tend to be in complement agreement with you but @agodemar told me otherwise in discussion #484.
Quoting @agodemar:

I think that as we begin to support Matlab S-Functions in JSBSim, it's fine having the user to take care of mex file builds.

However if we reconsider this statement, it's quite easy to release the MEX files that our GitHub actions build.

@seanmcleod
Copy link
Member

However if we reconsider this statement, it's quite easy to release the MEX files that our GitHub actions build.

Ah, I assumed once you had added the CMake support for building the mex file that you were bundling the mex file with the installer.

But glancing through that discussion I noticed your comment:

While I browsed the internet, I saw that distributing compiled mex files seems not to be the way to go since you need to get an S-function which has been compiled for the very version of Matlab that you are using, under the same platform and most likely with the same compiler.

Which I guess means that if we were to try and supply pre-built mex files then we'd need to ideally supply a whole bunch, e.g.

  • jsbsim-matlab-2020a-compiler1.mex
  • jsbsim-matlab-2020a-compiler2.mex
  • jsbsim-matlab-2021a-compiler1.mex
  • jsbsim-matlab-2021a-compiler1.mex
  • etc.

Which does seem like a whole lot of work 😉

So if we don't supply pre-built mex files then yes maybe the easiest/lowest friction option would be for users to use JSBSimSimulinkCompile.m to pick up the relevant version of Matlab and also their configured compiler.

And as you say if a user wants to make say source changes to JSBSim as well before building their mex file then they can go-ahead and use the CMake option.

So pretty much ignore everything else I said earlier 😉

So let's leave both compile options, and maybe generate a Wiki page with build info/instuctions, e.g. how to configure CMake in Visual Studio for building the mex file etc. Describing both the CMake option and the JSBSimSimulinkCompile option etc.

@agodemar
Copy link
Contributor Author

So let's leave both compile options, and maybe generate a Wiki page with build info/instuctions, e.g. how to configure CMake in Visual Studio for building the mex file etc. Describing both the CMake option and the JSBSimSimulinkCompile option etc.

Agreed

@bcoconni
Copy link
Member

Ah, I assumed once you had added the CMake support for building the mex file that you were bundling the mex file with the installer.

Well, the installer is not managed by CMake but by our CI workflow:

# Build the Windows installer
- name: Checkout JSBSim logos
if: env.release == 'true'
id: InstallLogos
uses: actions/checkout@v2
with:
repository: JSBSim-Team/jsbsim-logo
path: jsbsim-logo
- name: Build JSBSim installer for Windows
if: steps.InstallLogos.outcome == 'success'
id: BuildInstaller
working-directory: build
run: |
# Relocate the logos for the wizard installer
mkdir logos
cp ..\jsbsim-logo\wizard_installer\*.bmp logos\.
mkdir small
cp ..\jsbsim-logo\wizard_installer\small\*.bmp small\.
# Relocate the executables for the installer
cp src\RelWithDebInfo\JSBSim.exe src\.
cp src\RelWithDebInfo\JSBSim.lib src\.
cp utils\aeromatic++\RelWithDebInfo\aeromatic.exe utils\aeromatic++\.
# Get the MSVC C++ DLL
$Paths = $Env:PATH+';'+[System.Environment]::SystemDirectory
foreach($path in $Paths -split ';') {
if (Test-Path $path) {
$File = Get-ChildItem -Path $path | Where-Object {$_.Name -eq 'msvcp140.dll'}
if ($File) {
cp $File.FullName .
break;
}
}
}
# Compile the installer with Inno Setup
iscc JSBSim.iss

and the list of files that should be installed by the installer is managed in the file JSBSim.iss.in.

Which I guess means that if we were to try and supply pre-built mex files then we'd need to ideally supply a whole bunch, e.g.

  • jsbsim-matlab-2020a-compiler1.mex

  • jsbsim-matlab-2020a-compiler2.mex

  • jsbsim-matlab-2021a-compiler1.mex

  • jsbsim-matlab-2021a-compiler1.mex

  • etc.

Which does seem like a whole lot of work 😉

As long as the dull work is done by computers this is not much of an issue 😄. In my opinion, the real problem would be that we cannot cover every possible combinations of MATLAB versions and compiler versions: at the moment, GitHub supports Visual Studio Enterprise 2019 and Visual Studio Enterprise 2022 (Visual Studio Enterprise 2017 is being deprecated) and the MATLAB setup action supports MATLAB R2021a+. So even if we would release a mex file for every combination that GitHub Actions allows, we would still need the JSBSimSimulinkCompile.m script for other compiler/MATLAB versions.

So let's leave both compile options, and maybe generate a Wiki page with build info/instuctions, e.g. how to configure CMake in Visual Studio for building the mex file etc. Describing both the CMake option and the JSBSimSimulinkCompile option etc.

Yes, I think all the needed material is in the comments of the current issue. All we need is to collect it and make a tutorial out of it. I guess we need to release v1.1.11 before that, but I'd like to fix #553 first.

@bcoconni
Copy link
Member

bcoconni commented Jan 18, 2022

Instead I guess they expect having a MATLAB script that automagically compiles the S-Function using a simple command line in MATLAB. That's where JSBSimSimulinkCompile.m shines especially since the relative paths are imposed by the installer so the library and include paths can be hardcoded in JSBSimSimulinkCompile.m.

I'd like to clarify the parameters that are used by the mex command.

  • Should users modify the parameter -R2017b to match the MATLAB version that is installed on their computer ?
  • Is COMPFLAGS mandatory ?

%mex -v -R2017b COMPFLAGS='$COMPFLAGS' ./matlab/JSBSim_SFunction.cpp ./matlab/JSBSimInterface.cpp -I".\out\install\x64-Release\include\JSBSim" -L".\out\install\x64-Release\lib" -lJSBSim wsock32.lib ws2_32.lib

@bcoconni
Copy link
Member

I'd like to clarify the parameters that are used by the mex command.

Well, so I RTFM for mex 😉

  • Should users modify the parameter -R2017b to match the MATLAB version that is installed on their computer ?

According to the mex documentation, this parameter selects the API that is used for matrices. There are basically two options at the moment -R2017b (which is the default) and -R2018a. So we'll stick to the default for now i.e. -R2017b.

  • Is COMPFLAGS mandatory ?

According to the mex documentation, no. So we'll pass on this argument for now. Note that the keyword used for compiler options depends on the platform ☹️

bcoconni added a commit to bcoconni/jsbsim that referenced this issue Jan 23, 2022
…e folder installed by the Windows installer.

See discussion in issue JSBSim-Team#491.
@bcoconni
Copy link
Member

So if we don't supply pre-built mex files then yes maybe the easiest/lowest friction option would be for users to use JSBSimSimulinkCompile.m to pick up the relevant version of Matlab and also their configured compiler.

This is now implemented by commit 2c12a7b.

bcoconni added a commit to bcoconni/jsbsim that referenced this issue Feb 5, 2022
…e folder installed by the Windows installer.

See discussion in issue JSBSim-Team#491.
@bcoconni
Copy link
Member

Following the release of JSBSim v1.1.11, all the bugs reported in this issue have been fixed. This issue is closed. Please open a new issue if some further issues are encountered.

@lemondada777
Copy link

您好 JSBSimmers!

我已经设法在 Windows 上下载并安装了JSBSim 版本 v1.1.8,其中包括新发布的 Matlab 接口。 然而,除非您添加一些标题并在 Matlab 端做一些额外的工作,否则该界面在 Windows 上无法直接使用。 您可以采取以下措施使其发挥作用:

  1. 下载安装程序并在以下本地目录树中设置 JSBSim:
<JSBSim root>/
   aeromatic++/
   aircraft/
   data_output/
   engine/
   include/
   lib/
   matlab/
   scripts/
   systems/
   JSBSim.exe
   msvcp140.dll

您系统上的确切位置<JSBSim root>/取决于您选择安装 JSBSim 的位置。

  1. 当前发行版中缺少一些头文件,即所有*.hxxsimgear. 您必须将所有丢失的头文件,包括它们的目录结构,从源代码树复制到以下本地安装树:
<JSBSim root>/
   ...
   include/
      simgear/
         io/
            iostreams/
         magvar/
         misc/
         props/
         structure/
         xml/

@bcoconni这是在 Windows 上打包 JSBSim 设置可执行文件时应在下一版本中修复的重要步骤。

  1. 现在,让我们看看您在 Matlab 方面需要做的额外工作。

以下步骤针对我已安装在我的系统上的_Matlab v2020b进行了测试。_

要在 Windows 上编译该文件<JSBSim root>/matlab/JSBSim_SFunction.cpp并获取 MEX 文件JSBSim_SFunction.mexw64,您需要一个可用的 C++ 编译器。在可用选项中,我建议您选择Visual Studio 2019 社区版

一旦你有一个工作的 C++ 开发环境,你需要从 Matlab 命令行告诉 MEX 实用程序什么是默认的 C++ 编译器。您可以使用以下命令执行此操作:

[Matlab prompt]>> mex -setup CPP

MEX 将检测您的 C++ 编译器并将配置为构建您的*.mexw64文件。

  1. 调整 Matlab 脚本<JSBSim root>/matlab/JSBSimSimulinkCompile.m以构建您自己的 MEX 文件。

首先,将脚本复制<JSBSim root>/matlab/JSBSimSimulinkCompile.m到您自己<JSBSim root>/myJSBSimSimulinkCompile.m 的 JSBSim 安装目录根目录下的版本中。这是有道理的,因为我们想要一个<JSBSim root>/JSBSim.exe位于.aircraft``engine``scripts``systems

这是脚本的**<JSBSim root>/myJSBSimSimulinkCompile.m**样子:

disp('Compiling S-function from JSBSim...');
mex -v -R2017b COMPFLAGS='$COMPFLAGS' ./matlab/JSBSim_SFunction.cpp ./matlab/JSBSimInterface.cpp -I".\include" -L".\lib" -lJSBSim  wsock32.lib ws2_32.lib
disp('Finished.')

如果您将当前的_Matlab 工作目录_指向<JSBSim root>/并从 Matlab 编辑器或命令行运行上述 M 文件:

[Matlab prompt]>> myJSBSimSimulinkCompile

你会得到 MEX 文件<JSBSim root>/JSBSim_SFunction.mexw64

  1. 测试您的 MEX 文件<JSBSim root>/JSBSim_SFunction.mexw64

从源下载以下文件:TestJSBSim.m并将ex737cruise.slx它们保存在 中<JSBSim root>/,此外<JSBSim root>/JSBSim_SFunction.mexw64.

@bcoconni这两个文件在 Windows 上的 JSBSim 安装可执行文件中缺少。可能这很好,但我们必须调整我们的自述文件以告诉用户如何开始在 Matlab 上使用它们。

<JSBSim root>/TestJSBSim.m将是这样的:

disp('Run 737 example');
fprintf('Current directory: %s', pwd)
sim('ex737cruise');
clear functions;
clear all;
disp('JSBSim S-Function Reset');

这是打开文件时 Simulink 的屏幕截图<JSBSim root>/ex737cruise.slx

图片

JSBSim_SFunction特别是,当您双击Simulink 模块时,它是这样显示的:

图片

当您运行测试脚本时,您将在 Matlab 命令窗口中看到以下输出:

>> TestJSBSim
Run 737 example
Current directory: C:\Users\agodemar\JSBSim
Warning: 'Output Port 3' of 'ex737cruise/S-Function' is not connected. 
> In TestJSBSim (line 3) 


     JSBSim Flight Dynamics Model v1.1.8 [GitHub build 588/commit c943f83deeb3e14bed7939ac65dfac789a7a0181] Jul 24 2021 16:18:42
            [JSBSim-ML v2.0]

JSBSim startup beginning ...

Simulation dt set to 0.008333
Script input: scripts/737_cruise 
Reset file: 'cruise_init' .

JSBSim S-Function is initializing...

Note: For Aircraft with integrators in the FCS, please type 'clearSF' to completely reset S-Function.

	Setting up JSBSim with standard 'aircraft', 'engine', and 'system' paths.
	Loading aircraft '737' ...
Reading Aircraft Configuration File: 737
                            Version: 2.0


This aircraft model is a BETA release!!!

This aircraft model probably will not fly as expected.

Use this model for development purposes ONLY!!!

  Description:   Models a Boeing 737.
  Model Author:  Dave Culp
  Creation Date: 2006-01-04
  Version:       $Revision: 1.43 $

  Aircraft Metrics:
    WingArea: 1171
    WingSpan: 94.7
    Incidence: 0
    Chord: 12.31
    H. Tail Area: 348
    H. Tail Arm: 48.04
    V. Tail Area: 297
    V. Tail Arm: 44.5
    Eyepoint (x, y, z): 80 , -30 , 70
    Ref Pt (x, y, z): 625 , 0 , 24
    Visual Ref Pt (x, y, z): 0 , 0 , 0

  Mass and Balance:
    baseIxx: 562000 slug-ft2
    baseIyy: 1.473e+06 slug-ft2
    baseIzz: 1.894e+06 slug-ft2
    baseIxy: -0 slug-ft2
    baseIxz: 8000 slug-ft2
    baseIyz: -0 slug-ft2
    Empty Weight: 83000 lbm
    CG (x, y, z): 639 , 0 , -40

  Ground Reactions: 
    BOGEY Nose Gear
      Location: 158 , 0 , -84
      Spring Constant:  90000
      Damping Constant: 4000 (linear)
      Rebound Damping Constant: 8000 (linear)
      Dynamic Friction: 0.5
      Static Friction:  0.8
      Rolling Friction: 0.02
      Steering Type:    STEERABLE
      Grouping:         NONE
      Max Steer Angle:  35
      Retractable:      1
    BOGEY Left Main Gear
      Location: 648 , -100 , -84
      Spring Constant:  120000
      Damping Constant: 10000 (linear)
      Rebound Damping Constant: 20000 (linear)
      Dynamic Friction: 0.5
      Static Friction:  0.8
      Rolling Friction: 0.02
      Steering Type:    FIXED
      Grouping:         LEFT
      Max Steer Angle:  0
      Retractable:      1
    BOGEY Right Main Gear
      Location: 648 , 100 , -84
      Spring Constant:  120000
      Damping Constant: 10000 (linear)
      Rebound Damping Constant: 20000 (linear)
      Dynamic Friction: 0.5
      Static Friction:  0.8
      Rolling Friction: 0.02
      Steering Type:    FIXED
      Grouping:         RIGHT
      Max Steer Angle:  0
      Retractable:      1

  Propulsion:
      FUEL tank holds 10200 lbs. FUEL
      currently at 98.0392% of maximum capacity
      Tank location (X, Y, Z): 520, -80, -18
      Effective radius: 0 inches
      Initial temperature: -9999 Fahrenheit
      Priority: 1
      FUEL tank holds 10200 lbs. FUEL
      currently at 98.0392% of maximum capacity
      Tank location (X, Y, Z): 520, 80, -18
      Effective radius: 0 inches
      Initial temperature: -9999 Fahrenheit
      Priority: 1
      FUEL tank holds 15000 lbs. FUEL
      currently at 26.6667% of maximum capacity
      Tank location (X, Y, Z): 480, 0, -18
      Effective radius: 0 inches
      Initial temperature: -9999 Fahrenheit
      Priority: 1
    2 dimensional table with 6 rows, 8 columns.
		-10000.0000	0.0000	10000.0000	20000.0000	30000.0000	40000.0000	50000.0000	60000.0000	
	0.0000	0.0420	0.0436	0.0528	0.0694	0.0899	0.1183	0.1467	0.0000	
	0.2000	0.0500	0.0501	0.0335	0.0544	0.0797	0.1049	0.1342	0.0000	
	0.4000	0.0040	0.0047	0.0020	0.0272	0.0595	0.0891	0.1203	0.0000	
	0.6000	0.0000	0.0000	0.0000	0.0000	0.0276	0.0718	0.1073	0.0000	
	0.8000	0.0000	0.0000	0.0000	0.0000	0.0174	0.0468	0.0900	0.0000	
	1.0000	0.0000	0.0000	0.0000	0.0000	0.0000	0.0422	0.0700	0.0000	
    Function: propulsion/engine[0]/IdleThrust
    2 dimensional table with 7 rows, 8 columns.
		-10000.0000	0.0000	10000.0000	20000.0000	30000.0000	40000.0000	50000.0000	60000.0000	
	0.0000	1.2600	1.0000	0.7400	0.5340	0.3720	0.2410	0.1490	0.0000	
	0.2000	1.1710	0.9340	0.6970	0.5060	0.3550	0.2310	0.1430	0.0000	
	0.4000	1.1500	0.9210	0.6920	0.5060	0.3570	0.2330	0.1450	0.0000	
	0.6000	1.1810	0.9510	0.7210	0.5320	0.3780	0.2480	0.1540	0.0000	
	0.8000	1.2580	1.0200	0.7820	0.5820	0.4170	0.2750	0.1700	0.0000	
	1.0000	1.3690	1.1200	0.8710	0.6510	0.4750	0.3150	0.1950	0.0000	
	1.2000	0.0000	0.0000	0.0000	0.0000	0.0000	0.0000	0.0000	0.0000	
    Function: propulsion/engine[0]/MilThrust
      X = 540.0000
      Y = -193.0000
      Z = -40.0000
      Pitch = 0.0000 degrees
      Yaw = 0.0000 degrees
    2 dimensional table with 6 rows, 8 columns.
		-10000.0000	0.0000	10000.0000	20000.0000	30000.0000	40000.0000	50000.0000	60000.0000	
	0.0000	0.0420	0.0436	0.0528	0.0694	0.0899	0.1183	0.1467	0.0000	
	0.2000	0.0500	0.0501	0.0335	0.0544	0.0797	0.1049	0.1342	0.0000	
	0.4000	0.0040	0.0047	0.0020	0.0272	0.0595	0.0891	0.1203	0.0000	
	0.6000	0.0000	0.0000	0.0000	0.0000	0.0276	0.0718	0.1073	0.0000	
	0.8000	0.0000	0.0000	0.0000	0.0000	0.0174	0.0468	0.0900	0.0000	
	1.0000	0.0000	0.0000	0.0000	0.0000	0.0000	0.0422	0.0700	0.0000	
    Function: propulsion/engine[1]/IdleThrust
    2 dimensional table with 7 rows, 8 columns.
		-10000.0000	0.0000	10000.0000	20000.0000	30000.0000	40000.0000	50000.0000	60000.0000	
	0.0000	1.2600	1.0000	0.7400	0.5340	0.3720	0.2410	0.1490	0.0000	
	0.2000	1.1710	0.9340	0.6970	0.5060	0.3550	0.2310	0.1430	0.0000	
	0.4000	1.1500	0.9210	0.6920	0.5060	0.3570	0.2330	0.1450	0.0000	
	0.6000	1.1810	0.9510	0.7210	0.5320	0.3780	0.2480	0.1540	0.0000	
	0.8000	1.2580	1.0200	0.7820	0.5820	0.4170	0.2750	0.1700	0.0000	
	1.0000	1.3690	1.1200	0.8710	0.6510	0.4750	0.3150	0.1950	0.0000	
	1.2000	0.0000	0.0000	0.0000	0.0000	0.0000	0.0000	0.0000	0.0000	
    Function: propulsion/engine[1]/MilThrust
      X = 540.0000
      Y = 193.0000
      Z = -40.0000
      Pitch = 0.0000 degrees
      Yaw = 0.0000 degrees

  FCS: FCS: 737

    Channel Pitch

    Loading Component "Pitch Trim Sum" of type: SUMMER
      Minimum limit: -1.000000
      Maximum limit: 1.000000
      INPUTS: 
       elevator-cmd-norm
       pitch-trim-cmd-norm
      OUTPUT: pitch-trim-sum

    Loading Component "Elevator Control" of type: AEROSURFACE_SCALE
      INPUT: pitch-trim-sum
      GAIN: constant value 1.000000
      OUTPUT: elevator-pos-rad
      OUTPUT: elevator-control
      In/Out Mapping:
        Input MIN: -1.0000
        Input MAX: 1.0000
        Output MIN: -0.3000
        Output MAX: 0.3000

    Loading Component "Elevator Normalized" of type: AEROSURFACE_SCALE
      INPUT: elevator-pos-rad
      GAIN: constant value 1.000000
      OUTPUT: elevator-pos-norm
      OUTPUT: elevator-normalized
      In/Out Mapping:
        Input MIN: -0.3000
        Input MAX: 0.3000
        Output MIN: -1.0000
        Output MAX: 1.0000

    Channel Roll

    Loading Component "Roll Trim Sum" of type: SUMMER
      Minimum limit: -1.000000
      Maximum limit: 1.000000
      INPUTS: 
       aileron-cmd-norm
       roll-trim-cmd-norm
      OUTPUT: roll-trim-sum

    Loading Component "Left Aileron Control" of type: AEROSURFACE_SCALE
      INPUT: roll-trim-sum
      GAIN: constant value 1.000000
      OUTPUT: left-aileron-pos-rad
      OUTPUT: left-aileron-control
      In/Out Mapping:
        Input MIN: -1.0000
        Input MAX: 1.0000
        Output MIN: -0.3500
        Output MAX: 0.3500

    Loading Component "Right Aileron Control" of type: AEROSURFACE_SCALE
      INPUT: -roll-trim-sum
      GAIN: constant value 1.000000
      OUTPUT: right-aileron-pos-rad
      OUTPUT: right-aileron-control
      In/Out Mapping:
        Input MIN: -1.0000
        Input MAX: 1.0000
        Output MIN: -0.3500
        Output MAX: 0.3500

    Loading Component "Left aileron Normalized" of type: AEROSURFACE_SCALE
      INPUT: left-aileron-pos-rad
      GAIN: constant value 1.000000
      OUTPUT: left-aileron-pos-norm
      OUTPUT: left-aileron-normalized
      In/Out Mapping:
        Input MIN: -0.3500
        Input MAX: 0.3500
        Output MIN: -1.0000
        Output MAX: 1.0000

    Loading Component "Right aileron Normalized" of type: AEROSURFACE_SCALE
      INPUT: right-aileron-pos-rad
      GAIN: constant value 1.000000
      OUTPUT: right-aileron-pos-norm
      OUTPUT: right-aileron-normalized
      In/Out Mapping:
        Input MIN: -0.3500
        Input MAX: 0.3500
        Output MIN: -1.0000
        Output MAX: 1.0000

    Channel Yaw

    Loading Component "Rudder Command Sum" of type: SUMMER
      Minimum limit: -1.000000
      Maximum limit: 1.000000
      INPUTS: 
       rudder-cmd-norm
       yaw-trim-cmd-norm
      OUTPUT: rudder-command-sum

    Loading Component "Yaw Damper" of type: SCHEDULED_GAIN
    1 dimensional table with 3 rows.
	0.0000	0.0000	
	0.1000	0.0000	
	0.1100	1.0000	
      INPUT: r-aero-rad_sec
      GAIN: constant value 1.000000
      OUTPUT: yaw-damper
      Scheduled by table: 
    1 dimensional table with 3 rows.
	0.0000	0.0000	
	0.1000	0.0000	
	0.1100	1.0000	

    Loading Component "Yaw Damper Final" of type: SCHEDULED_GAIN
    1 dimensional table with 3 rows.
	0.0000	0.0000	
	0.1000	0.0000	
	0.1100	1.0000	
      INPUT: yaw-damper
      GAIN: constant value 1.000000
      OUTPUT: yaw-damper-final
      Scheduled by table: 
    1 dimensional table with 3 rows.
	0.0000	0.0000	
	0.1000	0.0000	
	0.1100	1.0000	

    Loading Component "Rudder Sum" of type: SUMMER
      Minimum limit: -1.000000
      Maximum limit: 1.000000
      INPUTS: 
       rudder-command-sum
       yaw-damper-final
      OUTPUT: rudder-sum

    Loading Component "Rudder Control" of type: AEROSURFACE_SCALE
      INPUT: rudder-sum
      GAIN: constant value 1.000000
      OUTPUT: rudder-pos-rad
      OUTPUT: rudder-control
      In/Out Mapping:
        Input MIN: -1.0000
        Input MAX: 1.0000
        Output MIN: -0.3500
        Output MAX: 0.3500

    Loading Component "Rudder Normalized" of type: AEROSURFACE_SCALE
      INPUT: rudder-pos-rad
      GAIN: constant value 1.000000
      OUTPUT: rudder-pos-norm
      OUTPUT: rudder-normalized
      In/Out Mapping:
        Input MIN: -0.3500
        Input MAX: 0.3500
        Output MIN: -1.0000
        Output MAX: 1.0000

    Channel Flaps

    Loading Component "Flaps Control" of type: KINEMATIC
      INPUT: flap-cmd-norm
      DETENTS: 9
        0.0000 0.0000
        0.1250 5.0000
        0.2500 4.0000
        0.3750 3.0000
        0.5000 2.0000
        0.6250 2.0000
        0.7500 2.0000
        0.8750 2.0000
        1.0000 2.0000
      OUTPUT: flap-pos-norm
      OUTPUT: flaps-control

    Channel Landing Gear

    Loading Component "Gear Control" of type: KINEMATIC
      INPUT: gear-cmd-norm
      DETENTS: 2
        0.0000 0.0000
        1.0000 5.0000
      OUTPUT: gear-pos-norm
      OUTPUT: gear-control

    Channel Flight Spoilers

    Loading Component "Flight Spoilers Control" of type: KINEMATIC
      INPUT: speedbrake-cmd-norm
      DETENTS: 2
        0.0000 0.0000
        1.0000 0.6000
      OUTPUT: speedbrake-pos-norm
      OUTPUT: flight-spoilers-control

    Channel Ground Spoilers

    Loading Component "Ground Spoilers Control" of type: KINEMATIC
      INPUT: spoiler-cmd-norm
      DETENTS: 2
        0.0000 0.0000
        1.0000 0.6000
      OUTPUT: spoiler-pos-norm
      OUTPUT: ground-spoilers-control
    1 dimensional table with 10 rows.
	0.0000	0.0480	
	0.1000	0.5150	
	0.1500	0.6290	
	0.2000	0.7090	
	0.3000	0.8150	
	0.4000	0.8820	
	0.5000	0.9280	
	0.6000	0.9620	
	0.7000	0.9880	
	0.8000	1.0000	
    Function: aero/function/kCDge
    1 dimensional table with 13 rows.
	0.0000	1.2030	
	0.1000	1.1270	
	0.1500	1.0900	
	0.2000	1.0730	
	0.3000	1.0460	
	0.4000	1.0280	
	0.5000	1.0190	
	0.6000	1.0130	
	0.7000	1.0080	
	0.8000	1.0060	
	0.9000	1.0030	
	1.0000	1.0020	
	1.1000	1.0000	
    Function: aero/function/kCLge
    1 dimensional table with 2 rows.
	0.0000	1.0000	
	0.1000	0.8500	
    Function: aero/function/kCLsb
    1 dimensional table with 2 rows.
	0.0000	1.0000	
	0.1000	0.6000	
    Function: aero/function/kCLsp

  Aerodynamics (Lift|Side|Drag axes):

    1 dimensional table with 5 rows.
	-1.5700	1.5000	
	-0.2600	0.0420	
	0.0000	0.0210	
	0.2600	0.0420	
	1.5700	1.5000	
    Function: aero/coefficient/CD0
    Function: aero/coefficient/CDi
    1 dimensional table with 4 rows.
	0.0000	0.0000	
	0.7900	0.0000	
	1.1000	0.0230	
	1.8000	0.0150	
    Function: aero/coefficient/CDmach
    Function: aero/coefficient/CDflap
    Function: aero/coefficient/CDgear
    Function: aero/coefficient/CDsb
    Function: aero/coefficient/CDsp
    1 dimensional table with 5 rows.
	-1.5700	1.2300	
	-0.2600	0.0500	
	0.0000	0.0000	
	0.2600	0.0500	
	1.5700	1.2300	
    Function: aero/coefficient/CDbeta
    Function: aero/coefficient/CDde
    Function: aero/coefficient/CYb
    1 dimensional table with 4 rows.
	-0.2000	-0.6800	
	0.0000	0.2000	
	0.2300	1.2000	
	0.4600	0.2000	
    Function: aero/coefficient/CLalpha
    Function: aero/coefficient/dCLflap
    Function: aero/coefficient/CLde
    Function: aero/coefficient/Clb
    Function: aero/coefficient/Clp
    Function: aero/coefficient/Clr
    1 dimensional table with 2 rows.
	0.0000	0.1000	
	2.0000	0.0330	
    Function: aero/coefficient/Clda
    Function: aero/coefficient/Cldr
    Function: aero/coefficient/Cmalpha
    1 dimensional table with 2 rows.
	0.0000	-1.2000	
	2.0000	-0.3000	
    Function: aero/coefficient/Cmde
    Function: aero/coefficient/Cmq
    Function: aero/coefficient/Cmadot
    Function: aero/coefficient/Cnb
    Function: aero/coefficient/Cnr
    Function: aero/coefficient/Cndr

  Input data set: 0  

  Input data set: 1  

    Declared properties


In file aircraft/737/737.xml: line 911
      Property fcs/aileron-cmd-norm is already defined.

In file aircraft/737/737.xml: line 912
      Property fcs/elevator-cmd-norm is already defined.

In file aircraft/737/737.xml: line 913
      Property fcs/rudder-cmd-norm is already defined.

In file aircraft/737/737.xml: line 914
      Property fcs/throttle-cmd-norm[0] is already defined.

In file aircraft/737/737.xml: line 915
      Property fcs/throttle-cmd-norm[1] is already defined.

In file aircraft/737/737.xml: line 916
      Property simulation/terminate is already defined.
	Model 737 loaded.
'737' Aircraft File has been successfully loaded!
Winsock DLL loaded ...
Creating input TCP socket on port 5137
Successfully bound to TCP input socket on port 5137

Winsock DLL loaded ...
Creating input UDP socket on port 5139
Successfully bound to UDP input socket on port 5139


  Mass Properties Report (English units: lbf, in, slug-ft^2)
                                      Weight    CG-X    CG-Y    CG-Z         Ixx         Iyy         Izz         Ixy         Ixz         Iyz
    Base Vehicle                     83000.0   639.0     0.0   -40.0    562000.0   1473000.0   1894000.0        -0.0      8000.0        -0.0
0   Fuel                               10000     520     -80     -18           0           0           0
1   Fuel                               10000     520      80     -18           0           0           0
2   Fuel                                4000     480       0     -18           0           0           0
                                                                                                                                            
    Total:                          107000.0   610.8     0.0   -35.1    591572.3   1539552.7   1986235.4         0.0     19109.1         0.0

End of vehicle configuration loading.
-------------------------------------------------------------------------------

Simulation completed.
Remember to reset the program by typing clearSF in the matlab command window! 
JSBSim S-Function Reset

在 Simulink 中,您将获得以下输出:

图片

因此,您只需尝试一下并根据您的需要调整此工作流程。
Can I design its control law in matlab to directly input it for control?

@bcoconni
Copy link
Member

bcoconni commented May 7, 2022

FYI I have copied the content of this issue in a README file located in matlab/README.md. That way users should be able to locate the instructions accumulated above in a single document.

Of course, comments are welcome about the content of matlab/README.md.

@bcoconni bcoconni added the MATLAB Topics linked to the MATLAB S-Function label Sep 26, 2022
@jevta23
Copy link

jevta23 commented Jun 24, 2023

Dear Professor De Marco,

I have installed JSBSim (version 1.1.13) last week, but I have a problem with outputs from S-function in Simulink. I cannot figure out why model doesn't accept the throttle command from the joystick. I have checked functionality of the joystick, and it's working, but when I want to drive the plane (c172p) in the simulation environment, there is a problem with generating thrust. Furthermore, I have noticed that elevation and aileron commands work only when I set the initial velocity (w, vc, or vt) in the initialization xml file. Do you have any suggestions how to fix this problem, and how can I set up the files before running the Simulink model? Thanks in advance!

Kind regards,
Đorđe Jevtić
Ph.D. Student & Junior Research Assistant
University of Belgrade, Faculty of Mechanical Engineering

@agodemar
Copy link
Contributor Author

@jevta23 you should open a new issue and give all possible details about your problem.

@jevta23
Copy link

jevta23 commented Jun 25, 2023

Dear Professor @agodemar ,

Thanks for your quick reply! I have opened a new issue and tried to explain my problem.

Kind regards,
Đorđe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug MATLAB Topics linked to the MATLAB S-Function Support request
Projects
None yet
Development

No branches or pull requests

8 participants