Jump to content

[DEV THREAD] On Demand Fuel Cells Refueled


zer0Kerbal

Recommended Posts

released under terms of the original license ( CC-BY-NC-SA-4.0).

On Demand Fuel Cells Refueled

This is the development thread.

For the release thread on ODFC go here.

 

On Demand Fuel Cells (ODFC) is a plugin to simulate fuel cells in Kerbal Space Program (KSP), and do a better job of it than stock's use of a resource converter.  The main difference is it only generates electricity when it's really needed (batteries almost empty), and otherwise lets electricity of a craft float up and down, as it might in a solar powered vehicle when the sun is eclipsed by another celestial body.  It also allows fuel cells to generate byproducts, aimed at supporting life support mods like TACLS.

Features:

  • adjustable fuel cell use - much more than just On/Off operation
  • multiple fuel modes (serial usage - one mode at a time)
  • variable activation threshold
  • configurable to produce byproducts (so O+H2 = EC + H2O)
  • very small memory footprint
  • Brown and Black out protection assistance
  • PAW (Part Action Window / Right Click Menu) grouping with autocollapse, click the down arrow to drop the ODFC control panel down (KSP 1.7.1).
  • more features coming soon (hopefully)

Known Issues:

ODFC-Spacedock-header.png

 

CC 4.0 BY-NC-SA

CC 4.0 BY-NC-SA

Source Code: Github repo.

Link to comment
Share on other sites

As it stands there are

 

three pressing code related issues (in order of being tackled):

  1. Tweakscale Support @Lisias
  2. B9 support @blowfish
  3. Background Processing/Resources Support @zer0Kerbal

code upgrades:

  1. additional config nodes

integration issues:

  1. smx patch
  2. SETI-ProbeParts

parts:

  1. Hot Beverages
  2. KGEx
  3.  
Edited by zer0Kerbal
Link to comment
Share on other sites

@Lisias having some difficulty with tweakscale on ODFC parts. finally just crowbarred the patch directly into the part and it works; however doesn't scale the maxEC.

 

here is the part (example):

Spoiler

// ***************** 1.25 m *****************
PART
{
    // Hot Beverage Inc. - Fuel Cell Module
    // INFINITE ENERGY! ... not.
    //

    // --- general parameters ---
    name = HB_Fuel_Cell_125
    module = Part
    author = ph34rb0t

    // --- asset parameters ---
    mesh = model.mu

    scale= 1.0
    rescaleFactor = 1.25

    // --- node definitions ---
    node_stack_top = 0.0, 0.083, 0.0, 0.0, 1.0, 0.0,1
    node_stack_bottom = 0.0, -0.083, 0.0, 0.0, -1.0, 0.0,1

    // --- editor parameters ---
    TechRequired = Electrics
    entryCost = 2250
    cost = 895
    category = Electrical
    subcategory = 0
    title = 1.25m Fuel Cell Module
    manufacturer = Hot Beverage Inc.
    description = The aesthetically easily offended Hot Beverage guild brings you this fuel cell module so you won't need these dreadful solar panels for shorter missions. Next to much needed electricity, these fuel cells also produce heat and water for tasty coffee or tea!

    tags = #autoLOC_500648
    // attachment rules: stack, srfAttach, allowStack, allowSrfAttach, allowCollision
    attachRules = 1,0,1,1,0

    // --- standard part parameters ---
    mass = 0.1
    dragModelType = default
    maximum_drag = 0.2
    minimum_drag = 0.2
    angularDrag = 1
    crashTolerance = 7
    maxTemp = 2000
    bulkheadProfiles = size1,srf

    MODULE
    {
        name = ModuleResourceConverter
        ConverterName = #autoLOC_502022 //#autoLOC_502022 = Fuel Cell
        StartActionName = #autoLOC_502023 //#autoLOC_502023 = Start Fuel Cell
        StopActionName = #autoLOC_502024 //#autoLOC_502024 = Stop Fuel Cell
        ToggleActionName = #autoLOC_502025 //#autoLOC_502025 = Toggle Fuel Cell
        FillAmount = 0.95
        AutoShutdown = false
        GeneratesHeat = true
        UseSpecialistBonus = true

        INPUT_RESOURCE
        {
            ResourceName = MonoPropellant
            Ratio = 0.0015
            FlowMode = STAGE_PRIORITY_FLOW
        }
        INPUT_RESOURCE
        {
            ResourceName = LiquidFuel
            Ratio = 0.0016875
            FlowMode = STAGE_PRIORITY_FLOW
        }
        INPUT_RESOURCE
        {
            ResourceName = Oxidizer
            Ratio = 0.0020625
            FlowMode = STAGE_PRIORITY_FLOW
        }
        OUTPUT_RESOURCE
        {
            ResourceName = ElectricCharge
            Ratio = 1.5
            DumpExcess = false
        }
    }

    MODULE
    {
        name = TweakScale
        type = ODFCStack
        defaultScale = 1.25
        freeScale = True
    }

    RESOURCE
    {
        name = ElectricCharge
        amount = 100
        maxAmount = 100
    }

    RESOURCE
    {
        name = MonoPropellant
        amount = 30
        maxAmount = 30
    }
}

here are the patches:

 

Spoiler

@Part[HB_Fuel_Cell_03125]:FOR[HotBeverages]
{
    %MODULE[TweakScale]:NEEDS[TweakScale]
    {
        %type = stack
        %defaultScale = 0.3125
        %freeScale = True
    }
}

Spoiler

+PART[HB_Fuel_Cell_03125]:NEEDS[ODFC,HotBeveragesIrradiated]:FOR[HotBeveragesIrradiated]
{
    @name ^= :^:ODFC:
    // @cost += 50
    @title ^= :$: <#569117> ODFC</color>:
    @description ^= :$: <#569117><i>ODFC installed.</i></color> :
    // @mass += 0.010
    @tags ^= :$:  odfc demand:

    !MODULE[ModuleResourceConverter] {}

    MODULE
    {
        name = ODFC
        MODE
        {
            MaxEC = 0.75
            FUELS
            {
                MonoPropellant = 0.00045
            }
        }
        MODE
        {
            MaxEC = 0.75
            FUELS
            {
                LiquidFuel = 0.00050625000000
                Oxidizer = 0.00061875000000
            }
        }
        MODE
        {
            MaxEC = 0.75
            FUELS
            {
                LiquidFuel = 0.00003825
                IntakeAir = 0.00057375
            }
        }
        MODE:NEEDS[CommunityResourcePack]
        {
            MaxEC = 0.75
            FUELS
            {
                Hydrogen = 0.007677684
                Oxygen = 0.003863235
            }
            BYPRODUCTS
            {
                Water = 0.00000621063244940
            }
        }
    }
}

Spoiler

//              ****************************
//              ** ODFC MODULES EXTENDED **
//              ****************************

TWEAKSCALEBEHAVIOR//:NEEDS[!ODFC]
{
    name = ODFC
    MODULE
    {
        name = ODFC
        TWEAKSCALEEXPONENTS
        {
            maxEC = 3
            {
                rate = 3
            FUELS
            {
                rate = 3
            }
            BYPRODUCTS
            {
                rate = 3
            }
        }
    }
}

SCALETYPE//:NEEDS[!ODFC]
{
    name = ODFCStack
    freeScale = true
    scaleFactors   = 0.078125, 0.15625, 0.3125, 0.625, 1.25, 1.875, 2.5, 3.75, 5.0, 6.25, 7.5, 10, 15, 20
    scaleNames    = .0781m, .156m, .312m, 0.625m, 1.25m, 1.875m, 2.5m, 3.75m, 5m, 6.25m, 7.5m, 10m, 15m, 20m
    defaultScale = 1.0
}

 

 

Edited by zer0Kerbal
Link to comment
Share on other sites

All the functions of ODFC work with Kerbalism.  However, the menu item for the fuel cells doesn't change status to "on".  Also, not sure if this is intended behavior but the fuel cells appear to only be producing as much electric charge as is being consumed and nothing more.  In the pic I set the odfc cells to turn on at 50% charge.

Kerbalism + ODFC

Link to comment
Share on other sites

20 minutes ago, Xt007 said:

All the functions of ODFC work with Kerbalism.  However, the menu item for the fuel cells doesn't change status to "on".  Also, not sure if this is intended behavior but the fuel cells appear to only be producing as much electric charge as is being consumed and nothing more.  In the pic I set the odfc cells to turn on at 50% charge.

Kerbalism + ODFC

thank you.

Glad to hear that.

so two issues:

Kerbalism isn't recognizing ODFC. Those labels on the PAW are Kerbalism showing it is expecting the 'old' resource converter. Since ODFC is so new (or rather so old and new) this is to be expected. Don't think there is much I can do about this issue, albeit is now included in the github issue tracker. @N70 (and now I believe @Sir Mortimer) are the ones. tagging them to see if they can fix it.

the fuel cells continue to operate and instead of maxEC output, they just 'trickle' charge to cover the vessels EC demands. Can't see the whole ODFC panel (drop down to show) however this looks like it is working as intended. If the threshold has been met (ie the threshold is say 50%, and the vessel has 100 EC (somebody forgot more batteries) that would be 50EC, and something (like Val's kPad) is draining 0.32 EC/s then ODFC will make up the difference - or call it the trickle charge.) Does this make sense? the drain drops the vessels' total EC available under the threshold by the total amount drained, so ODFC senses that and makes up for it. It is one of the quiet features of ODFC I really like. (PS if you don't like the color coding in the PAW status - it can be turned off in the game settings menu). When EC is at threshold, ODFC tries to keep it at threshold, only covering the demand *up to the max ability of available fuel cells). It also only uses enough fuel to do so - scaling the consumption to the production.

Love the screen shots! Here's a coupon for two free cups of Jeb's Coffee!

Edited by zer0Kerbal
Link to comment
Share on other sites

11 minutes ago, Xt007 said:

Thank you for the explanation, makes sense! In hind sight the trickle charge is better because then you're using the absolute minimum fuel cell fuel and with Kerbalism in a non sandbox game every resource counts!

I have submitted an issue to the Kerbalism github repo and linked it to the ODFC github issue - it 'should' be a minor fix, either to ODFC or Kerbalism.

Link to comment
Share on other sites

3 hours ago, zer0Kerbal said:

it 'should' be a minor fix

Famous last words...

You need to think about:

  • Running at such high time warp speeds that you get ONE function callback for HOURS of simulator time. This effectively means that you can't check for resource levels to decide if you're turning on or off.
  • Not running at all (unloaded vessels) but still work
  • Integration into Kerbalism's automation

Kebalism pretty much has the functionality built-in already. Sorry, but the chances of specific support for ODFC are rather slim. There might be an option to integrate it in the future, further details here.

Link to comment
Share on other sites

On 9/12/2019 at 9:49 PM, zer0Kerbal said:

@Lisias having some difficulty with tweakscale on ODFC parts. finally just crowbarred the patch directly into the part and it works; however doesn't scale the maxEC.

There's an error on the tweakscale behaviour. :)

TWEAKSCALEBEHAVIOR//:NEEDS[!ODFC]
{
    name = ODFC
    MODULE
    {
        name = ODFC
        TWEAKSCALEEXPONENTS
        {
            maxEC = 3
            XXXX // <--- Something is missing here.
            {
                rate = 3
            } // <--- You Missed this brace!
            FUELS
            {
                rate = 3
            }
            BYPRODUCTS
            {
                rate = 3
            }
        }
    }
}

If this is not enough, you will need to explain to me what's maxEC and where in the code (and part) if goes, so I can double check things with you.

Link to comment
Share on other sites

2 hours ago, Lisias said:

There's an error on the tweakscale behaviour. :)

If this is not enough, you will need to explain to me what's maxEC and where in the code (and part) if goes, so I can double check things with you.

thank you - am still thinking it is my slipshod patch writing :eek:

maxEC is the maximum amount of electricalCharge the fuel cell will produce for a given mode.

I tried two different versions of this - yes something might have been missing ; the MODE node name:

 

Spoiler

TWEAKSCALEBEHAVIOR//:NEEDS[!ODFC]
{
    name = ODFC1
    MODULE
    {
        name = ODFC
        TWEAKSCALEEXPONENTS
        {
            maxEC = 3
            FUELS
            {
                rate = 3
            }
            BYPRODUCTS
            {
                rate = 3
            }
        }
    }
}

TWEAKSCALEBEHAVIOR
{
    name = ODFC2
    MODULE
    {
        name = ODFC
        TWEAKSCALEEXPONENTS
        {
            MODE
            {
                maxEC = 3
                FUELS
                {
                    rate = 3
                }
                BYPRODUCTS
                {
                    rate = 3
                }
            }
        }
    }
}

but reread the instructions (here) again - and this makes the most sense:

Spoiler

TWEAKSCALEBEHAVIOR
{
    name = ODFC
    MODE    // fuel mode - may have several
    {
        maxEC = 2    // max electricalCharge this mode will generate
        FUELS        // list of fuels in /MonoPropellant = 0.255/ (name = consumption)
        {
            rate = 2
        }
        BYPRODUCTS // same as fuels, except byproducts like water
        {
            rate = 2
        }
    }
}

one final note - ODFC doesn't do much in onLoad - rather it does most if not all of its work in onStart.

Link to comment
Share on other sites

6 hours ago, Xt007 said:

Any plans to accommodate Real Fuels?  Real Fuels likes to convert all monopropellant to hydrazine.  Would it be possible to have ODFC use hydrazine + oxidizer or oxygen?  

No plans - well, that isn't strictly true. If someone is willing to supply the specifications, I can / will assist in writing the patches to integrate ODFC into pretty much anything it will fit into.

So if you want Realfuels, just supply the specifications to me:

  • input fuels, where these are defined, and consumption rates
  • output (byproducts) -
  • Maximum Electrical charge per consumption.

EXAMPLE:

Quote

        MODE:NEEDS[CommunityResourcePack] ****
        {
 *           MaxEC = 5
            FUELS
            {
   **             Hydrogen = 1.04264849617275
   **           Oxygen = 0.788621982550263
            }
            BYPRODUCTS
            {
   ***             Water = 0.000843419221524059
            }
        }

  1. * Maximum Electric Charge produced based upon consuming/producing resources
  2. ** fuel resource(s) and corresponding consumption rates per MaxEC
  3. *** byproduct resource(s) and corresponding consumption rates per MaxEC
  4. **** where these resources are defined (unless stock)

 

SO if you want a new mode for ODFC fuel cells that uses hydrazine + oxygen = ?? + EC - just need to supply me with the parts of the equation.

the code behind ODFC is very simple. It takes up to three resources as inputs (I believe 3 is the max, haven't tried more complex), and it outputs EC plus from 0 to 3 byproducts (resources). Just need to know how much of what for a given amount of ec.

 

on another side note: ODFC seems to be able to have as many MODES as one wishes, just can only use one at a time; so adding RealFuels MODES should be straighforward, as long as have the formulas.

Link to comment
Share on other sites

14 hours ago, Xt007 said:

My best napkin math shows for hydrazine fuel cell keeping inline with stock would be

.0782 hydrazine + .0591 Oxygen = 5 EC + .0000633 water

thank you.

initial trial:

doesn't need RealFuels, just CommunityResourcePack for the stock Fuel Cell - if this works for you, then I will expand and add to all patches.

Spoiler

@PART[FuelCell]:NEEDS[ODFC]:AFTER[ODFC]
{
    // @name ^= :^:ODFC:
    @cost += 50
    @title ^= :$: <#6495ED> ODFC</color>:
    @description ^= :$:<#6495ED><i>ODFC installed. </i></color>:
    @mass += 0.001
    @tags ^= :$:  odfc demand:

    !MODULE[ModuleResourceConverter] {}
    MODULE,0
    {
        name = ODFC
        MODE
        {
            MaxEC = 5
            FUELS
            {
                MonoPropellant = 0.005
            }
        }
        MODE
        {
            MaxEC = 5
            FUELS
            {
                LiquidFuel = 0.005625
                Oxidizer = 0.0152777777777778
            }
        }
        MODE:NEEDS[CommunityResourcePack]
        {
            MaxEC = 5
            FUELS
            {
                Hydrogen = 1.04264849617275
                Oxygen = 0.788621982550263
            }
            BYPRODUCTS
            {
                Water = 0.000843419221524059
            }
        }
        MODE
        {
            MaxEC = 5
            FUELS
            {
                LiquidFuel = 0.000425
                IntakeAir = 0.102
            }
        }
        MODE:NEEDS[CommunityResourcePack]
        {
            MaxEC = 5
            FUELS
            {
                Hydrazine = .0782
                Oxygen = .0591
            }
            BYPRODUCTS
            {
                Water = .0000633
            }
        }
    }
}

just tested - shows up in game just fine, I don't have any tanks that hold hydrazine, but as long as it shows up it has a 99.9% of working as intended.

Edited by zer0Kerbal
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...