Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chained Relay Power Provided Fluctuating Wildly #7864

Closed
1 task done
gerakis opened this issue Dec 19, 2021 · 8 comments
Closed
1 task done

Chained Relay Power Provided Fluctuating Wildly #7864

gerakis opened this issue Dec 19, 2021 · 8 comments
Labels
Bug Something isn't working Code Programming task

Comments

@gerakis
Copy link

gerakis commented Dec 19, 2021

  • I have searched the issue tracker to check if the issue has already been reported.

Description
If you daisy chain relays together to power any load, the relays from the second relay onward from the junction box have something wrong with their power supply. Power available seems to wildly jump up and down for no apparent reason. This is despite the fact that all relays can handle the loads provided. In fact if it cannot handle the load provided it seems to not do the fluctuations which is even more strange.

This isnt the load jumping around, this is the power. But the power supply is totally stable as measured from the first relay or the junction box. This happens with any load, but only if 2 or more relays are combined. This only started recently. This was in single player on the berilia and also in the editor.

Steps To Reproduce
Power a load with at least 3 relays that are daisy chained together. Inspect the second relay from the junction box, or any thereafter. Watch the power jump around. Ive tested it on lamps, diving suit racks, and charging docks.

Version
0.15.22.1 Windows 10 x64

Additional information
diving suit wiring

@gerakis gerakis changed the title Diving suit rack power consuption fluctuating wildly Chained Relay Power Provided Fluctuating Wildly Dec 20, 2021
@Regalis11
Copy link
Collaborator

Duplicate of #6471

@Regalis11 Regalis11 marked this as a duplicate of #6471 Dec 20, 2021
@gerakis
Copy link
Author

gerakis commented Dec 20, 2021

This is not the same bug at all. That was a load bug, this is a supply bug. This is also a new bug; this bug didn't exist before the new patch.

@Regalis11 Regalis11 reopened this Dec 29, 2021
@gerakis
Copy link
Author

gerakis commented Dec 31, 2021

I found this on #baro-sub-builder:

Relays are really fantastic for signaling, so don't discredit them, but for power transfer they are only useful in very specific scenarios.

The biggest drawback of relays is that there is a delay between calculating the load on the Power_Out grid, and requesting the power from the Power_In grid.

This can and will cause all sorts of issues if theres any "dynamic" load device, or one that fluctuates at all. What will happen is a ripple effect through your relay(s), where before the request for power can be sent to the generator, the load will have shifted, and the two numbers will never match up. This is what causes the flickering that so many people have seen in lights.
ThreadRelays1 Message ›
This thread is archived
Further, chaining relays with lights on them, as in more than one relay, would in theory be fine. But if anywhere on that grid, including at the beginning even before a relay, is a device that has a dynamic load, it will cause the lights to undervolt, then overvolt to compensate, then the ripple effect can occur and could be impossible to get rid of.

There are a couple best practices for using relays to transfer power.
First, don't mix and match devices. You can do one relay to one type of device, and be relatively fine.
Second, don't daisy chain power through relays. This is what causes the rippling effect and the flickering. There is only one bypass we've discovered, and that's to have an isolated battery before the chain of relays, the first relay being the only thing connected to the battery, and a single device type attached to those relays. For example, chaining relays and lights is feasible if ran off an isolated battery.
Third, keep them as far away from batteries and guns as possible. Guns specifically need super high voltage requirements for only half a second. Having a delay like that can keep them from firing altogether.
Reactors vs Relays
Relays will attempt to output the power regardless of what else is on the grid, due to their delay between transferring power packets.

As a result, the reactor is caught in a constant game of keep-up with the delayed output of the relay. The relay will provide power values either higher or lower than current grid load if grid load is fluctuating (depending on relay power throughput).

Due to the nature in which reactors provide power, they must first produce heat to spin up their turbine. The amount of time between the reactor adjusting and outputting power is long enough for the relay to incorrectly fulfill grid load. This usually results in the reactor attempting to provide overall less power so it does not overheat.

In grids where load fluctuates quickly, (a majority of functional submarine grids) the reactor will never be able to heat up enough to provide majority grid power. This results in effectively a "low output" mode of the reactor, as it will produce just enough power to maintain minimal fission levels, but won't ever increase to assist in grid load.

In grids where load is stable, either constant or with slow gradual transitions, the reactor and relay will oscillate between whom provides majority load. This is most likely a result of the relay's delay. The effect I've witnessed is when the relay is providing a substantial amount of power, the reactor will spin down until around minimum fission levels, where it will balance out and begin to climb. Power output from the reactor will increase and near 100% grid load. However right before providing 100% load, the relay's delay will once again cause the reactor to see a higher grid power and will attempt to provide less and less, until it gradually drops back down to minimum fission levels. Then the process repeats itself.

Stable grids with the above setups will benefit from more efficient reactor fuel rods. Higher heat output will mitigate the effects of the oscillation, but it will not resolve it completely. You will witness more majority output from the reactor, and after an oscillation less time in relay majority output as the reactor is able to recover quicker.
Batteries vs Relays
If you have a relay between the battery power_out and your grid, what's going to happen is while the relay is on, it will try to provide 100% power to match the load. It doesn't consider other generators on the grid, it will just see the load and match the power. If you've got a reactor on the same grid, it will dominate the reactors' load, potentially overvolting the system, and putting your reactor into idle. Then once your batteries are empty, it's just as bad because you'll severely undervolt while waiting for your reactor to spin back up.

If you've got a relay between the grid and the battery power_input, it's mostly fine...UNLESS your batteries loop back into the grid, which is most systems. What I mean by looping, is that the battery can output power into the same power grid that it can charge itself with. If that's your setup, and you've got a relay, the relay will actually somehow magically eat HALF the power that goes into the batteries, effectively causing your batteries to discharge twice as fast as they normally would.

Further, chaining relays with lights on them, as in more than one relay, would in theory be fine. But if anywhere on that grid, including at the beginning even before a relay, is a device that has a dynamic load, it will cause the lights to undervolt, then overvolt to compensate, then the ripple effect can occur and could be impossible to get rid of.

There are a couple best practices for using relays to transfer power.
First, don't mix and match devices. You can do one relay to one type of device, and be relatively fine.
Second, don't daisy chain power through relays. This is what causes the rippling effect and the flickering. There is only one bypass we've discovered, and that's to have an isolated battery before the chain of relays, the first relay being the only thing connected to the battery, and a single device type attached to those relays. For example, chaining relays and lights is feasible if ran off an isolated battery.
Third, keep them as far away from batteries and guns as possible. Guns specifically need super high voltage requirements for only half a second. Having a delay like that can keep them from firing altogether.

@MaaiG
Copy link

MaaiG commented Jan 3, 2022

Serial Relay Connection.
Only the first lamp glows!
Maximum power of all relay is modified!
Circuits not working!
Circuit file: 1-Serial Relay Connection.zip
Image 001_21-58

cshingle pushed a commit to cshingle/Barotrauma that referenced this issue Feb 1, 2022
@cshingle
Copy link

cshingle commented Feb 1, 2022

Since FakeFish was nice enough to share the source I spent my evening looking into this bug.
What I found is that the first relay in a chain works as expected, but following relays ramp up power very slowly. Reducing the MaxPower of the relay makes this effect even worse. Setting a very high value such as 10000 seems reduce the affect of the issue.

To debug the issue created a setup in the editor like what @MaaiG has above and set the MaxPower for the relays to 100.
I found that the throttlePowerOutput on line 165 did not make sense for a relay with MaxPower of 100.

I tracked the value back to line 116 where it appears that there is an order of operations issue.
#8149

@Regalis11
Copy link
Collaborator

Regalis11 commented Feb 2, 2022

Oh wow, I'm glad you spotted that! Thank you so much for taking the time to debug this. Merged the fix to our private repo now (Regalis11/Barotrauma-development@504e141) and moving this ticket to QA.

@Regalis11
Copy link
Collaborator

Regalis11 commented Feb 8, 2022

On a closer look, this was not an issue with the order of operations. The throttling was supposed to decrease at a speed relative to the maximum output of the relay. Now it drops immediately to zero, which essentially inverts the problem: now chained relays with a large maximum output and low load cause this kind of rapid fluctuation.

@Rokvach
Copy link
Collaborator

Rokvach commented Mar 9, 2022

Tested, working correctly. Closing.

@Rokvach Rokvach closed this as completed Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Code Programming task
Projects
None yet
Development

No branches or pull requests

5 participants