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

Rolling stock brakes not playing nice with forced zero crossing? #26

Closed k4kfh closed 7 years ago

k4kfh commented 7 years ago

For some reason the rolling stock brake system circumvents the forced-zero-crossing feature. The zero crossing code recognizes that it's crossing zero, but the brakes don't seem to notice and continue to apply negative force just long enough to make the speed negative, and then they notice and switch to positive force. This repeats over and over again, effectively nullifying the zero crossing feature as the entire train bounces back and forth between a very low forward speed and a very low reverse speed.

k4kfh commented 7 years ago

It seems to not be limited to just brakes, but also include rolling resistance.

k4kfh commented 7 years ago

It had nothing to do with the rolling stock specifically! It had everything to do with a mistake in curly braces. I accidentally put all the totaling code inside the main sim.accel() for loop, which cycles through the whole train and does the math for each element. This caused it to redo the totaling math in the middle of redoing the forces math, and it created all sorts of weird timing issues. It also screwed up the acceleration for a train with anything other than 1 locomotive and no cars, because it basically sped up time.