Adding states/information to the S-function outputs in JSBSim-Simulink integration #498
Replies: 6 comments 2 replies
-
Hi @Chris2814 an important feature of JSBSim is the fact that the internal property tree is exposed to the user. The class JSBSimInterface provides the functions |
Beta Was this translation helpful? Give feedback.
-
@Chris2814 I'm no Matlab/MEX expert, haven't actually used the S-function feature, but glancing at the code you'll notice, first off that there are 4 output ports defined with a hard-coded set of JSBSim states that are output via the output ports. if (!ssSetNumOutputPorts(S, 4)) return; The first output port, index 0, is set as the port for the Discrete States Output port 0 - Discrete States ssSetNumDiscStates(S, 12);
ssSetOutputPortWidth(S, 0, 12);//The model has 12 states:[u v w p q r h-sl-ft long lat phi theta psi] Output port 1 - Flight controls output /* Flight Controls output [thr-pos-norm left-ail-pos-rad right-ail-pos-rad el-pos-rad rud-pos-rad flap-pos-norm ]
speedbrake-pos-rad spoiler-pos-rad gear-pos-norm] */
ssSetOutputPortWidth(S, 1, 9); Output port 2 - Propulsion Outputs /* Propulsion output piston (per engine) [prop-rpm prop-thrust-lbs mixture fuel-flow-gph advance-ratio power-hp pt-lbs_sqft
* volumetric-efficiency bsfc-lbs_hphr prop-torque blade-angle prop-pitch]
* Propulsion output turbine (per engine) [thrust-lbs n1 n2 fuel-flow-pph fuel-flow-pps pt-lbs_sqft pitch-rad reverser-rad yaw-rad inject-cmd
* set-running fuel-dump]
*/
ssSetOutputPortWidth(S, 2, 48); //currently not in use, could be defined later Output port 3 - // Calculated outputs [pilot-Nz alpha alpha-dot beta beta-dot vc-fps vc-kts Vt-fps vg-fps mach climb-rate qbar-psf el-cmd-norm]
ssSetOutputPortWidth(S, 3, 13); I don't know enough about Matlab/Simulink to understand the distinction between the discrete states versus the other states that are output via the other output ports. But if you want to add additional states like drag forces etc. I guess the first thing to figure out/decide is which output port you're going to add the drag forces to. Then update the hard-coded values in terms of the relevant port width. In terms of how these states are retrieved from JSBSim and added to the relevant output port take a look at the following: jsbsim/matlab/JSBSimInterface.cpp Lines 678 to 701 in d53cb46 jsbsim/matlab/JSBSimInterface.cpp Lines 703 to 726 in d53cb46 jsbsim/matlab/JSBSimInterface.cpp Lines 728 to 747 in d53cb46 So once you've decided which output port you want to add your new states to, then you would edit the relevant method above to retrieve the state information from JSBSim and copy it to the relevant output port and index. |
Beta Was this translation helpful? Give feedback.
-
What I was wondering while glancing at the source code was whether you couldn't make the whole set of states and output ports dynamic in terms of reading a set of property names from a config file and use that to set up the output ports during initialization etc. and also use it during each time step to retrieve the property values from JSBSim. That way any user who wanted to use the JSBSim S-Function with their own unique set of states could simply edit the config file and therefore wouldn't need to understand any C++ coding and wouldn't need to have to recompile the S-Function DLL. When I first started looking at the source code in |
Beta Was this translation helpful? Give feedback.
-
I created that function to make things general in case of future developments of the |
Beta Was this translation helpful? Give feedback.
-
Hi, Thank you for your replies @agodemar and @seanmcleod, they are much appreciated! So far I have managed to figure out how to change the outputs from the S-function. As you mentioned there are 4 output ports. The propulsion output port was previously not in use, but I managed to get it functioning and I currently use it as a "test output port". I have observed the other output ports and how values are retrieved for the different elements of those output vectors. But I haven't really figured out how to, by the same measure, retrieve information using functions defined in other classes than those currently used. Allow me to elaborate with an example: In the class FGFCS there are a bunch of different functions to be used for retrieving the position of various control surfaces (GetDePos, GetDrPos, GetDsbPos...). These functions are used and called upon to output the position of the control surfaces through the control output port in the S-function. I would like to be able to, in the same manner as for the FGFCS functions, call upon functions defined in other classes and output the returned values through the output ports in the S-function. For instance, in the class FGTank there is a function called "GetPctFull". The function returns the filled value of the tank in percent. I would like to be able to call on that function and output the returned value on one of the output ports in the S-function. I know how to change the output ports once the function is call-able, but my skills fail me when it comes to calling this function. Probably due to me not knowing where to modify the code more than at the definition of the output ports (JSBSimInterace.cpp). I am somewhat familiar with the GetPropertyValue. I am however not aware if I can use it for the purpose described above. I suppose that the returned value from the GetPctFull function needs to be defined as a property somewhere for me to be able to retrieve it through the GetPropertyValue function? I found some native properties in the JSBSim manual. Those native properties where retrieve-able through the GetPropertyValue function at least :) I like the idea of a configurable file! If time allows me in the future, perhaps that is something to start working on! :) |
Beta Was this translation helpful? Give feedback.
-
In terms of properties they're defined/bound to methods typically in a You'll notice on line 465 a jsbsim/src/models/propulsion/FGTank.cpp Lines 454 to 489 in d53cb46 |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am currently setting up JSBSim with Matlab/Simulink to be used with system simulation of the flight control system. So far I've been successful with compiling and running JSBSim in Simulink, but I would want to access and output more information from JSBSim. For instance:
And I would also like to be able to change the fuel mass during simulation (due to system power consumption simulated outside of JSBSim).
I've been trying to reverse engineer how the current information (states, pilot, control) is accessed and conveyed through the output ports of the S-function. My C++ knowledge is however not sufficient for figuring out how to access and convey the information listed above.
Are there any guidelines to be found on how to add, virtually any information used during the simulation, and add it to the vectors outputted from the S-function?
Thanks in advance!
Kind regards,
Christopher
Beta Was this translation helpful? Give feedback.
All reactions