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

No way to handle repetitive work. (Was "XML copypasta" on jsbsim-users). #83

Closed
ghost opened this issue Jul 2, 2018 · 11 comments
Closed

Comments

@ghost
Copy link

ghost commented Jul 2, 2018

Is there a better way to program repetitive chains of functions than
simply copypasting?

For example, here I had to do a lot of copypasta for each pump and valve, and
now if I decide to fix something I will have to do it all over again:

https://gitlab.com/mdanil/Tu-144/blob/master/Tu-144-jsbsim/propulsion/fuel.xml

And is there a way to include a system passing some XML entities to
it in the tag? The way I have to handle repetitive
systems now is creating multiple files and editing the entities
manually, which is tedious and error prone, like:

https://gitlab.com/mdanil/Tu-144/blob/master/Tu-144-jsbsim/propulsion/RD-36-51A_0.xml
https://gitlab.com/mdanil/Tu-144/blob/master/Tu-144-jsbsim/propulsion/RD-36-51A_1.xml
https://gitlab.com/mdanil/Tu-144/blob/master/Tu-144-jsbsim/propulsion/RD-36-51A_2.xml
https://gitlab.com/mdanil/Tu-144/blob/master/Tu-144-jsbsim/propulsion/RD-36-51A_3.xml

I have been looking for the proper XML way on and off, and realised I
don't even know what question to search to get info about how the
'something="something"' part of XML tags is related to entities.

@ghost
Copy link
Author

ghost commented Jul 5, 2018

One more example -- distance functions for each INS waypoint:

https://gitlab.com/mdanil/Tu-144/blob/master/Tu-144-jsbsim/NPK/Orbita/func/dist.xml

@bcoconni
Copy link
Member

bcoconni commented Jul 5, 2018

@Mike402
There are already some features in JSBSim to handle the duplication of XML definitions. At the moment they are limited to:

  • engines definition where you can use the special character # to replace the engine number.
  • file inclusion with the file= attribute

If we plan to extend that to other elements, I think we should design how the thing should work before going any further. An important point to my view is consistency with the existing features.

Suggestions ?

@ghost
Copy link
Author

ghost commented Jul 5, 2018 via email

@bcoconni
Copy link
Member

bcoconni commented Dec 29, 2018

@Mike402 @abassign
To respond to the request of reducing the duplication of XML code in your aircraft models, I just pushed a new commit a7574e8 to JSBSim and 27ddcedad to FlightGear that allows to use "template functions" everywhere in JSBSim. The idea is to have generic functions which can be repeatedly used in the aircraft models.

For example, say you need to multiply some values by 2 in several places in your model. First, you need to declare a template function like below:

<function name="twice" type="template"> <!-- the type "template" tells JSBSim that it is a special function that will be evaluated later -->
  <product>
    <property> # </property> <!-- The character # stands for the variable of the function -->
    <value> 2.0 </value>
  </product>
</function>

Notice in particular the usage of the special character #. It can appear several times in a given template function.

The second step is to use that template function everywhere you need it. For that you must use the attribute apply of a property.

<function name="fct1">
  <sum>
    <pi>
    <property apply="twice"> prop1 </property> <!-- the attribute apply="twice" tells JSBSim to apply the template function "twice" to the property "prop1" before proceeding to the evaluation of the function "fct1"-->
    <sin>
      <property apply="twice"> theta </property> <!-- same as above -->
    </sin>
  </sum>
</function>

This is equivalent to

<function name="fct1">
  <sum>
    <pi>
    <product>
      <property> prop1 </property>
      <value> 2.0 </value>
    </product>
    <sin>
      <product>
        <property> theta </property>
        <value> 2.0 </value>
      </product>
    </sin>
  </sum>
</function>

The feature is available in the branch next of FlightGear. Could you please test that feature and give feedback in that issue report ? Since you both requested to have a feature similar to that, or asked for new functions, I suppose that you can be beta testers ? 😃

@ghost
Copy link
Author

ghost commented Jan 4, 2019

Thanks, it will take me a while to wrap my head around this and come up with an efficient use scheme, but this already looks useful!

I think #84 can be merged with this issue, as now there's cyclic clipto, and beside that sawtooth functions can be done as templates?

@ghost
Copy link
Author

ghost commented Jan 4, 2019

But I can immediately say that if the number of arguments is limited to 1, this would be limited to only the simplest use cases?

@bcoconni
Copy link
Member

bcoconni commented Jan 5, 2019

But I can immediately say that if the number of arguments is limited to 1, this would be limited to only the simplest use cases ?

I am sure people can be creative about using such a feature 😃 And I'd rather discuss about how to solve a problem on a real case rather than jumping to negative conclusions. This is not very supportive regarding the amount of time that has been involved in developing this feature 😭

@ghost
Copy link
Author

ghost commented Jan 5, 2019 via email

@bcoconni
Copy link
Member

bcoconni commented Jan 5, 2019

No no I didn't meant to say it's useless, I, for one, can immediately think of a hundred uses for it in my plane.

This was purposely provocative 😈 to point out that we should focus on problem solving rather than on general statements. I'm sure you will find plenty of creative ways to use the template function feature 😄

I'm just saying that with multi-argument support it would have been maybe five hundred.

Right but we should move one step at a time.

My plan is to collect feedback about the current implementation of template functions with uses, problems and bugs issued from real case uses. Only then we might consider improvements or changes to the feature.

I have had bad experiences about over-engineering things due to wrong anticipations of future needs of users. This ended up with additional, almost useless, code to maintain for backward compatibility and a redesign of the feature.

@OpenUAS
Copy link

OpenUAS commented Mar 18, 2021

Maybe time then to close this issue? @bcoconni your remarks look wise and indicating years of real life development experience, thanks 🥇 Hope to see you working on JSBsim in the long long future.

@bcoconni
Copy link
Member

@OpenUAS I guess you are right. We got no feedback on that feature for 2 years now, it seems it's time to close the issue now.
If someone wants to report some bugs/feature request please open a new issue. Feedback and support will be handled in Discussions.

Hope to see you working on JSBsim in the long long future.

I've been involved in the project for more than 10 years now. Who knows may be there are some more 10 years of involvement ahead of me ? 😄 Anyway thanks for the positive feedback it's always very much appreciated 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants