Thoughts on overhauling the MATLAB S-Function? #627
Replies: 13 comments 19 replies
-
Out of interest what is your research topic? I'd say continue the discussion here in terms of your proposed improvements. I did discuss 1 or 2 proposed changes to the S-Function with @agodemar who wrote the original S-Function many years ago, but I never got round to making them. |
Beta Was this translation helpful? Give feedback.
-
@noah-curran here is a link to #498 (comment) some of my comments about modifying the current s-function. In terms of your setup, I presume the control loop, say for example one implementing a g-command FBW law, is going to be implemented in Simulink? As opposed to being implemented in the JSBSim aircraft model? Given that both options are available when using the JSBSim s-function. If you're modelling actuators, again will they be modelled in Simulink which then simply outputs a control surface deflection angle to JSBSim, or will you use the actuator model available in JSBSim? Which leads me to my final question. Are the anomalous/adversarial control inputs going to be input at the level of the command law, e.g. if 4g was commanded, will the anomalous control input be modelled as changing that 4g to some delta, or will the anomalous inputs be implemented by adding some delta to the final control surface deflection? |
Beta Was this translation helpful? Give feedback.
-
I'm going to be doing development of the MATLAB S-Function on my fork of JSBSim: A few things I've noticed and made some changes to:
In making these changes, I'm starting to appreciate @agodemar's suggestion to generalize the parameters. Besides for the problem of the number of engines capable of being controlled, I think there are several other control inputs that could become necessary in the future. Some other state output could also become useful. While it might be a few days of labor at least, I think generalizing it will just make it less painful. I'm probably going to dig into this tomorrow and see where it goes. |
Beta Was this translation helpful? Give feedback.
-
In terms of generalizing this is what I was suggesting.
So some sort of ini file along these lines. [OutputPort 0]
velocities/u-fps
velocities/v-fps
velocities/w-fps
velocities/p-rad_sec
velocities/q-rad_sec
velocities/r-rad_sec
position/h-sl-ft
position/long-gc-rad
position/lat-gc-rad
attitude/phi-rad
attitude/theta-rad
attitude/psi-rad
[OutputPort 1]
...
... So if I'm working with a piston engined aircraft then I would include properties for mixture, but exclude them if I'm working on a turbine engine model. If I'm interested in fuel flow for example then I include the relevant property to have it available for my Simulink model otherwise I don't bother including it. If I'm working with a multi-engine model then I include properties for multiple engines, e.g. As opposed to have some massive union of all/most properties that clutter up the Simulink port blocks most of which I don't want, or if the subset we currently expose via the hard-coded set in the C++ source doesn't include what I need then I have to go and edit C++ code and recompile etc. |
Beta Was this translation helpful? Give feedback.
-
I don't have an overall spec. These were just some of my observations when I reviewed the code when it was submitted. I don't actually use Matlab/Simulink for my work, I use JSBSim pretty much as is with some minor tweaks of my own in the VSS (Variable Stability System) simulator that I developed to help with test pilot training.
Don't see why not. PropertyManager->Tie("fcs/elevator-cmd-norm", this, &FGFCS::GetDeCmd, &FGFCS::SetDeCmd); One thing though I would do is cache the property lookup for performance reasons, especially if users want to run thousands of simulations faster than real-time, see @bcoconni's comment - #530 (comment) FGPropertyManager* pm = fdm->GetPropertyManager();
FGPropertyNode* node = pm->GetNode("/my/property/name");
while (fdm->Run()) {
x = node->getDoubleValue();
} So cache the property nodes for each property specified in the Simulink ports. |
Beta Was this translation helpful? Give feedback.
-
Regarding the file that configures the ports, we can adopt the XML format, along the lines: <?xml version="1.0"?>
<s_function_config>
<outputs>
<output name="Output 1">
<property> velocities/vc-kts </property>
<property> accelerations/a-pilot-x-ft_sec2 </property>
<property> accelerations/a-pilot-y-ft_sec2 </property>
<property> accelerations/a-pilot-z-ft_sec2 </property>
<property> attitude/phi-rad </property>
<property> attitude/theta-rad </property>
<property> attitude/psi-rad </property>
</output>
<output name="Output 2">
<property> position/h-agl-ft </property>
<property> position/lat-gc-deg </property>
<property> position/long-gc-deg </property>
</output>
</outputs>
</s_function_config> |
Beta Was this translation helpful? Give feedback.
-
@agodemar @seanmcleod Thanks for this tips. I think this shouldn't be too difficult of a task. |
Beta Was this translation helpful? Give feedback.
-
@agodemar @seanmcleod Great news, I have a preliminary version of the configurable port input/output feature working pretty well on my fork: One thing to note is that I also added a <?xml version="1.0"?>
<s_function_config>
<input>
<property> fcs/elevator-cmd-norm </property>
</input>
<outputs>
<output name="Output 1">
<property> velocities/vc-kts </property>
<property> accelerations/a-pilot-x-ft_sec2 </property>
<property> accelerations/a-pilot-y-ft_sec2 </property>
<property> accelerations/a-pilot-z-ft_sec2 </property>
<property> attitude/phi-rad </property>
<property> attitude/theta-rad </property>
<property> attitude/psi-rad </property>
</output>
<output name="Output 2">
<property>position/h-agl-ft</property>
<property>position/lat-gc-deg</property>
<property>position/long-gc-deg</property>
</output>
</outputs>
</s_function_config> Another thing to note is that the ports, while named in the xml file, cannot be dynamically named in the S-Function, as it is unsupported by MATLAB at the moment. Who knows if they will ever add this feature, but if they do I made a comment in the code of where it would be best to add it. A final thing to note is that because the I/O ports to the S-Function are dynamic, I believe a single initial run is required to get the ports to pop up in the correct configuration. I haven't had enough time to play around with this to confirm this though. I'm sure there is a bug or two, but I'm going to tackle a stress test tomorrow to double check and do some clean-up. The next task I'm going to go after is allowing weather input to the S-Function. |
Beta Was this translation helpful? Give feedback.
-
Great news @noah-curran Regarding the initialization of the simulink block, I would try the callback mechanism. That is, you can use callbacks for various events in the lifecycle of a Simulink project. There is one event that is triggered when the project is loaded up, that we can use to initialize the S-Function block. |
Beta Was this translation helpful? Give feedback.
-
So I think what @agodemar is requesting is an array of values for the input to be fed in on each time step, e.g. say for I guess for example he could pre-generate a doublet input. |
Beta Was this translation helpful? Give feedback.
-
@seanmcleod Honestly, I don't see why that would be useful here. Why not just generate your values and feed them to the S-Function one at time? This is what every data source block does in Simulink. I have never seen values stack up in this way besides for in Laplace functions that have a time delay on input. Since in this case there is no need for this functionality for JSBSim's input, I don't see the usefulness here. |
Beta Was this translation helpful? Give feedback.
-
@agodemar will have to motivate given his usage of Simulink. |
Beta Was this translation helpful? Give feedback.
-
@noah-curran ready to submit a pull request yet? |
Beta Was this translation helpful? Give feedback.
-
Hi all, thank you for your hard work on this project. After a long search for a good tool for data collection for my current research paper, we landed on JSBSim after discovering the MATLAB S-Function that @sthelia put together (thanks a ton!).
I've noticed it could use some major work with cleaning up and trimming some unnecessary parts / bugs in it. For instance, the altitude outputs to meters instead of feet (I think this is a bug), and adding documentation for MacOS compiling (just worked this out this past weekend).
I'm wondering if there is any interest in opening up a discussion if I were to overhaul some parts of it? This project seems promising for my own research, so if I were to make some changes while conducting my research I'd love to discuss contributing what I can.
Thanks,
Noah
Beta Was this translation helpful? Give feedback.
All reactions