Nertea

[1.9.x] Dynamic Battery Storage: electrical/thermal planning and timewarp compensation (Feb 20)

Recommended Posts

KSP 1.9.x 

Dynamic Battery Storage [2.1.5] 
Last Updated February 20, 2020

screenshot39.png

[better pictures coming soon]

Dynamic Battery Storage is a mod intended to ease vessel construction and solve problems related to power flow. It is effectively required by my mods Near Future Electrical, Cryogenic Engines and Kerbal Atomics. It used to be purely bundled as part of these mods, but the 2.0.0 update added new functionality that makes it relevant for use without these mods. Hence, a thread to centralize reporting of bugs and improvements.

The mod is divided into two main components - Vessel Systems Management and Electrical Timewarp Compensation

Vessel Systems Management

The mod provides a vessel monitoring user interface to assist in looking at your ship's electrical and thermal properties. It is difficult in KSP to look at power flows and do effective mission engineering when you start to add a large number of electricity consumers and producers to your vessel. This UI lets you see summaries of how your vessel's power sources and sinks are interacting and lets you size batteries and generators to respond to actual power loads. In a nutshell, it...

  • Shows whole-vessel power flows, separated into consumption and generation, in flight or in the VAB
  • Estimates time to drain or time to charge batteries
  • Can drill down to part categories (eg. Solar Panels, Harvesters, etc.)
  • Can drill down to turn individual parts on or off for simulation purposes
  • The VAB interface has a tool to simulate distance effects on solar panel efficiency

A similar paradigm can be applied to thermal flows - specifically, core heat, as used in resource converters, resource harvesters and radiators, plus mod parts like fission/fusion reactors. This thermal UI ...

  • Shows whole-vessel core heat flows, separated into consumption and generation, in flight or in the VAB
  • Can drill down to part categories (eg. Radiators, Harvesters, etc.)
  • Can drill down to turn individual parts on or off for simulation purposes
  • NOTE: does not handle non-core heat (eg. re-entry, engines, solar irradiance)
  • NOTE: does not make a distinction between adjacent-only radiators and full-vessel radiators, so be careful

Electrical Timewarp Compensation

This mod dynamically adjusts Electric Charge storage to combat the game's awful handling of resource generation/draw mechanics at high timewarp.

Let's consider a ship that has a generator that makes 1000 EC/s, and has batteries totalling 2000 EC of storage. A power consumer on the ship operates with a draw of 10 Ec/s. In any game physics frame at 1x time warp, the following occurs:

  1. The generator generates 1000 EC * the duration of the physics frame (0.02) * the timewarp increment (1x) and adds it to the storage, which is full, leaving a total stored energy value of 2000 EC.
  2. The power consumer uses 10 EC * the duration of the physics frame (0.02) * the timewarp increment (1x) which nets 0.2 EC and subtracts it from the storage. We now have 1999.8 EC.
  3. The cycle begins again.

When timewarp increases to a high value, the cycle stays the same, but there are consequences

  1. The generator generates 1000 EC * the duration of the physics frame (0.02) * the timewarp increment (100 000x) and adds it to the storage, which is full, leaving a total stored energy value of 2000 EC.
  2. The power consumer uses 10 EC * the duration of the physics frame (0.02) * the timewarp increment (100 000x) which nets 20,000 EC and subtracts it from the storage.
  3. There is apparently not enough power, even though the power generation rate far exceeds the consumption rate, so there will be negative consequences from the consumer thinking it is out of power

The mod functions by choosing a electricity-containing part as the 'buffer', and then expanding or contracting its storage temporarily when high timewarp factors are engaged. The size of the buffer is calculated by determining the total amount of electrical draw that all parts contribute in a single physics frame, and determining the total electrical production. If there is truly enough production to meet demand, the storage will be temporarily expanded so no timewarp related effects occur.

Supported Mods

At the moment, DBS needs to be made aware of new modules so it can get data from them. Here's a list of the following ones:

Supported Electrical Modules

  • ModuleDeployableSolarPanel (Stock)
  • ModuleGenerator (Stock)
  • ModuleResourceConverter (Stock)
  • ModuleActiveRadiator (Stock)
  • ModuleResourceHarvester (Stock)
  • ModuleCommand (Stock)
  • ModuleLight (Stock)
  • ModuleDataTransmitter (Stock)
  • ModuleEngines (Stock)
  • ModuleEnginesFX (Stock)
  • ModuleAlternator (Stock)
  • ModuleCurvedSolarPanel (Near Future Solar)
  • FissionGenerator (Near Future Electrical)
  • DischargeCapacitor (Near Future Electrical)
  • ModuleRadioisotopeGenerator (Near Future Electrical)
  • ModuleCryoTank (CryoTanks)
  • ModuleDeployableCentrifuge (Stockalike Station Parts Expansion Redux)
  • RealBattery (RealBattery)
  • KopernicusSolarPanel (Kopernicus)

Supported Thermal Modules

  • ModuleResourceConverter (Stock)
  • ModuleActiveRadiator (Stock)
  • ModuleResourceHarvester (Stock)
  • FissionFlowRadiator (Near Future Electrical)
  • FissionGenerator (Near Future Electrical)

Adding support for your mod is not difficult - contact me if you wish to do so. More support is coming soon for SSTU and hopefully some life support mods.

Bug Reporting

It is essential that I get screenshots of the craft in question, screenshots of the UI, and an output_log.txt file (not KSP.log). In addition, please go to the DynamicBatteryStorageSettings.cfg file in your GameData/DynamicBatteryStorage directory and change DebugMode to true - this will enable verbose logging of DBS and is very helpful for me. Be ready to provide reproduction steps on request. 

Frequently Asked Questions

Q: Will you support LS mods?
A: Eventually, this requires additional development. I aim to support TAC and Snacks.

Q: What mods will you NOT support?
A: Kerbalism and KSPI have their own planners and brokers and don't need this mod. 

Q: How is this different than FuseBox/AmpYear?
A: It is similar, but the UI is (in my opinion) clearer, plus has thermal functions and the ETC functionality. 
It also lacks the reserve battery feature

Q: Stock drills and converters heat values are behaving weirdly in flight, is something wrong?
A: These parts behave in very strange ways due to the way Squad has designed them. They produce additional
heat below optimum temp and less heat above it. The Editor planner uses the equilibrium values, but in flight when you 
first turn on a converter, you will see very high heat flux values until it heats up and weirdly low values if it is too hot.

As long as you follow what the Editor UI says, you will be fine for heat. 

Licensing

  • All code and cfgs are distributed under the MIT License

Download Mirrors

  Primary (GitHub)

Issue Tracking and Source


If you appreciate this project, please consider contributing to my caffeine addiction! I really appreciate it, and also helps justify this time sink to my wife :wink:, which results directly in more stuff.
btn_donate_SM.gif

Edited by Nertea

Share this post


Link to post
Share on other sites

First. Nertea with another must have :)

Edited by Svm420

Share this post


Link to post
Share on other sites
1 hour ago, Nertea said:

 

Q: How is this different than FuseBox/AmpYear?
A: It is similar, but the UI is (in my opinion) clearer, plus has thermal functions and the ETC fun

 

 

Terrific to see this out - been looking forward to it for a while!

A feature of AmpYear which I find particularly useful is the reserve EC - it's got me out of many scrapes due to miscalculating dark side warps or just having solar panels pointing in slightly the wrong direction.  Does DBS have a similar function (or part) that can replicate this feature?

Share this post


Link to post
Share on other sites
7 hours ago, Svm420 said:

First. Nertea with another must have :)

Well you probably had half of the mod already but yeah this is a must have if you deal with anything that consumes > 50 EC/s and you use at high timewarp.

6 hours ago, Friznit said:

Terrific to see this out - been looking forward to it for a while!

A feature of AmpYear which I find particularly useful is the reserve EC - it's got me out of many scrapes due to miscalculating dark side warps or just having solar panels pointing in slightly the wrong direction.  Does DBS have a similar function (or part) that can replicate this feature?

I think this function was weird in AmpYear, seemed out of place - would rather see it in a dedicated 'jump start' part perhaps that you stick on a ship and can function without ship control. 

So no it does not. 

2 hours ago, MaxPeck said:

The new system manager is the best thing ever. Awesome work!

Come for the system manager, stay for the timewarp compensation. 

28 minutes ago, BigFatStupidHead said:

This sounds really good. Will it work with non-stock time warp rates?

It should, presuming that the other mod hooks into the stock timewarp mechanisms correctly. The theory is the same at least. 

Share this post


Link to post
Share on other sites

Great, it looks like AmpYear on steroids (and without the reserve EC feature, which I always found cheaty), will definitely give it a try.

You say that it's easy to add support for DBS to a mod. I'd love to include it in Kerbal Health and Signal Delay; is there any guide for it?

Share this post


Link to post
Share on other sites

@Nertea I just updated this morning. Holy log spam. I thought this mod was bad enough before, but I think you've made it even worse. At points it's spewing messages at a rate of about 4000 messages per .15 seconds. Doing this much file I/O is a performance hit to the game. Is this really necessary? It seems to be a problem at scene changes. I didn't even bother seeing if it does anything useful.

KSP.Log

 

Spoiler

[LOG 08:42:55.364] [HighLogic]: =========================== Scene Change : From SPACECENTER to TRACKSTATION =====================
[LOG 08:42:55.838] [Dynamic Battery Storage]: [Controller] [Karfal's Craft (unloaded)]: Regenerating electrical data
[LOG 08:42:55.838] [Dynamic Battery Storage]: [Controller] [Karfal's Craft (unloaded)]: Could not find an electrical storage part
[LOG 08:42:55.838] [Dynamic Battery Storage]: [Controller] [Cargo Shuttle (unloaded)]: Regenerating electrical data
[LOG 08:42:55.838] [Dynamic Battery Storage]: [Controller] [Cargo Shuttle (unloaded)]: Could not find an electrical storage part
[LOG 08:42:55.838] [Dynamic Battery Storage]: [Controller] [Ast. TUB-267 (unloaded)]: Regenerating electrical data
[LOG 08:42:55.838] [Dynamic Battery Storage]: [Controller] [Ast. TUB-267 (unloaded)]: Could not find an electrical storage part
[LOG 08:42:55.838] [Dynamic Battery Storage]: [Controller] [Passenger Shuttle (unloaded)]: Regenerating electrical data
[LOG 08:42:55.838] [Dynamic Battery Storage]: [Controller] [Passenger Shuttle (unloaded)]: Could not find an electrical storage part
[LOG 08:42:55.838] [Dynamic Battery Storage]: [Controller] [Ast. PTD-407 (unloaded)]: Regenerating electrical data
[LOG 08:42:55.838] [Dynamic Battery Storage]: [Controller] [Ast. PTD-407 (unloaded)]: Could not find an electrical storage part
[LOG 08:42:55.838] [Dynamic Battery Storage]: [Controller] [Minmus Probes (unloaded)]: Regenerating electrical data
[LOG 08:42:55.838] [Dynamic Battery Storage]: [Controller] [Minmus Probes (unloaded)]: Could not find an electrical storage part
[LOG 08:42:55.838] [Dynamic Battery Storage]: [Controller] [Ast. CZN-286 (unloaded)]: Regenerating electrical data
[LOG 08:42:55.838] [Dynamic Battery Storage]: [Controller] [Ast. CZN-286 (unloaded)]: Could not find an electrical storage part
[LOG 08:42:55.838] [Dynamic Battery Storage]: [Controller] [Kerbol Surveyor Debris (unloaded)]: Regenerating electrical data
[LOG 08:42:55.838] [Dynamic Battery Storage]: [Controller] [Kerbol Surveyor Debris (unloaded)]: Could not find an electrical storage part
[LOG 08:42:55.838] [Dynamic Battery Storage]: [Controller] [Kerbol Surveyor (unloaded)]: Regenerating electrical data

 

 

 

Edited by Tonka Crash

Share this post


Link to post
Share on other sites
8 minutes ago, Tonka Crash said:

@Nertea I just updated this morning. Holy log spam. I thought this mod was bad enough before, but I think you've made it even worse. At points it's spewing messages at a rate of about 4000 messages per .15 seconds. Doing this much file I/O is a performance hit to the game. Is this really necessary? It seems to be a problem at scene changes. I didn't even bother seeing if it does anything useful.

KSP.Log

Translation:
I really like this mod so I took it for a spin. I noticed it was logging a lot of messages particularly at scene changes to the point where it impacted performance. Is this intended behavior or a debug option that's still set to enabled somewhere?

Share this post


Link to post
Share on other sites

Love it so far - I mean, like you said, half of it's always been here, but having the GUI and info is awesome.

Share this post


Link to post
Share on other sites

It doesn't seem to like SSTU, it says something about the LH2 Boiloff system, I think somethings conflicting. Noticed no performance impact, except when I opened the log to find a bunch of nullrefs mentioning it. I don't have a full log for you yet, but I'll post it when I do. HnCeh7F.png

Share this post


Link to post
Share on other sites
1 hour ago, Tonka Crash said:

@Nertea I just updated this morning. Holy log spam. I thought this mod was bad enough before, but I think you've made it even worse. At points it's spewing messages at a rate of about 4000 messages per .15 seconds. Doing this much file I/O is a performance hit to the game. Is this really necessary? It seems to be a problem at scene changes. I didn't even bother seeing if it does anything useful.

KSP.Log

You seem a little frustrated. Just in case you weren't aware, this is one of a large number of projects that I work on and it's easy for small issues to sneak in with new releases, particularly ones that involved a large change to the backend architecture. 

In this case there are a couple of debug messages that were not completely gated behind the debugging config setting. I didn't notice this because I run with that setting on for development, where it can be quite helpful. Happily for you, this is a simple change and I can release a fix whenever the combination of parenting, work and other personal items allow it. 

1 minute ago, The Destroyer said:

It doesn't seem to like SSTU, it says something about the LH2 Boiloff system, I think somethings conflicting. Noticed no performance impact, except when I opened the log to find a bunch of nullrefs mentioning it. I don't have a full log for you yet, but I'll post it when I do. 

Ugh I have prototypical support for SSTU but it's not very tested so I didn't want to ship it with the initial version. I must have forgotten to disable it. Correction coming when I can. 

10 hours ago, garwel said:

 You say that it's easy to add support for DBS to a mod. I'd love to include it in Kerbal Health and Signal Delay; is there any guide for it?

Effectively you just create a KSPField for your part modules that I can poll that reports accurate information about the consumption of the part in the VAB or in flight. When you've done that I can hook the resource monitor up to it.  If your mod doesn't use partmodules it's currently not possible, I am trying to dream up a generic solution to work with vessel modules and similar plugins for the future. I'm also working on a method where authors can supply config-level fields without needing to change code, so it'll get better than it is right now. Just not a high priority.

 

Share this post


Link to post
Share on other sites

Dynamic Battery Storage 2.0.1

  • Disabled SSTU and FFT support (until I get time to work on it)
  • Fixed some log messages that were not gated behind the DebugMode config setting
  • Fixed ModuleCurvedSolarPanel being in the Generators instead of the Solar Panels category
  • Consolidated Fission/Fusion reactor categories
  • Categories are now configurable (see config for details)
  • Some properties of handlers are now configurable (see config for details)
  • Added support for FissionFlowRadiator as a Heat type (NFE/Kerbal Atomics)
  • Fixed ModuleAternator not polling right in the VAB

Share this post


Link to post
Share on other sites

according to the thermal sim, FissionFlowRadiators add heat instead of remove it.

Share this post


Link to post
Share on other sites

I've added support for DBS in Kerbal Health.

  • Module: ModuleKerbalHealth
  • KSPField: ecPerSec

Signal Delay mod is also almost ready (it currently works in flight, but I'll add actual values for Editor at next release).

  • Module: ModuleSignalDelay
  • KSPField: actualECRate

Share this post


Link to post
Share on other sites
11 hours ago, garwel said:

I've added support for DBS in Kerbal Health.

  • Module: ModuleKerbalHealth
  • KSPField: ecPerSec

Signal Delay mod is also almost ready (it currently works in flight, but I'll add actual values for Editor at next release).

  • Module: ModuleSignalDelay
  • KSPField: actualECRate

Sweet! I'm almost done the configurable interface for other mods. Effectively  you will soon be able to define in config a GenericFieldDataHandler, which has a very simple ability to parse named fields without having to reach into DBS's internals and do a new release to support a new mod. 

PARTMODULEHANDLER
  {
    // The name of the module
    name = ModuleSignalDelay
    // The type of handler - can be Power or Heat
    type = Power
    // The name of the handler to use
    handlerModuleName = GenericFieldDataHandler
    // Is this shown in the UI at all?
    visible = true
    // Do we use solar distance attenuation?
    solarEfficiencyEffects = false
    // Is this module a producer by default?
    producer = false
    // Is this module a consumer by default?
    consumer = true
    // Does this item start off as active in the UI? Should canonically be true for constant sources/draws
    simulated = false
    // Does this item count as a continuous power source for the purpose of the UI?
    continuous = false
    HANDLER_CONFIG
    {
      // Field to poll in editor
      editorFieldName = actualECRate
      // Field to poll in flight
      flightFieldName = actualECRate
      // Multiply the output by these if you need to. Convention is that a consumer is negative.
      editorValueScalar = -1.0
      flightValueScalar = -1.0
    }
  }

This lets you set up pretty much all the options for polling the module and how it is displayed in the interface.

It will be targetable with MM too, so you'd be able to throw in something like 

@DYNAMICBATTERYSTORAGE
{
  @HANDLERCATEGORY[Habitation]
  {
    module = ModuleKerbalHealth
  }
}

To add module to categories.

14 hours ago, toric5 said:

according to the thermal sim, FissionFlowRadiators add heat instead of remove it.

Ugh thought I fixed this last minute but I guess I did not. 

Share this post


Link to post
Share on other sites

Hey @Nertea I think it would be nice to add support for EC consumption for ScanSat modules. 

 

*Doh should have read the post above sorry. Guess it would be supported via that system. 

Edited by Zorg

Share this post


Link to post
Share on other sites
26 minutes ago, Zorg said:

Hey @Nertea I think it would be nice to add support for EC consumption for ScanSat modules. 

 

*Doh should have read the post above sorry. Guess it would be supported via that system. 

It may need an update by @DMagic unless there is currently a KSPField I can poll to check EC usage. 

- edit: I think I could do it with what's there right now actually but it would be a custom thing, not the generic field polling. 

I also added an item to the FAQ about the weird, illogical was that stock converters and harvesters work:

Quote

Q: Stock drills and converters heat values are behaving weirdly in flight, is something wrong?
A: These parts behave in very strange ways due to the way Squad has designed them. They produce additional
heat below optimum temp and less heat above it. The Editor planner uses the equilibrium values, but in flight when you 
first turn on a converter, you will see very high heat flux values until it heats up and weirdly low values if it is too hot.

As long as you follow what the Editor UI says, you will be fine for heat. 

 

Edited by Nertea

Share this post


Link to post
Share on other sites
4 hours ago, Nertea said:

- edit: I think I could do it with what's there right now actually but it would be a custom thing, not the generic field polling.

My 2 cents; Stick with the generic solution. Less headaches in the future ;) and a large chance of snowballing into a pile of code that was exactly the thing (I assume) you wrote the generic polling for to prevent.

Share this post


Link to post
Share on other sites

Hi,

I found some NRE in DBS. The logs are here.

I had DBS debugging mode on to try and find some weirdness in the handling of electricity. I'm using TAC, and there may be some conflict between DBS and the TAC background processing of power. I had to disable the TAC background processing for now, as the two may be conflicting with each other.

Please let me know if you need anything else. Thanks

Share this post


Link to post
Share on other sites
44 minutes ago, Gilph said:

Hi,

I found some NRE in DBS. The logs are here.

I had DBS debugging mode on to try and find some weirdness in the handling of electricity. I'm using TAC, and there may be some conflict between DBS and the TAC background processing of power. I had to disable the TAC background processing for now, as the two may be conflicting with each other.

Please let me know if you need anything else. Thanks

Thanks, I'll take a look at the log. It would always be helpful to tell me what was going on at the time of the NRE though.

I'm also interested in learning what the weirdness with TAC was exactly .

Share this post


Link to post
Share on other sites
1 hour ago, Nertea said:

Thanks, I'll take a look at the log. It would always be helpful to tell me what was going on at the time of the NRE though.

I'm also interested in learning what the weirdness with TAC was exactly .

 

42 minutes ago, Tonka Crash said:

@Nertea If you want to fix NREs, here's a log. I'm seeing NRE's from this mod sometimes on scene changes or changing focus from one ship to another.

This. It seemed like it was tied to me jumping between different vessels. I'll try to get a better correlation.

With TAC background processing on, my orbital stations would seem to be running OK at 10000 warp. Then something would change and my power would jump straight to 0 after a few seconds, where i just had like 170 days of power remaining a few moments before. The bad one was that one station had an NFE reactor that was powered off. I would see the power reserve drop to a 0, NaN almost instantly on the TAC status screen. When I switched to the vessel, I see some messages, the last one being Core Overheated, and the whole vessel would disappear, killing the kerbals. Not sure how that happened with it turned off.

If it's useful, I'll try and replicate with debug on and will post is the same directory in my link above.

Thanks for your help.

Share this post


Link to post
Share on other sites
33 minutes ago, Gilph said:

The bad one was that one station had an NFE reactor that was powered off.

One of the stations I seems to trigger NREs when shift scenes does have a MX-1 GARNET reactor, but mine is running at about 28% capacity.

Share this post


Link to post
Share on other sites

I did a few more things with TAC background disabled. It looks like there are 2 NREs: one in the battery part and one in the thermal part.

The battery one seems like it happens when a ship is loading and is being modified: ([ERR 15:48:10.979] Exception handling event onVesselWasModified in class ModuleDynamicBatteryStorage:System.NullReferenceException: 

The thermal one seems to be when you switch away from the old vessel and it's being removed: [ERR 15:50:01.273] Exception handling event onVesselDestroy in class VesselDataManager:System.NullReferenceException: 

All three sets of logs are linked in my first post

Edited by Gilph

Share this post


Link to post
Share on other sites

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.