The only problem with comparing the hyd length to a value is the imperfect constraint system. Stuff sags even when welded sometimes.
I've tried doors like this in the past and while they will indeed latch, as soon as someone manages to move the door even a little, the output length on the hyd changes and the weld disengages. The same applies for driving or flying contraptions. Constraints can sag when things are moved around and that sagging is shown in the hyd output length and will cause problems with latch-circuits.
A more reliable way to do it is by time. Measure how long it takes for the door to come to a full close and have the latch engage from then on, regardless of the hydraulics output length.
Here's the (very simple) expression I use for weld-latch doors. It has a built-in delay of one second:
Code:
N@DoorController
I@A B C
O@Hyd Lock Timer
interval(1000)
Hyd = ( A | B | C ? 120 : 2)
Lock = ((Hyd <= 10) & (Timer >= 1) ? 1 : 0)
Timer = ( A | B | C ? 0 : Timer += 1)
A non-zero value wired to any of the inputs will set the hyd length to 120. When the inputs are all zero, the length will drop back to 1. These are "while" inputs for things like keypads which can output a 1 for the amount of time selected or target finders which will output a 1 while you're in range (color filter on the TF and color yourself so it doesn't activate for anyone else). You can modify the open and closed lengths there in the first line of code for use with all sorts of doors.
If you like, I could probably make one that's a little more button-friendly. I.e. lets you push the button and the door remains open for a set time. Let me know if you want it!
Bookmarks