Jump to content

Let's talk Electricity


Recommended Posts

So, Cephei got the ball rolling by creating a module for having an ion engine powered by solar panels and a battery. It\'s a great start, but as far as I can tell, it essentially copies the fuel system, requiring energy using parts to be physically attached to each other.

I\'d like to propose a more generic system of electricity generation/storage/usage, the idea being that many different parts (sensors, ion engines, lights, etc) might wish to use electricity, and that wires on a spacecraft/station would be internal and not noticeable by the user (kind of like how RCS currently works).

My basic idea is something like this: (please excuse me and correct me if I\'m using the wrong units, it\'s been a while since I did a course on electrical stuff!)

energyprop.png

The idea of this would be that there would be one main system for electrical usage, which modders could fairly use with their own parts/plugins. So, the plugin I\'m proposing would provide the EnergyManager (perhaps it should be renamed ElectricityManager to avoid confusion) part type, and three simple interfaces for interacting with it (generating, storing and using electricity) for other plugin makers to use.

From the user\'s point of view, they would download this plugin (which would be licensed so that other modders could also include it in their downloads if they wanted), and then be able to mix and match different electrical using parts (for example, someone might make a set of ion engines, someone else might make various types of batteries, and someone different might make a radioisotope generator, and/or a set of solar panels), but have them all work nicely together (i.e., you don\'t need to use different sets of batteries to make sure your station can use parts from different peoples\' packs).

I\'m mostly interested at the moment in what other modders think. I believe NovaSilisko intends to make some of his parts run on electricity, and personally I think building rovers would be more fun if we had to make sure they had a suitable power source + battery that could survive the Munar nights and be able to power all the sensors available, so I\'m sure I\'m not the only one who would like a general way of using electricity. It would also provide a way for new modders wanting a taste of KSP modding to be able to create a part, say a solar panel, without having to make an entire pack for that part to be useful.

With that in mind, some specific questions:

[list type=decimal]

[li]Are modders interested in using this (i.e., would you implement an electrical standard in your parts if there were one available)?[/li]

[li]Is anyone already working on something similar already?[/li]

[li]Would anyone like to work on this? (Personally I\'d be very keen on coding the first version, with community input and help of course, but I don\'t want to start unless i know others would appreciate it!) [/li]

[li]Do you think my interface ideas are appropriate? If not, how would you improve them?[/li]

Link to comment
Share on other sites

How I think it would work:

A part implementing IGeneratesEnergy would, when created, search the ship for the EnergyManager, then register itself. A part implementing IStoresEnergy would do the same (there would probably need to be unRegister methods as well, for when parts are destroyed/disconnected/broken).

Everytime the EnergyManager updates, it goes through its list of IGeneratesEnergy parts, and requests the energy from the part (perhaps it should pass a timestep, and they return how much energy they generated in that time period in wattHours, or an appropriate unit). It then goes through its list of IStoresEnergy parts, and attempts to put all the energy generated this timestep in the storage devices.

Whenever an IUsesEnergy part updates (technically we don\'t actually need this interface yet, as there are no methods that are needed by the EnergyManager), it requests an amount of energy from the EnergyManager (which then searches through the IStoresEnergy list to find the energy), which returns the amount the EnergyManager was able to come up with (usually this should be the full amount requested).

Link to comment
Share on other sites

It may be interesting to model one or more busses, where every generator or consumer of energy specifies which bus it\'s connected to by name -- and some components may be able to be toggled between busses or plugged/unplugged via a 'breakerpanel' UI of some sort. By default components use the 'A' bus (to keep it simple), but that could be overridden in the part.cfg or dynamically.

Over time available generation may depend on things like:

- is the Sun obscured or not (Solar Panels)

- how old is the component (Batteries, RTGs)

Attempting to inject more than some specified limit of energy through a bus could result in a blown breaker or a Kerbaltacular electrical fire or the like...

Attempting to draw more than the available energy through a bus probably results in all components on a bus suffering.

Energy sources or containers may be able to produce only so much instantaneous energy -- solar panels maybe insufficient to power your IonEngine with a Battery to buffer things, and a single Battery may be able to provide only so much instantaneous energy, etc...

EDIT: I\'m working with a friend getting some fancy unfolding solar panels put together, but once we\'ve got that working (modeling side is looking good, need to fiddle with addon code to unfold the panels), I\'m going to be interested in actually rigging the panels up to the electrical system. Hoping to have a bunch of time to hack on stuff this weekend.

Link to comment
Share on other sites

Consider the difference between energy and power.

A solar panel will generate a different amount of power based on its distance and angle to the sun, and an ion engine will consume a certain amount of power based on its desired thrust. A battery stores some amount of energy, but it also has a maximum power output (and input). I think it\'s acceptable for an API to handle these basic conversions so that plugins don\'t have a misunderstanding when making power/energy transactions. Parts should be able to draw power from each other, but energy should be internal.

Link to comment
Share on other sites

I think you might be overcomplicating it. In my case, I just have a percentage value on the main object, then a check in each attached object to make sure that the root part in the vessel is the right module (in this case, ProbodobodyneCore). The core itself has a drain value which represents batteries (right now, it will last about two days left alone, so don\'t power up all your stuff right away without a power source!), and attached parts modify it - solar panels decrease the value (and can negate it, where it will slowly fill up to 100%), and instruments will increase it, draining the power faster.

I still need to get a vector from the sun to solar panels to change the production rate, but that will work fine with the system I have set up. It\'s simple enough that it can just be injected into any part without much fuss.

Link to comment
Share on other sites

I think you might be overcomplicating it. In my case, I just have a percentage value on the main object, then a check in each attached object to make sure that the root part in the vessel is the right module (in this case, ProbodobodyneCore). The core itself has a drain value which represents batteries (right now, it will last about two days left alone, so don\'t power up all your stuff right away without a power source!), and attached parts modify it - solar panels decrease the value (and can negate it, where it will slowly fill up to 100%), and instruments will increase it, draining the power faster.

I still need to get a vector from the sun to solar panels to change the production rate, but that will work fine with the system I have set up. It\'s simple enough that it can just be injected into any part without much fuss.

Can you add extra batteries / other energy storage systems onto a probe?

Link to comment
Share on other sites

Can you add extra batteries / other energy storage systems onto a probe?

I\'m going to work out a way to do that tomorrow.

Edit: Eventually I think I\'ll make my system more robust by removing all code specific to the parts, so the core does most of the work instead of the parts. It\'s kinda messy right now.

Link to comment
Share on other sites

Well, after people been bugging me to make my animatable solar panels produce electricity so I gave it a thought.

Cephei\'s solution is a start, but it is very unfriendly to other plugin\'s so probably not the way to go.

I think you might be overcomplicating it. In my case, I just have a percentage value on the main object, then a check in each attached object to make sure that the root part in the vessel is the right module (in this case, ProbodobodyneCore). The core itself has a drain value which represents batteries , and attached parts modify it - solar panels decrease the value (and can negate it, where it will slowly fill up to 100%), and instruments will increase it, draining the power faster.

This also sounds (I don\'t see your code, so I\'m not sure, just a guess) like a solution that will work well only within it\'s own set of parts - Relying on a core energy manager makes the system completely dependent on that part.

So I thought I\'d propose something more like the RCS system:

Part type: Battery (aka energy fuel tank) - takes care of displaying its fullness level.

Implements interface IBattery with just one method: requestPower(float amount) - can be used to drain / refill battery (if amount is negative).

Parts that produce / use energy would implement findPower(float amount) function (in their onActiveFixedUpdate or OnUpdate, depending on their type i guess).

Looking for power would happen like lookup for rcs, but would have to be coded in the findPower function start at the root of the vessel and search it\'s children for IBattery compliant parts. When a suitable part is found - try to request power from in using the requestPower method. Taking symmetrical batteries into account would be quite easy, as would be defining behavior to drain last stage batteries first, and refill those in the earliest.

Pros of such solution - any part could be easily made into battery, and it could be derived from any part class - same for energy users - any class could do it. Modifying power consumption / batter power levels would be trivial cfg edits.

In large crafts this constant lookup could be slow, so caching the results of the first search and then checking if the sources are still there could be a solution.

Anyway - I\'d be happy to give this code a shot if anyone wants it - or to help implement another solution. But I\'d like for it to be a community standard, that is easily extendable to all people\'s parts and plugins.

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