Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hello,

I'm wondering if anyone has a code sample for taking a block fuel quantity and automatically distributing the fuel through the tanks.

I understand how to use the dll to add fuel to a tank, it's just the calculating of amounts for each tank that has me a bit stuck on how to do this most efficiently.

Here's what I want to do:

Fill aux and/or tip tanks first if present

fill main left and main right next

finally fill center tanks with remaining fuel.

 

Any help would be apreciated.

 

 

Posted

Hi Jayson,

I'll add this to the PayloadServices today. It'll be a useful feature. You'll be able to set your rules for the priority of each tank.

It'll probably be later today.

Paul

Posted

Thanks Paul. I've said this before, but you are awesome!

I'm relatively new to coding, so your help has been great.

I'm sure I've mentioned this before, but the add-on we're writing is an interface that allows totally blind users to use FSX or p3d. About a year and a half ago, It started off as a way to know the nearest city to your aircraft position, but it's now snowballed into something fairly complex. It's rapidly becoming a completely accessible flight management system. 

In fact, we've been asked to present at the Toronto Accessible Gaming conference at the end of October. This is just to say that we wouldn't have come as far as we have without your amazing interface into FSUIPC. 

 

 

 

Posted

I remember you mentioning it before. I think it's a very worthwhile project so I've been more than happy to help. Congratulations for being asked to present at the conference, that's great.

You've also come up with some good ideas for the DLL which makes it better for other users too.

Version 3.1.22 is now up on NuGet with the automatic fuel loading. Full documentation and examples will be in a separate post below.

The fuel is loaded according to a flexible distribution scheme. I've set the default scheme to the one you described above (tips and aux first, then main, then centres). However, it's configurable so you can make up a different one if you need to.

It seems to work okay on the default aircraft; let me know if you run into any issues...

Paul

Posted

Version 3.1.22

PayloadServices now has methods to automatically load fuel onto the aircraft. These methods start with 'LoadFuel' and there is one for each supported unit (Lbs, Kg, Gallons etc). Fuel can be loaded by weight or volume.

You can choose to set the total fuel to the specified level, or to add the specified quantity of fuel to the fuel currently in the tanks.

The tanks will be loaded according to the Fuel Distribution Plan. 

The Distribution Plan is a list of tanks groups. Fuel is balanced within each group. If a group of tanks becomes full it moves on to next group.

A default plan is provided, but you can specify your own plan if you want. This example shows setting a new fuel distribution plan. (This is the default plan built in to the DLL).

C#

        FSUIPCConnection.PayloadServices.FuelDistributionPlan = {
              new FSFuelTanks[] { FSFuelTanks.Left_Tip, FSFuelTanks.Right_Tip, FSFuelTanks.Left_Aux, FSFuelTanks.Right_Aux },
              new FSFuelTanks[] { FSFuelTanks.Left_Main, FSFuelTanks.Right_Main },
              new FSFuelTanks[] { FSFuelTanks.Centre_Main, FSFuelTanks.Centre_2, FSFuelTanks.Centre_3 },
              new FSFuelTanks[] { FSFuelTanks.External_2, FSFuelTanks.External_1 }
        }; 

VB.NET

        FSUIPCConnection.PayloadServices.FuelDistributionPlan = {
              New FSFuelTanks() {FSFuelTanks.Left_Tip, FSFuelTanks.Right_Tip, FSFuelTanks.Left_Aux, FSFuelTanks.Right_Aux},
              New FSFuelTanks() {FSFuelTanks.Left_Main, FSFuelTanks.Right_Main},
              New FSFuelTanks() {FSFuelTanks.Centre_Main, FSFuelTanks.Centre_2, FSFuelTanks.Centre_3},
              New FSFuelTanks() {FSFuelTanks.External_2, FSFuelTanks.External_1}
        }

This plan means that fuel is first loaded into the Tip and Aux tanks equally. When they are full the remaining fuel is then loaded equally into the main tanks, and so on down the list. 

If a tank is not present on the aircraft it is ignored. You should therefore include all tanks in the distribution plan.

You can have any number of groups and any number of tanks in a group.

When adding fuel, the algorithm will attempt to correct any existing imbalance between the tank levels in a group. 

For example: a small plane has two main tanks - Left and Right. The current levels are 5 lbs and 8 lbs. If you use LoadFuelLbs() to add 7 lbs, the left tank will get 5 lbs and the right will get 2 lbs. This will leave each tank balanced at 10 lbs each.

The LoadFuel methods return the amount of fuel that could not be loaded into the tanks because they were full. 0 means all requested fuel was loaded.

Example code - Gets fuel amount from a number control on a form and uses it to set the total fuel in the aircraft.

C#

            // Loading fuel in USGallons
            PayloadServices ps = FSUIPCConnection.PayloadServices;
            double newFuelAmt = (double)this.nudFuelToLoad.Value;

            // call load fuel to set an absolute amount.
            // to add fuel change the second parameter to false
            double fuelOver = ps.LoadFuelUSGallons(newFuelAmt, true);

            // you can check if your fuel fitted in the tanks but checking how much is left over
            if (fuelOver > 0)
            {
                this.txtResult.Text = "Over capacity by " + fuelOver.ToString("F2") + "Gal";
            }
            else
            {
                this.txtResult.Text = "Filled OK";
            }

VB.NET

        ' Loading fuel in USGallons
        Dim ps As PayloadServices = FSUIPCConnection.PayloadServices
        Dim newFuelAmt As Double = Me.nudFuelToLoad.Value

        ' call load fuel to set an absolute amount.
        ' to add fuel change the second parameter to false
        Dim fuelOver As Double = ps.LoadFuelUSGallons(newFuelAmt, True)

        ' you can check if your fuel fitted in the tanks but checking how much Is left over
        If fuelOver > 0 Then
            Me.txtResult.Text = "Over capacity by " & fuelOver.ToString("F2") & " Gal"
        Else
            Me.txtResult.Text = "Filled OK"
        End If

Paul

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.