Recharging Lithium Super/Air Batteries
daliu87 opened this issue ยท 10 comments
Hey there,
I've noticing since switching to the FNBatteryGenerator part module, there doesn't seem to be any way to recharge the EC2502 or EC2503 Lithium batteries? I might be misunderstanding the purpose of kilowatt hours, but when using the older InterstellarResourceConverter, EC or megajoules from panels/reactors could be converted to kilowatt hours using the conversion slider.
Also, it looks like the IXS Command module and possibly a few parts still have the InterstellarResourceConverter for kilowatt hours. The various IFS Megajoule Super Capacitors also use InterstellarResourceConverter for EC <-> Megajoules.
Was this functionality intended?
Thanks!
They suppose to automatically charge when there is an excess amount of power and discharge when there is a shortage
KSP-Interstellar-Extended/GameData/WarpPlugin/Patches/IFS.cfg
Lines 13 to 15 in e880097
I was having this problem as well for some reason, and although this isn't really a fix for the automatic recharging issue, it does work in a way to allow the lithium batteries to recharge in some way. Just delete these two lines of code from the IFS.cfg file under both battery parts (13-15, 52-54) in order to keep the InterstellarResourceConverter slider at the least.
Since the Lithium batteries are so powerful when working with beamed power, I've been doing a lot of digging into what the problem is necessarily using just the KSPIE GameData to prevent other mod interference. With my game, the power surplus does show a value, but the actual battery doesn't recharge at all; only the radioactive decay occurs until the battery is empty.
As I said in my previous post, I was able to make it so the battery could be recharged manually by reincorporating the InterstellarResourceConverter, although it is not a perfect solution and I'd like to have the automatic recharging feature for convencience.
I've been experimenting a lot with the resource definitions in both the IFS and WarpPlugin folders, altering the IFS.cfg patch in WarpPlugin, altering the original EC2503 part config in the IFS folder, but nothing has worked. The battery discharging when there is a shortage and showing a surplus on the GUI in flight, but not actually recharging, leads me to believe that the issue is within the FNBatteryGenerator.cs plugin, most likely within the for (powerSurplus > 0) loop. The code itself makes sense and it seems like it should work, but it might be an issue with getting values from other plugin files or calling functions to edit the values. As far as I can tell, there haven't been any errors or warnings regarding FNBatteryGenerator or other plugin files under that for loop.
I personally don't have the experience working with C# to debug this issue, but I hope I've narrowed down the problem a little bit so that it'll be easier to fix. Has this issue occurred at all for you before @sswelm? It might just be my KSPIE Gamedata or my KSP files as I haven't tried to use a fresh KSP download, but just using the KSPIE mods, the problem still persists.
For what it's worth, I'm seeing this issue as well.
In the Megajoules Management Display, it is showing in the "Consumer Component" section that the Lithium Air Battery is demanding 0 W.
In the context menu for the battery, it is saying:
Spare MW Capacity: 0.000MW
Electric Power Needed: 0.0000MW
powerSurplus: 0.0030MW
Barking up the wrong tree probably, but looking at some of the code
https://github.com/sswelm/KSP-Interstellar-Extended/blob/master/FNPlugin/Powermanagement/FNBatteryGenerator.cs#L144 .. Though I don't do any C# code, I'm guessing that canRecharge is being set to true, and being set to false in various .cfg's (such as the Kerbstein)
However, https://github.com/sswelm/KSP-Interstellar-Extended/blob/master/FNPlugin/Powermanagement/FNBatteryGenerator.cs#L10 sets it to false, and I don't see from a quick look elsewhere setting it to true. (Saying again I haven't done any C# code, and I'm probably wrong)
Okay, that was the wrong tree. But this time I have a different tree to bark up.
is set by
which is
That is a fixed value, of 2.77777777777e-1
var maxPowerNeeded = currentInputConversionRate > 0 ? 0 : spareRoom / currentInputConversionRate / fixedDeltaTime;
From what I understand of C code, currentInputConversionRate will always be an array of doubles, of which 2.77777777777e-1 is the first entry.
Thus, the expression above can be simplified as
var maxPowerNeeded = 0;
Which means that:
requestedPower = Math.Min(powerSurplus * 0.995, maxPowerNeeded);
consumedPower = consumeFNResourcePerSecond(requestedPower, ResourceManager.FNRESOURCE_MEGAJOULES);
means there will always be a demand of 0 on the power source. This lines up with what I saw before with a "0 W demand" in the megajoule management screen.
So, TL;DR,
var maxPowerNeeded = currentInputConversionRate > 0 ? 0 : spareRoom / currentInputConversionRate / fixedDeltaTime;
should be something like
var maxPowerNeeded = currentInputConversionRate > 0 ? (spareRoom / currentInputConversionRate / fixedDeltaTime) : 0;
I have no development environment setup, so it may take a while. I'll try and do that over the weekend.
I may have overestimated the expected difficulties I would face in setting up the development environment, and getting it to compile. It is easier than I had expected.
Test procedure:
I copied the newly compiled DLL's over the top of the existing ones. I started up the game, and went to my structure where I saw this issue. I watched what happened with the Kilowatt hours as I fast forwarded time, and what was happening in the Megajoules management screen.
Results:
The battery would discharge until 0.00 Kilowatt hours was left over. It would then charge the battery for a tick or so. It would then start draining the battery again. The resulting charge was around 240 Kilowatt Hours out of 2531 (powerSurplus * 0.995).
Conclusions:
The Lithium Air battery now works better than before, so the above pull request works.
However, it does not feel very optimal. If we can supply power (
), then we will. The battery will only OnFixedUpdateResourceSuppliable() once before discharging again.I think the batteries should provide power if there is a deficit, otherwise charge if there is surplus power. I will try and understand how to implement that, and how KSP handles resources.