Jump to content

[1.7.3] Real Battery v1.7


Blackline

Recommended Posts

Hello everyone,

i don't like squads idea of batteries. The parts in the game called "batteries" actually behave like capacitors: unlimited re-/charge rates, and low EC storage capacity.

My idea of a new mod: increase the available EC-storage per mass, and to keep the balance: a) limit the "fuel" flow rate (if that is possible) or b) convert EC to another type of "fuel" and thus enable some sort of re-/charge rate.

I present: Real Battery 

ALVapTB.png

Imgur albumhttp://imgur.com/gallery/mb01Z

With this mod you get a realistic battery behavior:

  • Charge and discharge rates are limited (dependent on battery tech ie. Lead_Acid or Li_Ion...) and is displayed in the right click menu
  • Charge rate degrades, if the battery comes close to full charge or becomes too hot/cold (see wiki for detailed behaviour); Heat behaviour is customizeable in the cfg file
  • EC range of operation is configurable in RealBattery_mm.cfg file; What this means: Discharge RealBattery until EC is at xx% level, and recharge until EC reaches yy% level. defaults are 10% and 90%.
  • Much higher EC per mass ratio than stock "batteries"
  • Stock batteries are currently cloned and enhanced with the new behavior
  • RealBattery uses Stored Charge (1SC = 3600EC)
  • Fits perfectly in the realism suite of RO, RSS or RP-0. 
  • Compatible with Ven's stock revamp mod altering battery models
  • Support for @Nertea's DynamicBatteryStorage

DOWNLOAD https://github.com/blackliner/RealBattery/releases and CKAN

SOURCE https://github.com/blackliner/RealBattery

WIKI https://github.com/blackliner/RealBattery/wiki

Required Addons:

Todo:

  • Balancing (done some with v1.1.5)
  • Single use batteries (currently lead acid) DONE with v1.1.4
  • a nice model(currently using stock battery models) 
  • charging behavior dependend on soc DONE with v1.1.0
  • different classes of battery DONE: Li ION with 1.1.2
  • 1.2 upgrade system (lead acid -> li ion -> future...)
  • stock heat system (fast initial discharge, slowdown when getting too hot/cold) DONE with v1.1.1
  • load balancing algorithm DONE with v1.1.3

 

License: MIT

Edited by Blackline
Link to comment
Share on other sites

I used @Nertea's mod in the past, and if you are reffering to the parts called "capacitors", thats not exactly what i am about. But it can of course be used as a starter for another mod, to learn stuff etc.

What i don't like with NFT-capacitors: proprietary unit and manual re/charge. And of course the naming is imho totally wrong.

Link to comment
Share on other sites

29 minutes ago, Blackline said:

I used @Nertea's mod in the past, and if you are reffering to the parts called "capacitors", thats not exactly what i am about. But it can of course be used as a starter for another mod, to learn stuff etc.

What i don't like with NFT-capacitors: proprietary unit and manual re/charge. And of course the naming is imho totally wrong.

no not the capacitors i seen you said limit the charge to slow it down and sounds like even if you had to rename stuff so was thing you could use the FissionReactor but would stay away from calling it EC think so other mod uses it but then you could limit the output

 

EDIT-  batteries are pretty much  capacitors they just take longer to charge

Edited by Mecripp2
Link to comment
Share on other sites

Batteries in KSP have functionality of capacitors. And NF capacitors work like manual discharging batteries. The fuelcell idea with a new fuel type might be a good alternative actually. hah, I'll play with it myself tonight :)

BTW: Nertea already has an optional patch for RTG decay in his NF E mod. It's in the Extras folder and you have to manually move it to your gamedata.

Link to comment
Share on other sites

What does Realism Overhaul do about batteries?  Nothing?

Some ideas: real batteries have temperature effects - for instance charging rates are often thermally limited.  So maybe if you have no radiators on the ship, you can only use trickle charge rates, with a radiator support fast charging and heat discharge.  EC levels might drop as ship temps go high or low out of the battery's ideal range.  

Thinking more about this, you might even be able to use the core heat mechanic of the ISRU to regulate this.  Charging causes heat, as heat builds up to a limit, the charge rate goes to zero.  Is there any function in the game where being too cold has effects?  How do the life support mods handle that for cabin heating?

Also, how about the new upgrade functionality?  Early career batteries are lead-acid: very heavy, bulky, charge rate limit of X.  Late career you get a lithium battery upgrade, lighter, smaller, and charge rate of Y.

Link to comment
Share on other sites

[snip]

Meanwhile, i am trying this:

PART
{
name = bettery
module = Part
author = Flo

mesh = model.mu
//MODEL
//{
//	model = Squad/Parts/Resources/FuelCell/FuelCell
//}
rescaleFactor = 1

node_attach = 0, 0, 0, 1, 0, 0, 0

TechRequired = largeElectrics
entryCost = 2250
cost = 750
category = Electrical
subcategory = 0
title = Bettery 1k
manufacturer = Elektro Me
description = A better battery.  Also handy for re-heating snacks.
attachRules = 0,1,0,0,0

// --- standard part parameters ---
mass = 0.05
dragModelType = default
maximum_drag = 0.2
minimum_drag = 0.2
angularDrag = 2
crashTolerance = 7
maxTemp = 2000 // = 3000
bulkheadProfiles = srf
tags = array bank charge convert e/c elect energ pack power volt watt

	MODULE
	{
		 name = ModuleResourceConverter
		 ConverterName = Bettery BEC 2 EC
		 StartActionName = Start BEC 2 EC
		 StopActionName = Stop BEC 2 EC
		 ToggleActionName = Toggle BEC 2 EC
		 FillAmount = 0.95
		AutoShutdown = false
		GeneratesHeat = false
		UseSpecialistBonus = false
 		 
		 
		 INPUT_RESOURCE
		 {
			ResourceName = BetterEC
			Ratio = 1
			FlowMode = NO_FLOW
		 }
		 OUTPUT_RESOURCE
		 {
			ResourceName = ElectricCharge
			Ratio = 10
			DumpExcess = false
		 }
	}
	
	MODULE
	{
		 name = ModuleResourceConverter
		 ConverterName = Bettery EC 2 BEC
		 StartActionName = Start EC 2 BEC
		 StopActionName = Stop EC 2 BEC
		 ToggleActionName = Toggle EC 2 BEC
		 FillAmount = 0.95
		AutoShutdown = false
		GeneratesHeat = false
		UseSpecialistBonus = false
 		 
		 
		 INPUT_RESOURCE
		 {
			ResourceName = ElectricCharge
			Ratio = 10
		 }
		 OUTPUT_RESOURCE
		 {
			ResourceName = BetterEC
			Ratio = 1
			DumpExcess = false
		 }
	}

	RESOURCE
	{
		name = BetterEC
		amount = 1000
		maxAmount = 1000
	}
}

 

Edited by Vanamonde
Keep it on-topic, please.
Link to comment
Share on other sites

Alright, updatet code. And a name: Bettery

What works: manual conversion from EC to BetterEC (BEC) and back. And it only fills EC up until 95% due to FillAmount

Whats missing: automatism - Only charge bettery if total EC > 95%, Only discharge bettery if total EC < 90%

 

RESOURCE_DEFINITION
{
	name = BetterEC
	abbreviation = BEC
	density = 0
	unitCost = 0
	hsp = 0
	flowMode = STAGE_PRIORITY_FLOW
	transfer = PUMP
	isTweakable = true
	volume = 1
}

PART
{
name = bettery
module = Part
author = Flo

mesh = model.mu
//MODEL
//{
//	model = Squad/Parts/Resources/FuelCell/FuelCell
//}
rescaleFactor = 1

node_attach = 0, 0, 0, 1, 0, 0, 0

TechRequired = largeElectrics
entryCost = 2250
cost = 750
category = Electrical
subcategory = 0
title = Bettery 1k
manufacturer = Elektro Me
description = A better battery.  Also handy for re-heating snacks.
attachRules = 1,0,1,1,0
node_stack_top = 0.0, 0.1108553, 0.0, 0.0, 1.0, 0.0
node_stack_bottom = 0.0, -0.1108553, 0.0, 0.0, -1.0, 0.0

// --- standard part parameters ---
mass = 0.05
dragModelType = default
maximum_drag = 0.2
minimum_drag = 0.2
angularDrag = 2
crashTolerance = 7
maxTemp = 2000 // = 3000
bulkheadProfiles = srf
tags = array bank charge convert e/c elect energ pack power volt watt



	MODULE
	{
		 name = ModuleResourceConverter
		 ConverterName = Bettery BEC 2 EC
		 StartActionName = Start BEC 2 EC
		 StopActionName = Stop BEC 2 EC
		 ToggleActionName = Toggle BEC 2 EC
		 FillAmount = 0.95
		AutoShutdown = false
		GeneratesHeat = false
		UseSpecialistBonus = false
 		 
		 
		 INPUT_RESOURCE
		 {
			ResourceName = BetterEC
			Ratio = 1
			FlowMode = NO_FLOW
		 }
		 OUTPUT_RESOURCE
		 {
			ResourceName = ElectricCharge
			Ratio = 10
			DumpExcess = false
		 }
	}
	
	MODULE
	{
		 name = ModuleResourceConverter
		 ConverterName = Bettery EC 2 BEC
		 StartActionName = Start EC 2 BEC
		 StopActionName = Stop EC 2 BEC
		 ToggleActionName = Toggle EC 2 BEC
		 FillAmount = 0.95
		AutoShutdown = false
		GeneratesHeat = false
		UseSpecialistBonus = false
 		 
		 
		 INPUT_RESOURCE
		 {
			ResourceName = ElectricCharge
			Ratio = 10
		 }
		 OUTPUT_RESOURCE
		 {
			ResourceName = BetterEC
			Ratio = 1
			DumpExcess = false
		 }
	}

	RESOURCE
	{
		name = BetterEC
		amount = 1000
		maxAmount = 1000
	}
}

 

Edited by Blackline
Link to comment
Share on other sites

6 hours ago, Vanamonde said:

Some posts have been removed from this thread. Let's please not make enemies out of each other over the functions of electronic parts and just talk in a friendly way about the game we all like. 

I wanna see how people got confrontational about a thread discussing batteries.  I don't even know.

Link to comment
Share on other sites

4 hours ago, Rath said:

I wanna see how people got confrontational about a thread discussing batteries.  I don't even know.

It was battery vs capacitor vs real world. not worth the hassle...

To the Topic:

With 1.2 the ion engine got a new feature, which stops the engines fuel consumption, if no/very little EC is left. Can I somehow use this mechanic for my part?

 

Edit found it: minResToLeave, found in ionEngine.cfg, under MODULE --> PROPELLANT: only time mentioned in the internet: 

so, @NathanKell: could INPUT_RESOURCE also profit of that mechanic?

After some thinking, maybe i need to throw in an engine, without thrust etc, and have it run on EC, with BetterEC as byproduct?

Edited by Blackline
Link to comment
Share on other sites

I agree that Squad batteries are somewhat unrealistic in several ways (though it doesn't really bother me), but they do not have the typical characteristics of a capacitor:
The characteristic behavior of a capacitor is that it reduces output voltage and output current down to zero as the capacitor discharges, usually quite quickly. It does not maintain output power at all, which makes a capacitor pretty useless as a battery (though tricks with additional electronics can make it behave more like a battery).  

A battery however both irl and in KSP, maintains output voltage and output current pretty well during discharge. Arguably KSP batteries maintain output power to well - but that only makes them less capacitor-like.
Good luck with creating this mod anyway.

 

Link to comment
Share on other sites

1 hour ago, rkman said:

I agree that Squad batteries are somewhat unrealistic in several ways (though it doesn't really bother me), but they do not have the typical characteristics of a capacitor:
The characteristic behavior of a capacitor is that it reduces output voltage and output current down to zero as the capacitor discharges, usually quite quickly. It does not maintain output power at all, which makes a capacitor pretty useless as a battery (though tricks with additional electronics can make it behave more like a battery).  

A battery however both irl and in KSP, maintains output voltage and output current pretty well during discharge. Arguably KSP batteries maintain output power to well - but that only makes them less capacitor-like.
Good luck with creating this mod anyway.

 

I am not going down that road again and get me some sour cookies. And I won't discuss electrotechnical basics. Whoever thinks he knows capacitors AND thinks, batteries in KSP are not similar to capacitors at all: http://machinedesign.com/batteriespower-supplies/what-s-difference-between-batteries-and-capacitors and some of https://www.quora.com/What-is-the-difference-between-a-capacitor-and-a-battery and maybe even some of http://physics.stackexchange.com/questions/32391/what-is-the-difference-between-a-battery-and-a-charged-capacitor

@Jimbodiahany luck last night?

  

 

Edited by Blackline
Link to comment
Share on other sites

30 minutes ago, Blackline said:

I am not going down that road again and get me some sour cookies. And I won't discuss electrotechnical basics. Whoever thinks he knows capacitors AND thinks, batteries in KSP are not similar to capacitors at all: http://machinedesign.com/batteriespower-supplies/what-s-difference-between-batteries-a

Those links do not describe KSP batteries. I also won't go down that road but you are incorrect.

High charge rates and low storage capacity are not what distinguish capacitors from batteries, it is the discharge behavior of the two that is fundamentally different.

Edited by rkman
Link to comment
Share on other sites

KSP batteries hold charge, they do not generate anything by means of a chemical process and have no limit as to how fast you can pull current out of them or for how long. Hence KSP batteries are capacitors in real life.

But no, not had luck, I need to make a plugin for what I had in mind. Using a fuel cell with a different fuel is only for the draining part, not the recharging. For that I would need to detect if there is another more powerful source on board that will charge the battery so that it does not supply current (and drain the fuel) while there are other sources like solar panels delivering all the needed current to begin with. So making a real battery analogy will be harder than just making a fuel cell copy. The only other alternative is to check the output of all solar panels or reactors, and if they are 0 the to start the fuel-cell automatically, stopping it later if one of the other sources starts up again (and has a greater Ec output than the battery itself).

Might make a really nice mod this: Real Batteries. Even add battery decay in function of time like Nertea did with his RTG plugin. Maybe we can trick @Nertea into adding something like this to his NFE pack :wink:

Link to comment
Share on other sites

One Step ahead: But it wont work, it seems OnFixedUpdate is not called... EDIT: seems a part.force_activate(); was missing, it works!!

EDIT2: final set for tonight:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using UnityEngine;

namespace KSPplugin1
{
    public class Bettery : PartModule
    {

        // Charge Rate, how much storedCharge is taken per call
        [KSPField(isPersistant = false)]
        public float ChargeRate;

        // Amount of Ec per storedCharge
        [KSPField(isPersistant = false)]
        public float ChargeRatio;

        // Only charge if total EC is higher than this, eg 0.95
        [KSPField(isPersistant = false)]
        public float HighEClevel;

        // Only discharge if total EC is lowe than this, eg 0.9
        [KSPField(isPersistant = false)]
        public float LowEClevel;

        // chargin/discharge efficiency
        [KSPField(isPersistant = false)]
        public float ChargeEfficiency;

        // Bettery Status string
        [KSPField(isPersistant = false, guiActive = true, guiName = "Status")]
        public string ChargingStatus;



        public override void OnStart(StartState state)
        {
            //Debug.Log("Bettery: OnStart");
            ChargingStatus = "Initializing";

            part.force_activate();
        }

        public override void OnUpdate()
        {
            //Debug.Log("Bettery: OnUpdate");
            //ChargingStatus = "OnUpdate";            
        }

        public override string GetInfo()
        {
            //Debug.Log("Bettery: GetInfo");
            return String.Format("Maximum Charge Rate: {0:F2}SC/s", ChargeRate) + "\n" + String.Format("Efficiency: {0:F2}%", ChargeEfficiency * 100);
        }

        public override void OnFixedUpdate()
        {
            //Debug.Log("Bettery: OnFixedUpdate");
            double EC_amount, EC_maxAmount, EC_delta, EC_delta_avail, EC_delta_missing;
            double SC_amount, SC_maxAmount, SC_SOC, SC_delta;

            //ChargingStatus = "OnFixedUpdate";

            int EC_id = PartResourceLibrary.Instance.GetDefinition("ElectricCharge").id;
            int SC_id = PartResourceLibrary.Instance.GetDefinition("StoredCharge").id;

            this.part.GetConnectedResourceTotals(EC_id, out EC_amount, out EC_maxAmount);

            if (EC_maxAmount > 0)
            {
                EC_delta_avail = EC_amount - EC_maxAmount * HighEClevel;  //amount of available EC for charging: 980 - 1000 * 0.95 = 30EC to spare
                EC_delta_missing = EC_maxAmount * LowEClevel - EC_amount;  //amount of missing EC for discharging: 1000 * 0.9 - 500 = 400EC missing
            }
            else
            {
                EC_delta_avail = 0;
                EC_delta_missing = 0;
            }

            this.part.GetConnectedResourceTotals(SC_id, out SC_amount, out SC_maxAmount);

            if (SC_maxAmount > 0)
                SC_SOC = SC_amount / SC_maxAmount;
            else
                SC_SOC = 0;

            if (EC_delta_avail > 0 && SC_SOC < 1) // Charge internal Bettery
            {   
                EC_delta = this.part.RequestResource(EC_id, Math.Min(TimeWarp.fixedDeltaTime * ChargeRate * ChargeRatio, EC_delta_avail));    // EC_delta = 0.1s * 1SC/s * 10EC/SC = 1EC

                SC_delta = this.part.RequestResource(SC_id, -EC_delta / ChargeRatio * ChargeEfficiency);            // SC_delta = -1EC / 10EC/SC * 0.9 = -0.09SC

                ChargingStatus = String.Format("Charging");
            }
            else if (EC_delta_missing > 0 && SC_SOC > 0)  // Discharge internal Bettery
            {
                SC_delta = this.part.RequestResource(SC_id, Math.Min(TimeWarp.fixedDeltaTime * ChargeRate, EC_delta_missing / ChargeRatio));                  // SC_delta = 0.1s * 1SC/s = 0.1SC

                EC_delta = this.part.RequestResource(EC_id, -SC_delta * ChargeRatio);                               // EC_delta = -0.1SC * 10EC/SC = 1EC

                ChargingStatus = String.Format("Discharging");
            }
            else
            {
                ChargingStatus = String.Format("idle");
            }
            
        }
    }
}
RESOURCE_DEFINITION
{
	name = StoredCharge
	abbreviation = SC
	density = 0
	unitCost = 0
	hsp = 0
	flowMode = NO_FLOW
	transfer = NONE
	isTweakable = true
	volume = 1
}

PART
{
name = bettery1k
module = Part
author = Flo

mesh = model.mu
//MODEL
//{
//	model = Squad/Parts/Resources/FuelCell/FuelCell
//}
rescaleFactor = 1

node_attach = 0, 0, 0, 1, 0, 0, 0

TechRequired = largeElectrics
entryCost = 2250
cost = 750
category = Electrical
subcategory = 0
title = Bettery 1k
manufacturer = Elektro Me
description = A better battery. Also handy for re-heating snacks.
attachRules = 1,0,1,1,0
node_stack_top = 0.0, 0.1108553, 0.0, 0.0, 1.0, 0.0
node_stack_bottom = 0.0, -0.1108553, 0.0, 0.0, -1.0, 0.0

// --- standard part parameters ---
mass = 0.05
dragModelType = default
maximum_drag = 0.2
minimum_drag = 0.2
angularDrag = 2
crashTolerance = 7
maxTemp = 2000 // = 3000
bulkheadProfiles = srf
tags = array bank charge convert e/c elect energ pack power volt watt



	MODULE
	{
		 name = Bettery
		 ChargeRate = 0.1
		 ChargeRatio = 10
		 ChargeEfficiency = 1
		 HighEClevel = 0.95
		 LowEClevel = 0.9
	}
	
	RESOURCE
	{
		name = StoredCharge
		amount = 1000
		maxAmount = 1000
	}
	RESOURCE
	{
		name = ElectricCharge
		amount = 10
		maxAmount = 10
	}
}

25% of the credits go to @Nertea, i stole used some code from his capacitors...

Edited by Blackline
Link to comment
Share on other sites

Interesting thread

Im looking for a similar thing but for lead acid traction blocks..sealed lead acid heavy as half of kerbin

The idea is to use them in battery locomotives for land trains.. Consumptions easy enough to dial by the numbers based on time vs use..say for a 12 hour realtime shift before charging

But a battery mod with discharge and recharge rates would be nice

Id hate for a fuel powered generator wagon to charge in seconds or for hills and overloading to.make no difference

Sadly though at 100 kilos+ for a standard battery pack I doubt theyd be spaceworthy

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...