Minecraft – How to get this redstone blast door to do what I want

minecraft-java-editionminecraft-redstone

I'm working on expanding my Minecraft Redstone experience and contraptions. Here, I have a 2 blocks high x 3 blocks wide section of a tunnel with a track approaching it that is meant to act as a "blast door" or "flood lock". The minecart arrives at the detector rail, the three pistons in the ceiling and floor retract, and the one in the side pushes the rail out, delayed slightly. Perfect.
enter image description here
enter image description here

The problem, however, is when the cart moves through the gate and the blocks return to their original location.
The yellow block that the rail is resting on gets pushed up, taking the rail up with it (and both sides) immediately. Then, the side piston retracts, taking the yellow wool block sideways, snapping the rail into three pieces.
enter image description here

The wiring is fairly simple (which is probably my downfall).

This is the wiring for the "lower" pistions. The redstone torch (next to the detector rail) turns off, retracting the pistons.
enter image description here

The wiring for the upper section is equally simple. The redstone goes up and onto the area where the two glass sections are, hitting the repeaters and triggering the pistons.
enter image description here

Finally, the wiring for the track piston. Delayed and inverted this is most likely to be the issue.
enter image description here

What can I do (is it even possible) to get this to work?

Best Answer

I've made a video of a working example:

All you need are properly calibrated repeaters (4 ticks each), a "short-cut" for the door pistons and an inverter on one of the system parts.