Fuel consumption control for thrusters in Space Age

This board is to show, discuss and archive useful combinator- and logic-creations.
Smart triggering, counters and sensors, useful circuitry, switching as an art :), computers.
Please provide if possible always a blueprint of your creation.
alessandrouw
Burner Inserter
Burner Inserter
Posts: 10
Joined: Fri Jun 29, 2018 2:29 pm
Contact:

Re: Fuel consumption control for thrusters in Space Age

Post by alessandrouw »

MBas wrote:
Sun Oct 27, 2024 7:43 pm

Set the constant F to 1200. This value represents the flow rate of a single pump. If you’re using a larger ship where one pump isn’t enough, you can use two pumps in parallel and change the constant F to 2400.

The constant E indicates the number of engines in one wing. In this setup, we’re using 4 engines per wing, for a total of 7 engines (one thruster is shared between both wings).

The parameter C specifies the total fuel consumption. In this example, we set C to 23, meaning each engine consumes 23 units of fluid per second.
I see that your BP works, perhaps it's too late at night and I'm tired, but do you mind explaining me the logic behind it? I just launched to space and made a few round trips, and I can't understand your logic, so I'm trying to break it down here starting from the Decider Combinator:
  • Decider combinator receives planet 'from-to' and you also set up desired consumption, pumps (1200) and number of enginers per wing. In your BP, F = 1200, E = 2 and C = 40
  • Arithmetic combinator receives DC info above, takes E and multiplies by C, outputs T (in this case, 80)
  • Decider combinator receives AC info above and compares if T < 1.5g (I assume this is a failsafe?). If true, it outputs to itself the value of T and pass it along to the next AC. T is still 80 so far, but it keeps adding itself each cycle, I guess
  • T now goes to Aritchmetic combinator 2 and calculates T % 1.2k (I also don't know what is going on here). Outputs Q.
  • Decider combinator 2 receives info from above AC and from the started DC. If all conditions are true, it outputs Checkmark = 1. I'm also not sure what it is checking for planets < 3
  • Pumps works when they receive Checkmark = 1 from above DC
Even though it works, I like to understand the logic I'm using. If you can explain that logic to me further, I'd really appreciate it. Thanks

User avatar
MBas
Long Handed Inserter
Long Handed Inserter
Posts: 94
Joined: Fri Jan 06, 2017 12:57 pm
Contact:

Re: Fuel consumption control for thrusters in Space Age

Post by MBas »

Here is my explanation:

I want to turn the pump on for only a few ticks. In a simple scenario, if I want to pump 120 units of fluid, the pump should be active for one tick out of every 10. This can be achieved using a simple clock combinator that accumulates a count of 1 per tick and resets every 10 ticks.

However, this simple approach has a significant problem: one tick out of 10 will pump 120 units of fluid, while one tick out of 9 will pump 133 units. This means it is impossible to achieve an activation between 120 and 133.

To address this rounding issue, the clock should not reset but continue accumulating. The activation time must be determined using the modulo operation on this ongoing clock value. The pump is activated based on the following conditions:

Pump is on when: 0 < SIGNAL modulo 1200 < FLOW
Pump is off when: FLOW <= SIGNAL modulo 1200 < 1200

(note: FLOW = E * C from used signals and SIGNAL is what we accumulate in clock)

With this method, the activation ratio is exactly FLOW / 1200. The signal continues to accumulate over time. The value 1.5G is just an arbitrary large number that ensures it has no significant effect on the operation.

With this algorithm, it technically does not matter by how much you increment SIGNAL each tick. However, the best outcome is achieved when SIGNAL := SIGNAL + FLOW, as this results in the shortest possible intervals between activation and deactivation.

alessandrouw
Burner Inserter
Burner Inserter
Posts: 10
Joined: Fri Jun 29, 2018 2:29 pm
Contact:

Re: Fuel consumption control for thrusters in Space Age

Post by alessandrouw »

I see, thanks for the explanation. I wonder if the clock accumulating indefinetely would cause an issue or lag in the long run, I have never setup something similar, so I was just curious. It would be awesome if we could control the pump flow using the circuits instead.

User avatar
MeduSalem
Smart Inserter
Smart Inserter
Posts: 1685
Joined: Sun Jun 08, 2014 8:13 pm
Contact:

Re: Fuel consumption control for thrusters in Space Age

Post by MeduSalem »

alessandrouw wrote:
Mon Nov 04, 2024 1:05 pm
I see, thanks for the explanation. I wonder if the clock accumulating indefinetely would cause an issue or lag in the long run, I have never setup something similar, so I was just curious. It would be awesome if we could control the pump flow using the circuits instead.
No. Accumulating forever has no significant influence on the game performance. At least not if you don't do that with like a bazillion combinators like some freaks already did in the past to stress the absolute limits of the circuit logic system. But only having a couple of those, like on a handful of platforms to control fluid flow, will not cause any performance issues you will ever notice. ^^

That said, if it would keep on accumulating forever, I guess it might eventually cause the accumulator to overflow and start from scratch again, because 32bit numbers can only store values up to 2^32 or half that if can also store negative numbers. ^^

I don't know however what would happen when it overflows, if it actually starts at 0 or at -2^31 and whether the logic above could deal with a negative number should it happen. Don't know how the factorio modulo is implemented to deal with such a situation. Some programming languages do signed modulos some don't. Could become funky then. ^^

User avatar
MBas
Long Handed Inserter
Long Handed Inserter
Posts: 94
Joined: Fri Jan 06, 2017 12:57 pm
Contact:

Re: Fuel consumption control for thrusters in Space Age

Post by MBas »

I also prefer not to rely on conventions, especially when modulo is involved. This reset does no harm to the system; it only means there will be one extra (or fewer) tick approximately once every 100 in-game hours. It's not a big deal. :)

alessandrouw
Burner Inserter
Burner Inserter
Posts: 10
Joined: Fri Jun 29, 2018 2:29 pm
Contact:

Re: Fuel consumption control for thrusters in Space Age

Post by alessandrouw »

MeduSalem wrote:
Mon Nov 04, 2024 5:24 pm
alessandrouw wrote:
Mon Nov 04, 2024 1:05 pm
I see, thanks for the explanation. I wonder if the clock accumulating indefinetely would cause an issue or lag in the long run, I have never setup something similar, so I was just curious. It would be awesome if we could control the pump flow using the circuits instead.
No. Accumulating forever has no significant influence on the game performance. At least not if you don't do that with like a bazillion combinators like some freaks already did in the past to stress the absolute limits of the circuit logic system. But only having a couple of those, like on a handful of platforms to control fluid flow, will not cause any performance issues you will ever notice. ^^

That said, if it would keep on accumulating forever, I guess it might eventually cause the accumulator to overflow and start from scratch again, because 32bit numbers can only store values up to 2^32 or half that if can also store negative numbers. ^^

I don't know however what would happen when it overflows, if it actually starts at 0 or at -2^31 and whether the logic above could deal with a negative number should it happen. Don't know how the factorio modulo is implemented to deal with such a situation. Some programming languages do signed modulos some don't. Could become funky then. ^^
I just have this approach to avoid leaks. For what's worth, I was able to make your combinator works only during flights (so it doesn't keep adding itself forever). I just connected the hub to the Decider Combinator using a green wire and added the check condition for flight, just like your final Decider Combinator. That means this combinator effectively stops when the platform is not in flight:
11-04-2024, 21-34-59.png
11-04-2024, 21-34-59.png (65.7 KiB) Viewed 1251 times
I have not added other planets to this screenshot because this ship only goes to Vulcanus, but you can add all of them if you want. I tested a bit and it looks good. A minor and might even be unnecessary improvement, but I like it :)

daahl
Manual Inserter
Manual Inserter
Posts: 1
Joined: Sat Feb 24, 2024 8:15 pm
Contact:

Re: Fuel consumption control for thrusters in Space Age

Post by daahl »

First things first: thanks for this! It would have been cooler if one could control the thruster or pumps directly, but this works pretty good and solved my fuel problem.

However, Can someone explain why the decider is testing against 1.5G? Where is that number coming from? Why not 1G or 2G?

jdrexler75
Inserter
Inserter
Posts: 25
Joined: Sat Nov 28, 2020 5:27 pm
Contact:

Re: Fuel consumption control for thrusters in Space Age

Post by jdrexler75 »

I was able to simplify this to just one decider and a Q=1 constant that can easily be combined with other constant combinators you might have. This solution albeit doesn't have the convenience of automatic throughput calculation. The value of 40 just means "pump every 40 ticks" which is good enough for the single thruster I have (therefore only needs one pump as well). Adjust as needed...

But this should help for starting platforms that you want to keep as small and simple as possible for fewer rocket launches.



Basically the green output is looped back so the decider keeps counting up until 40 while moving (i.e. when "moving to" + "moving from" signal for any planet does equal 2). The pump is set to operate when the Q value equals 1, which then happens once every 40 ticks.

I also added a condition for it to stop pumping when we run out of ammo, to stop plowing into more asteroids... in my case the signal is ammo count that is needed until safe to proceed, you'll want to adjust (or remove) this condition as needed as well.

When stopped (left screenshot behind), the second "OR" condition becomes true for all planets and so the counter never resets and the pump stays off, at least until the counter rolls over after a few years.

Connect red input to the hub and enable both "read moving from" and "read moving to" just like in the OP design.
Screenshot_20241105_184831e.png
Screenshot_20241105_184831e.png (592.85 KiB) Viewed 1132 times

Vulteran
Burner Inserter
Burner Inserter
Posts: 10
Joined: Tue Aug 23, 2022 3:50 am
Contact:

Re: Fuel consumption control for thrusters in Space Age

Post by Vulteran »

I have been thinking about this design, and the more I think about it and use it, the more the usage of number of engines and per engine flow rate seems unintuitive.

In reality, I will generally know my total fuel production rate, and want my engines to consume exactly that much fuel per second, regardless of how many engines I actually have.

As such, the variables are really just desired consumption rate, and the pumping speed of the pump. If you assume a normal pump you could just hardcode that number as well. Any design needing more than one pump would be so large you would want custom control logic anyways for everything.

Here is an example simplified version of the combinators, using one less combinator. It also allows for you to send a yellow signal from the hub to force the pumps online even if you aren't moving. This fixes the issue where you would normally need to fiddle with the wires to get fuel into the engines initially.


hazardland
Burner Inserter
Burner Inserter
Posts: 5
Joined: Mon Apr 22, 2024 10:13 am
Contact:

Re: Fuel consumption control for thrusters in Space Age

Post by hazardland »

Vulteran wrote:
Sat Nov 09, 2024 7:53 pm
I have been thinking about this design, and the more I think about it and use it, the more the usage of number of engines and per engine flow rate seems unintuitive.

In reality, I will generally know my total fuel production rate, and want my engines to consume exactly that much fuel per second, regardless of how many engines I actually have.

As such, the variables are really just desired consumption rate, and the pumping speed of the pump. If you assume a normal pump you could just hardcode that number as well. Any design needing more than one pump would be so large you would want custom control logic anyways for everything.

Here is an example simplified version of the combinators, using one less combinator. It also allows for you to send a yellow signal from the hub to force the pumps online even if you aren't moving. This fixes the issue where you would normally need to fiddle with the wires to get fuel into the engines initially.

Can you help me attaching your solution to my ship? It seems elegant but too complicated for me at this point, I think I just have add pumps (where?) and connect your controller to it?

This is my ship:


It is battle tested ship and has done around 500 round trips between inner planets without flaws, but if it carries science from Fulgora nonstop - sometimes it might require 2 minute refuel and I guess I am using excess fuel
11-13-2024, 04-39-00.png
11-13-2024, 04-39-00.png (1.29 MiB) Viewed 371 times

The_Chomper
Manual Inserter
Manual Inserter
Posts: 1
Joined: Wed Nov 13, 2024 1:13 am
Contact:

Re: Fuel consumption control for thrusters in Space Age

Post by The_Chomper »

Set the constant F to 1200. This value represents the flow rate of a single pump. If you’re using a larger ship where one pump isn’t enough, you can use two pumps in parallel and change the constant F to 2400.

The constant E indicates the number of engines in one wing. In this setup, we’re using 4 engines per wing, for a total of 7 engines (one thruster is shared between both wings).

The parameter C specifies the total fuel consumption. In this example, we set C to 23, meaning each engine consumes 23 units of fluid per second.
Two questions about how this works:
  • What's the logic behind using "wings" instead of the total number of engines? Conceptually that doesn't make any sense to me, unless there's something about engine behavior/consumption that I'm mission.
  • You have the constant combinator set to the flow rate of a single pump, but nowhere is this value used when I look at the blueprint. Should it be being used somewhere, or was the logic that needed it taken out and the constant combinator was never updated?

Xampa
Burner Inserter
Burner Inserter
Posts: 10
Joined: Sat Feb 23, 2013 3:43 pm
Contact:

Re: Fuel consumption control for thrusters in Space Age

Post by Xampa »

The_Chomper wrote:
Wed Nov 13, 2024 1:26 am
  • What's the logic behind using "wings" instead of the total number of engines?
  • You have the constant combinator set to the flow rate of a single pump, but nowhere is this value used when I look at the blueprint.
- The 'Wings' come from the way the piping is done to link all the thrusters, assuming you're using a V or inverted V shape. A pump will supply all the thrusters on a side + the middle one. The thruster on the remaining side have unlimited input from a regular pipe and are instead limited by the other fuel type.

- The 1200 value is used as the modulo value in the upper left combinator. Yes the variable in the constant combinator is unused.

Grenadith
Burner Inserter
Burner Inserter
Posts: 5
Joined: Wed Feb 07, 2018 7:57 am
Contact:

Re: Fuel consumption control for thrusters in Space Age

Post by Grenadith »

MBas wrote:
Mon Nov 04, 2024 12:51 am
Here is my explanation:

I want to turn the pump on for only a few ticks. In a simple scenario, if I want to pump 120 units of fluid, the pump should be active for one tick out of every 10. This can be achieved using a simple clock combinator that accumulates a count of 1 per tick and resets every 10 ticks.

However, this simple approach has a significant problem: one tick out of 10 will pump 120 units of fluid, while one tick out of 9 will pump 133 units. This means it is impossible to achieve an activation between 120 and 133.

To address this rounding issue, the clock should not reset but continue accumulating. The activation time must be determined using the modulo operation on this ongoing clock value. The pump is activated based on the following conditions:

Pump is on when: 0 < SIGNAL modulo 1200 < FLOW
Pump is off when: FLOW <= SIGNAL modulo 1200 < 1200

(note: FLOW = E * C from used signals and SIGNAL is what we accumulate in clock)

With this method, the activation ratio is exactly FLOW / 1200. The signal continues to accumulate over time. The value 1.5G is just an arbitrary large number that ensures it has no significant effect on the operation.

With this algorithm, it technically does not matter by how much you increment SIGNAL each tick. However, the best outcome is achieved when SIGNAL := SIGNAL + FLOW, as this results in the shortest possible intervals between activation and deactivation.
So I'm pretty sure that I reached 2.1G on my T signal (I had increased the maximum value limit to 2.1G). It went negative.
factorio_OUIJbAitF8.jpg
factorio_OUIJbAitF8.jpg (671.71 KiB) Viewed 162 times
This in turn causes the Q signal to always be less than T, thus causing the pumps to be active constantly. Did I mess something up? My ships that hit/exceeded T=2.1G are definitely not pulsing the pumps anymore.
factorio_rmhE9FrRoV.jpg
factorio_rmhE9FrRoV.jpg (788.02 KiB) Viewed 162 times
My save has 128 hours in it. Unless I'm missing something, the 2.1G limit can be reached pretty quickly, actually. For instance:

My parameters were set to C=90 and E=3. Therefore, T=270. This value is added to itself in the timer every single tick, so given 60 UPS, it would only take approximately 36 hours until it reaches T=2.1G (2,100,000,000 / 60 UPS / 60 sec per min / 60 min per hour / 270 addition rate). Am I correct? I'm not enough of a circuits guru to understand how to solve this problem though.

User avatar
MBas
Long Handed Inserter
Long Handed Inserter
Posts: 94
Joined: Fri Jan 06, 2017 12:57 pm
Contact:

Re: Fuel consumption control for thrusters in Space Age

Post by MBas »

Grenadith wrote:
Thu Nov 14, 2024 6:41 am
My save has 128 hours in it. Unless I'm missing something, the 2.1G limit can be reached pretty quickly, actually. For instance:
Yes, but the statement remains that it doesn’t matter. Even if you set it to 50k, it doesn’t matter. What it does is, when the timer resets, I pump an extra 20 fluid units into the system, or 20 less. Or maybe not even that, depending on rounding errors. This combinator logic mainly ensures that you don’t encounter this rounding error every time (which could be a problem), but only once every few hours, which is definitely not an issue

It is true that it doesn’t necessarily have to be an arbitrarily large value, but baseT * 1200 is sufficient. That value is prepared for a safe modulus of 1200 and eliminates any rounding errors accumulated by the baseT value. I am working on an update where I also want to include some remarks, and I will edit the original BP accordingly. Thanks for the tip!

Post Reply

Return to “Combinator Creations”