Board index FlightGear Support Flying

Default Cessna fuel weirdness, stuck at 9 pounds of fuel.

Controlling your aircraft, using the autopilot etc.

Re: Default Cessna fuel weirdness, stuck at 9 pounds of fuel

Postby TheEagle » Fri Oct 28, 2022 8:09 pm

I don't think the JSBSim devs can do anything about it - there must be some error in the fuel system, but I can't find either …

and btw …
Code: Select all
                <capacity unit="LBS"> 0.1 </capacity>

I don't think FG understands the unit attribute ! :wink: But ought to have nothing to do with the issue …
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: 3413
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: Default Cessna fuel weirdness, stuck at 9 pounds of fuel

Postby property_tree » Fri Oct 28, 2022 8:16 pm

The suspicion that the nasal code ultimately only drove user interface stuff dawned on me pretty early, but in my ignorance ...I didn't want to reject it too quickly.

I have not yet tested your workaround, wlbragg, but I will later.
Thanks for your time/effort, all of you, regardless. I am really liking this suite...
I'll get to grips with the codebase better eventually, too. I ain't an ace coder, but I do like poking around.
property_tree
 
Posts: 98
Joined: Wed Oct 26, 2022 1:13 pm

Re: Default Cessna fuel weirdness, stuck at 9 pounds of fuel

Postby wlbragg » Fri Oct 28, 2022 8:33 pm

I don't think the JSBSim devs can do anything about it - there must be some error in the fuel system, but I can't find either …


I'm not so sure.

propulsion/tank[0]/contents-volume-gal GT propulsion/tank[0]/unusable-volume-gal are JSBSim calculated values as far as I can tell. I don't know the relationship to JSBSim or FG direct that the consumables code is representing.

Code: Select all
    <consumables>
        <fuel>
            <tank n="0">
                <name>Left Tank</name>
                <level-gal_us type="double">0</level-gal_us>
                <selected type="bool">false</selected>
                <water-contamination type="double">0.0</water-contamination>
                <sample-water-contamination type="double">0.0</sample-water-contamination>
                <fuel-sample-taken type="bool">false</fuel-sample-taken>
                <unusable-gal_us type="double">1.49</unusable-gal_us>
            </tank>
            <tank n="1">
                <name>Right Tank</name>
                <level-gal_us type="double">0</level-gal_us>
                <selected type="bool">false</selected>
                <water-contamination type="double">0.0</water-contamination>
                <sample-water-contamination type="double">0.0</sample-water-contamination>
                <fuel-sample-taken type="bool">false</fuel-sample-taken>
                <unusable-gal_us type="double">1.49</unusable-gal_us>
            </tank>

            <tank n="2">
                <name>Integral Left Tank</name>
                <level-gal_us type="double">0</level-gal_us>
                <selected type="bool">false</selected>
                <unusable-gal_us type="double">1.49</unusable-gal_us>
            </tank>
            <tank n="3">
                <name>Integral Right Tank</name>
                <level-gal_us type="double">0</level-gal_us>
                <selected type="bool">false</selected>
                <unusable-gal_us type="double">1.49</unusable-gal_us>
            </tank>
            <tank n="4">
                <name>Float Chamber</name>
                <capacity unit="LBS"> 0.1 </capacity>
                <selected type="bool">true</selected>
                <hidden type="bool">true</hidden>
            </tank>
            <contamination_allowed type="bool">false</contamination_allowed>
        </fuel>
    </consumables>


Code: Select all
    <!-- ****************************************************** -->
    <!-- Collector Tank 4 level-maintenance                     -->
    <!-- ****************************************************** -->
    <channel name="To Tank6">
        <!-- from Tank 0 (to Collector Tank 4) -->
        <fcs_function name="propulsion/tank[0]/contents-volume-gal">
            <function>
                <quotient>
                    <p> propulsion/tank[0]/contents-lbs </p>
                    <p> propulsion/tank[0]/density-lbs_per_gal </p>
                </quotient>
            </function>
        </fcs_function>
        <switch name="fuel/from-tank0-to-tank4">
            <default value="0"/>
            <test logic="AND" value="0.1">
                propulsion/tank[0]/priority EQ 1
                propulsion/tank[0]/contents-volume-gal GT propulsion/tank[0]/unusable-volume-gal
                /consumables/fuel/tank[4]/level-lbs LT 0.05
                propulsion/tank[4]/priority EQ 1
                accelerations/Nz GE 0
                fuel/tank EQ 0
            </test>
        </switch>

        <!-- from Tank 1 (to Collector Tank 4) -->
        <fcs_function name="propulsion/tank[1]/contents-volume-gal">
            <function>
                <quotient>
                    <p> propulsion/tank[1]/contents-lbs </p>
                    <p> propulsion/tank[1]/density-lbs_per_gal </p>
                </quotient>
            </function>
        </fcs_function>
        <switch name="fuel/from-tank1-to-tank4">
            <default value="0"/>
            <test logic="AND" value="0.1">
                propulsion/tank[1]/priority EQ 1
                propulsion/tank[1]/contents-volume-gal GT propulsion/tank[1]/unusable-volume-gal
                /consumables/fuel/tank[4]/level-lbs LT 0.05
                propulsion/tank[4]/priority EQ 1
                accelerations/Nz GE 0
                fuel/tank EQ 0
            </test>
        </switch>

        <!-- from Tank 2 (to Collector Tank 4) -->
        <fcs_function name="propulsion/tank[2]/contents-volume-gal">
            <function>
                <quotient>
                    <p> propulsion/tank[2]/contents-lbs </p>
                    <p> propulsion/tank[2]/density-lbs_per_gal </p>
                </quotient>
            </function>
        </fcs_function>
        <switch name="fuel/from-tank2-to-tank4">
            <default value="0"/>
            <test logic="AND" value="0.1">
                propulsion/tank[2]/priority EQ 1
                propulsion/tank[2]/contents-volume-gal GT propulsion/tank[2]/unusable-volume-gal
                /consumables/fuel/tank[4]/level-lbs LT 0.05
                propulsion/tank[4]/priority EQ 1
                accelerations/Nz GE 0
                fuel/tank EQ 1
            </test>
        </switch>

        <!-- from Tank 3 (to Collector Tank 4) -->
        <fcs_function name="propulsion/tank[3]/contents-volume-gal">
            <function>
                <quotient>
                    <p> propulsion/tank[3]/contents-lbs </p>
                    <p> propulsion/tank[3]/density-lbs_per_gal </p>
                </quotient>
            </function>
        </fcs_function>
        <switch name="fuel/from-tank3-to-tank4">
            <default value="0"/>
            <test logic="AND" value="0.1">
                propulsion/tank[3]/priority EQ 1
                propulsion/tank[3]/contents-volume-gal GT propulsion/tank[3]/unusable-volume-gal
                /consumables/fuel/tank[4]/level-lbs LT 0.05
                propulsion/tank[4]/priority EQ 1
                accelerations/Nz GE 0
                fuel/tank EQ 1
            </test>
        </switch>

    </channel>

    <!-- Total from Tank 0 and Tank 1 to Collector Tank 4 -->
    <channel name="Total flow rate into tank 4">
        <summer name="tank0 and 1 to tank4">
            <input>fuel/from-tank0-to-tank4</input>
            <input>fuel/from-tank1-to-tank4</input>
            <input>fuel/from-tank2-to-tank4</input>
            <input>fuel/from-tank3-to-tank4</input>
            <output>propulsion/tank[4]/external-flow-rate-pps</output>
        </summer>
    </channel>


    <!-- ****************************************************** -->
    <!-- FLOW RATE from each MAIN TANK (consumption)            -->
    <!-- ****************************************************** -->

    <channel name="Total flow rates">
        <summer name="fuel/tank0-flow-rate">
            <input>-fuel/from-tank0-to-tank4</input>
            <output>propulsion/tank[0]/external-flow-rate-pps</output>
        </summer>
        <summer name="fuel/tank1-flow-rate">
            <input>-fuel/from-tank1-to-tank4</input>
            <output>propulsion/tank[1]/external-flow-rate-pps</output>
        </summer>

        <summer name="fuel/tank2-flow-rate">
            <input>-fuel/from-tank2-to-tank4</input>
            <output>propulsion/tank[2]/external-flow-rate-pps</output>
        </summer>
        <summer name="fuel/tank3-flow-rate">
            <input>-fuel/from-tank3-to-tank4</input>
            <output>propulsion/tank[3]/external-flow-rate-pps</output>
        </summer>
    </channel>


The above is the relevant pieces of code and the latter is JSBSim specific. I don't know how you would control the precision outside of JSBSim?

I am not JSBSim fluent so I may be off base here.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Default Cessna fuel weirdness, stuck at 9 pounds of fuel

Postby TheEagle » Fri Oct 28, 2022 9:49 pm

If this issue is caused by a precision error, then why does it only happen for the main tanks and not the integral ones ? Makes no sense to me.
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: 3413
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: Default Cessna fuel weirdness, stuck at 9 pounds of fuel

Postby property_tree » Fri Oct 28, 2022 10:38 pm

Perhaps there was some copy pasted code that had some tiny detail that wasn't adjusted correctly?
It seems to be a common pitfall.

It could possibly explain why one tank works and the other doesn't.
Especially if, from a data modeling standpoint, the engines don't differ much, which, again invites copy pasting.

That's just one possibility though, could be many other things I'm sure.

Edit:
This could possibly open a debugging opportunity.

By making the default tanks exactly like the integral tanks.
If it still happens then, then...it might be a more insidious issue.
property_tree
 
Posts: 98
Joined: Wed Oct 26, 2022 1:13 pm

Re: Default Cessna fuel weirdness, stuck at 9 pounds of fuel

Postby wlbragg » Fri Oct 28, 2022 10:44 pm

I totally agree, this makes no sense. But that code block is the where the comparison is made and I am pretty sure that the calculation of contents-volume-gal happens internal to JSBSim. Do a "find in files" search on it and the only reference to that property is in the code block I posted.

Also by changing only the consumables property unusable-gal_us to 1.49 which is a JSBSim internal as well fixes the entire issue.

So I think this is a JSBSim bug. There just isn't anywhere else this is being calculated and the logic presented here is correct.

If those values of 1.5 and 1.50000001 are correct, then that is really the only conclusion I can come to with the available data.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Default Cessna fuel weirdness, stuck at 9 pounds of fuel

Postby wlbragg » Fri Oct 28, 2022 10:49 pm

Then again, why does the fuel supply quit reducing?
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Default Cessna fuel weirdness, stuck at 9 pounds of fuel

Postby property_tree » Fri Oct 28, 2022 11:19 pm

I have multiplied the consumption rate by 100 at line 263 in fgpropulsion.cpp and it still didn't go below 9 pounds.
however, this really made the "hobbs system" spazz out, enabling and disabling rapidly.

Which seems to be connected with fuel shortages.
And this increased consumption more reliably dips the variables under that threshold, but something is bringing them back up.
I'm gonna try and grep for some pattern that tests for "if var is smaller than minimum, set var to minimum" ...perhaps I can pull that off and get some insight in where this kind of operation is done.

Edit:
This is quite confusing, and I'm tempted to just fabricate a crash in the hobbs system (whatever it really is) and then do a debugger backtrace... maybe that'll yield something.
Edit2: the hobbs thing hooks into the engine running test, time to do this.
property_tree
 
Posts: 98
Joined: Wed Oct 26, 2022 1:13 pm

Re: Default Cessna fuel weirdness, stuck at 9 pounds of fuel

Postby wlbragg » Fri Oct 28, 2022 11:58 pm

Admittedly I don't know much about how the fuel system is actually simulated in JSBSim. Something that is bothering me is that
fdm/jsbsim/propulsion/tank[1]/contents-volume-gal stops reducing at 1.5 gallons. Where does that jsbsim property get calculated?

Also the calculation that this code is using...
Code: Select all
            <function>
                <quotient>
                    <p> propulsion/tank[0]/contents-lbs </p>
                    <p> propulsion/tank[0]/density-lbs_per_gal </p>
                </quotient>
            </function>


Where is the density-lbs_per_gal set?

I guess contents originates from here...
Code: Select all
 <!-- Tank number 0 -->
        <tank type="FUEL">
            <location unit="IN">
                <x> 48 </x>
                <y>-44 </y>
                <z> 55 </z>
            </location>
            <capacity unit="LBS">129.43</capacity>
            <contents unit="LBS">0.0 </contents>
            <type>AVGAS</type>
        </tank>

And we set it to a value at any given time.

But from what I can tell, everything else is set internally in JSBSim. Do we get the density-lbs_per_gal value from the type of gas used, ie: AVGAS?

The draw down them must come from propulsion/tank[4]/external-flow-rate-pps?
Code: Select all
    <!-- Total from Tank 0 and Tank 1 to Collector Tank 4 -->
    <channel name="Total flow rate into tank 4">
        <summer name="tank0 and 1 to tank4">
            <input>fuel/from-tank0-to-tank4</input>
            <input>fuel/from-tank1-to-tank4</input>
            <input>fuel/from-tank2-to-tank4</input>
            <input>fuel/from-tank3-to-tank4</input>
            <output>propulsion/tank[4]/external-flow-rate-pps</output>
        </summer>
    </channel>


If so then I can see why the draw down stops because propulsion/tank[3]/contents-volume-gal GT propulsion/tank[3]/unusable-volume-gal is never false.

There are to many detail I don't know for me to be of much help here.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Default Cessna fuel weirdness, stuck at 9 pounds of fuel

Postby TheEagle » Sat Oct 29, 2022 12:25 am

Yes, density is set from the type (but can be overridden in the JSBSim tank definition with the density tag) and the level is calculated as level-lbs + (external-flow-rate-pps + engine/fuel-flow-rate-pps) * dt.
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: 3413
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: Default Cessna fuel weirdness, stuck at 9 pounds of fuel

Postby property_tree » Sat Oct 29, 2022 12:45 am

check out the changes in this commit, maybe it will help you.
git log -p 9c7243e1c432bb26fbcc0fad87c2e6ff7acff560
property_tree
 
Posts: 98
Joined: Wed Oct 26, 2022 1:13 pm

Re: Default Cessna fuel weirdness, stuck at 9 pounds of fuel

Postby property_tree » Sat Oct 29, 2022 1:10 am

I fixed it...but I am not sure if it's a nasty hack or proper.
FGTank.cpp
Line 266
Code: Select all
double FGTank::Drain(double used)
{
  double remaining = Contents - used;

  if (remaining >= 0) { // Reduce contents by amount used. //this used to check if remaining is >= GetUnusable()
    Contents -= used;
  } else { // This tank must be empty.
    if (Contents > GetUnusable())
      Contents = GetUnusable();

    remaining = Contents;
  }

  PctFull = 100.0*Contents/Capacity;
  CalculateInertias();

  return remaining;

As hinted at by the comment I added, the previous check checked if the remaining fuel is greater or equal as the unusable fuel, gotten via "GetUnusable()"
Now that it checks if there is *ANYTHING* in the tank before subtracting the fuel, it, well, substracts the fuel.
Which in itself is odd, and the reason why this might be a hack, instead of proper:
In that case the "this tank should be empty" should never be checked while above 0...but for some reason the engine now properly dies at 9 pounds.
So there must be another check elsewhere.

Strangely enough. The engine dies immediately at 9, no more 'dying breath', another indicator that it might be a hack.
But, at the very least, it's a step in the right direction..........maybe.


Edit:
As an aside, this does not trigger an 'out of fuel' nasal thingy. So, there's still some bugs there, too.

Edit2:
If I drag the slider from a 'not enough fuel' to a 'enough fuel' value, then the 'dying breath comes back'.
So...this hack might not be as hacky as I thought. Maybe.

Edit3:
While I cannot see the return value of this method being used at first glance, the "Contents" member, which is set to the remainder after the drainage, is used in some other places.

Code: Select all
FGColumnVector3 FGTank::GetXYZ(void) const
{
  return vXYZ_drain + (Contents/Capacity)*(vXYZ - vXYZ_drain);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

double FGTank::GetXYZ(int idx) const
{
  return vXYZ_drain(idx) + (Contents/Capacity)*(vXYZ(idx)-vXYZ_drain(idx));
}

Could these have some significance?

Edit4:
Huh, the code does reach the 'this tank must be empty', spot, will trace this more.
And the dying breath does occur naturally, it just went quicker in my first test cause I had the throttle on max power with the parking brake on.

This seems to be a decent fix then, maybe
Edit5 (haaha, sorry...)
Alright, I am now thinking that this 'Drain' method is part of that floatbowl, and not direclty tied to the tank contents like I assumed based on the class/source file.
The bug is kind of obvious then, maybe the author was led astray by the same thought.

The float bowl can now empty properly, and not testing it against 'unusable fuel' seems to be fine because it's not really part of the capacity thing anyway.
I couted the value and it always went to ~/0.05 or 0.5 (my terminal doesn't scroll that far up, and I am seeing the choke values now)
Even if I dragged the tank full, hence me now thinking that this is the mysterious float bowl I was told about before.

Anyway, with this fix it drains fully, but also does not go under the unused fuel value because, when the sim considers the bowl empty, it just sets it to the unusable amount, which, realistically it can't burn, so.
it all works out.

But this should be tested further. Just saying, so far so promising.
No idea why this was different with the integral fuel tanks tho.
They all work fine, however, both integral and regular.

Also, yeah I am 70% certain that the root of this problem is a shared variable, related to 'content' cause I could see that at the start of the game, this value, which during normal runtime goes from ~0.05 to 0.0, briefly gets set to the standard "32.4" pounds the cessna starts with, but then goes to the 0.05 thing.

So, this, to me, suggests some weird variable interplay that might need some proper separation somewhere.
property_tree
 
Posts: 98
Joined: Wed Oct 26, 2022 1:13 pm

Re: Default Cessna fuel weirdness, stuck at 9 pounds of fuel

Postby wkitty42 » Sat Oct 29, 2022 10:09 am

wlbragg wrote in Fri Oct 28, 2022 10:44 pm:Also by changing only the consumables property unusable-gal_us to 1.49 which is a JSBSim internal as well fixes the entire issue.

FWIW: if this were to be the fix, i might use 1.49999999 only because of the precision and 8 digits on the decimal side of the fence...

edit: i forgot to add that if it is not already done, i'd set a variable to 1.49999999 and then use a multiplier based on the tank size to get the unusable amount for each tank size... this way there is only one place to edit if the unusable amount changes for some reason and not umpteen frobzoid places to hunt this value down and replace...
"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: 9148
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Default Cessna fuel weirdness, stuck at 9 pounds of fuel

Postby property_tree » Sat Oct 29, 2022 6:04 pm

That Drain method adjustment I did in FGTank.cpp still works perfectly well for me, by the way.
At least for the Cessna, the only plane I have really tested it.
But any combination of parameters works as expected with it.

At least that's what I have been led to believe after about 8 hours of testing/flying to see if it somehow affects something else subtly, so far nothing. It just works.
(Without touching any nasal scripts, by the way, but I do believe that the 'tell the user the fuel is gone' check should still test against the 'unusable tank contents' and not just 'zero'. )
property_tree
 
Posts: 98
Joined: Wed Oct 26, 2022 1:13 pm

Re: Default Cessna fuel weirdness, stuck at 9 pounds of fuel

Postby wlbragg » Sat Oct 29, 2022 6:19 pm

but I do believe that the 'tell the user the fuel is gone' check should still test against the 'unusable tank contents' and not just 'zero'.

I can fix that in the dev repo and port the fix back to the latest release.

Did you ask for a merge request on SourceForge? Please do and I will leave the unusable-gal_us set to 1.5.

Thank you for you diagnostics and helping to get this fixed.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

PreviousNext

Return to Flying

Who is online

Users browsing this forum: No registered users and 11 guests