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

Reduction always starting from feed valve pressure #15

Closed k4kfh closed 7 years ago

k4kfh commented 7 years ago

When you make a reduction after already making one, it doesn't calculate them correctly. For example, let's say:

The cylinder should have air from both those reductions in it. But instead, the brake system treats the second as though it's been charged back up to 90psi in between. So the second reduction basically has no effect..

k4kfh commented 7 years ago

Traced it down to line 540 in bundles.json. This is inside brake.reduction() code for the Generic Boxcar object. It's stopping here for some reason and not finishing the reduction.

if (resultingCylinderPSI == train.all[trainPosition].prototype.brake.cylinderPSI) {
    return undefined; //stop the function
}
k4kfh commented 7 years ago

Correction: the problem is that .reduction() doesn't take into consideration the existing brake cylinder pressure. It just assumes it to be 0. On line 537 you can see this.

resultingCylinderPSI = psi * 2.5;
k4kfh commented 7 years ago

I changed the line above to:

resultingCylinderPSI = train.all[trainPosition].prototype.brake.cylinderPSI + (psi * 2.5);

And a few tests seem to indicate that fixes the problem. I will commit the changes shortly.