Board index FlightGear Development Aircraft Flight dynamics model

How to combine a JSBsim switch and table ?  Topic is solved

Good sims require good FDMs (the "thing" that makes an aircraft behave like an aircraft).

How to combine a JSBsim switch and table ?

Postby TheEagle » Sat Nov 13, 2021 10:31 pm

I am trying to implement a basic damage system in JSBsim.

When the left wing hits the ground or the airspeed exceeds 250 kts, the wing should get damaged. This could easily be implemented using a <switch>:
Code: Select all
<switch name="Left wing damage">
    <output>damage/left-wing</output>
    <default value="damage/left-wing"></default>
    <test logic="OR" value="1">
         contacts/unit[3]/compression-ft gt 1
         /velocities/airspeed-kt gt 250
    </test>
</switch>

But naturally, the wing won't suddenly break away when you go over 250 kts - rather, the damage increases with increasing airspeed. Solution is to use an <fcs_function> with a <table>:
Code: Select all
<fcs_function>
    <function>
        <table>
            <independentVar lookup="row">/velocities/airspeed-kt</independentVar>
            <independentVar lookup="column">contacts/unit[3]/compression-ft</independentVar>
            <tableData>
                        0    1    2
                0      0    0    1
                250  0    1    1
                300  1    1    1
            </tableData>
        </table>
    </function>
</fcs_function>


But now, the damage disappears again as soon as the airspeed decreases again or the wing is lifted off the ground again. That's not how it would be in reality.
So, I need some combination of the two. Is that possible, or will I have to use some Nasal code (that would be easy) ?



.
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: How to combine a JSBsim switch and table ?

Postby wkitty42 » Sat Nov 13, 2021 11:04 pm

maybe take a look at the c172p... it definitely has damage... i've bent and broken the wings more times than i care to admit... and landing gear... oof!
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9146
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: How to combine a JSBsim switch and table ?

Postby TheEagle » Sat Nov 13, 2021 11:13 pm

Nah, I've had a thorough look at the C172p already, and it uses a stepped damage system - light, heavy, broken. What I want is a smooth transition, like with an interpolation table.
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: How to combine a JSBsim switch and table ?

Postby Maerchenprinz » Sun Nov 14, 2021 5:11 am

What about putting all that it into a seperate channel and stop that channel with
Code: Select all
execute=some/value
?
The prop will be "released" and you can use nasal or whatever you like to "repair" the wing and make the channel start again.
Just a quickshot idea...

Ciao,

Adrian
User avatar
Maerchenprinz
 
Posts: 306
Joined: Thu Mar 15, 2007 6:24 pm
Location: Bochum, it's better, much better than you think!
Callsign: Adrian

Re: How to combine a JSBsim switch and table ?

Postby TheEagle » Sun Nov 14, 2021 9:17 am

No - the wing is already auto-repaired if I use a table, which is just what I don't want. To repair when the user wants it, you just need another switch with value="0".
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: How to combine a JSBsim switch and table ?

Postby Thorsten » Sun Nov 14, 2021 1:11 pm

But now, the damage disappears again as soon as the airspeed decreases again or the wing is lifted off the ground again.


:mrgreen:

Isn't that nice?

What you want to do is quite possible in JSBSim, but a bit tricky (aka you need to learn to think a certain way) - look in the JSBSim manual how a 'sample-hold' structure works, that is what you need here.

Having said that - coding an managing a damage system is a lot simpler and more efficient in Nasal, usually you do not need damage checks 120 times per second for instance.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: How to combine a JSBsim switch and table ?

Postby benih » Sun Nov 14, 2021 1:18 pm

You could also make the switch „stuck“.
For that make the first test return the current switch value if the damage applied. This will always be „true“ unless you repair (make that a part of the test condition).
I think i did it that was in the c182, however that also was a large copy/paste from the 172.
User avatar
benih
 
Posts: 1689
Joined: Tue Aug 15, 2017 10:34 am
Callsign: D-EBHX
Version: next
OS: Debian Linux 64bit

Re: How to combine a JSBsim switch and table ?

Postby S&J » Sun Nov 14, 2021 2:26 pm

I take it you're after smooth variable flight model damage ?
"Stay away from negative people.They have a problem for every solution." - Albert Einstein
S&J
 
Posts: 794
Joined: Wed Aug 26, 2020 7:31 pm

Re: How to combine a JSBsim switch and table ?

Postby TheEagle » Sun Nov 14, 2021 2:58 pm

@S&J: exactly.
@benih: no - this is what I have currently, but that puts exactly x damage exactly at x kts. Of course I could make a separate switch for every 1 or 2 or whatever kts to get finer stepping, but that would bloat up my XML file and be total nonsense.
@Thorsten: I cannot find that sample-hold in the JSBsim manual ! :( :x Can you give me a link ?
I thought it would be better to implement the damage system as a JSBsim system, because I want to reduce the lift when the wings get damaged, and by putting the damage system in Nasal, I would kind of interweave JSBsim and Nasal, which I thought would be better to avoid. You are right that the damage system doesn't need to run at 120 Hz - 20 would be more than enough, but what have we execrate for ? :wink:
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: How to combine a JSBsim switch and table ?

Postby Thorsten » Sun Nov 14, 2021 5:00 pm

I thought it would be better to implement the damage system as a JSBsim system, because I want to reduce the lift when the wings get damaged, and by putting the damage system in Nasal, I would kind of interweave JSBsim and Nasal, which I thought would be better to avoid.


Why?

JSBSim is good for some things (low-level per frame workhorse type), Nasal is good for other things (rarely used, complex planning type) - so why would you not combine the strengths of both?

The possibility to interweave Nasal and JSBSim is extremely powerful, so why would you not use this?

I fancy I know pretty much all there is to know about complex damage simulation from having implemented it - and from my perspective you're trying to cut your hand off in the hope to better do some task.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: How to combine a JSBsim switch and table ?

Postby TheEagle » Sun Nov 14, 2021 5:18 pm

Thorsten wrote in Sun Nov 14, 2021 5:00 pm:I fancy I know pretty much all there is to know about complex damage simulation from having implemented it - and from my perspective you're trying to cut your hand off in the hope to better do some task.

Well, if it's like that, I'll just do it ! :)
Which aircraft did you implement complex damage for ? I could probably learn something from that …
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: How to combine a JSBsim switch and table ?

Postby Ysop » Sun Nov 14, 2021 5:32 pm

A few thoughts:
1) Wing spar failure is depending on g-load, not velocity.

Velocity depending failure modes are
2) flutter effects (then same result as in 1)
3) disintegration of panels due to aerodynamic loads.

So there are plenty of things to model once you enter this territory.
User avatar
Ysop
 
Posts: 1348
Joined: Thu Oct 25, 2018 10:06 pm
Version: 2020.3.18
OS: ubuntu 22.04

Re: How to combine a JSBsim switch and table ?  

Postby benih » Sun Nov 14, 2021 5:34 pm

@benih: no - this is what I have currently, but that puts exactly x damage exactly at x kts. Of course I could make a separate switch for every 1 or 2 or whatever kts to get finer stepping, but that would bloat up my XML file and be total nonsense.


I tought about something like that:
- The function calculates current damage level.
- The switch is:
- "0" in case you repair
- the current calculate damage in case it is bigger than the previously strored value
- the current stored value otherwise.

This way the switch can only grow, but will reset when you set "damage/repairing" to 1

Code: Select all

<fcs_function>
    <function>
        <table>
            <independentVar lookup="row">/velocities/airspeed-kt</independentVar>
            <independentVar lookup="column">contacts/unit[3]/compression-ft</independentVar>
            <tableData>
                        0    1    2
                0      0    0    1
                250  0    1    1
                300  1    1    1
            </tableData>
        </table>
    </function>
    <output>damage/left-wing-calculated</output>
</fcs_function>

<switch name="Left wing damage">
    <output>damage/left-wing</output>
    <default value="damage/left-wing"></default> <!-- hold current damage -->
   <test logic="AND" value="0">  <!-- reset damage if repairing -->
        damage/repairing EQ 1
    </test>
    <test logic="AND" value="damage/left-wing-calculated">  <!-- apply more damage  -->
        damage/left-wing-calculated  GT  damage/left-wing
    </test>
</switch>


User avatar
benih
 
Posts: 1689
Joined: Tue Aug 15, 2017 10:34 am
Callsign: D-EBHX
Version: next
OS: Debian Linux 64bit

Re: How to combine a JSBsim switch and table ?

Postby TheEagle » Sun Nov 14, 2021 5:37 pm

Thank you benih - that was just what I needed ! :)
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: How to combine a JSBsim switch and table ?

Postby S&J » Sun Nov 14, 2021 5:56 pm

If you reversed it so that when the airfoil is 100% healthy the damage value is 1 and when ripped off 0.
You can simply multiply your lift value by it. Of course damage doesn't just effect lift it also increases surface drag
"Stay away from negative people.They have a problem for every solution." - Albert Einstein
S&J
 
Posts: 794
Joined: Wed Aug 26, 2020 7:31 pm

Next

Return to Flight dynamics model

Who is online

Users browsing this forum: No registered users and 1 guest