k4kfh / ZephyrCab

Drive a model train with prototypical controls, realistic behavior, and simulated physics; uses JMRI's WebSockets interface for layout connection
http://k4kfh.github.io/ZephyrCab
GNU Affero General Public License v3.0
10 stars 4 forks source link

Implementing train-wide brake line and feed valve system #7

Closed k4kfh closed 7 years ago

k4kfh commented 8 years ago

The first step in creating the brake system is to get a feed valve and brake line working. This must span the entire length of the train, and it must be kept to the proper pressure according to the valve set in the cab.

For the sake of efficient and concise code, I think it's best to only have a single global brake line pressure variable. This would be slightly unprototypical since any pressure change will propagate from the head end to the rear end of the train. However, the lack of correctly simulated pressure drop should not matter if the function to set the train brake pressure is done correctly. Using a for loop with progressively increasing setTimeout times, it should be possible to have a brake change propagate in real time.

It is worth noting that it may be necessary to decrease the physics cycle interval to 10ms. 100ms has proved acceptable for TE-only simulation thus far, but the braking may demand more responsiveness, particularly with long trains where the brakes could cause the train to jerk and lurch.

k4kfh commented 8 years ago

Henceforth, all brake-related development should take place in the brakes branch.

k4kfh commented 8 years ago

Under ideal circumstances the air signal travels at about 920 fps. Source

For realism's sake, the speed at which the brake signal travels through a car will be set individually for each railcar (in that car's JSON object). The brake system should take that number and do the math for each car to figure out how long it takes for the signal to travel to a certain point.

k4kfh commented 8 years ago

Update:

After speaking with Bruce Kingsley, I have opted to go for a simpler approach in many ways with the brakes. While I could have it calculate everything on the fly, I will probably simplify some things to make the program easier to write and less intense. For example, instead of having it calculate the timing of the brake pressure changes based on a speed in feet/sec, I'll just set a time in milliseconds for each car. As long as the creator of the car's JSON does their math right, it won't impact realism at all, but it will drastically reduce unnecessary code, variable names, and general programming clutter, plus it cuts down on unnecessary math.

I am developing a branch based on Bruce Kingsley's tips in ZephyrCab/psi-simple, and it is coming along. As of commit dfe30e7116b9eede3c735ca85ca0b95876401ba0, I have a basic timing system for pressure changes. I still have to create an alternative for this used in emergency applications, and I must add a feed valve system. It does work though, and it is coming along nicely.

k4kfh commented 8 years ago

To Do: In scripts/brakes.js, I'm not sure if I'm handling differences in pressure on the lead locomotive correctly. The code in question is inside brake.cycle on lines 85-96, shown below:

else if (carNumber == 0) {
            //special version  of this cycle for the leading element, which is always assumed to be a locomotive
            var eqReservoirPSI = train.all[0].prototype.brake.eqReservoirPSI; //find the psi of the equalizing reservoir
            var linePSI = train.all[0].prototype.brake.linePSI; //find train brake line PSI
            var waitingOnChange = train.all[0].prototype.brake.waitingOnChange; //this lets us know whether or not any differences in pressure have already been dealt with
            if ((eqReservoirPSI != linePSI) || (waitingOnChange == false)) {
                linePSI = eqReservoirPSI; //Is this realistic enough? Not sure.
            }
        }

There's no timing to set linePSI equal to eqReservoirPSI. I don't think there should be because this is only the linePSI for this element. It goes through the timing system before it applies it to the rest of the train. But I'm not sure?

k4kfh commented 8 years ago

I just committed an improvement on the feed valve system. Now, when a new car is added, the reservoir/line pressure are automatically configured to match the rest of the system. This is necessary if the user's feed valve setting is different than the one set by default in the car's JSON, so with this new functionality any difference is automagically taken care of.

k4kfh commented 7 years ago

This is essentially finished. The control system for the brake line pressure is not entirely finished, but I am closing this issue since the cars' valves respond to brake pipe pressure correctly. Some work is still needed on the conversion to actual braking force, but that's just adding in the correct leverage numbers.