3 This file is part of the MSP Märklin suite
4 Copyright © 2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/core/except.h>
9 #include <msp/time/units.h>
10 #include "simplephysics.h"
17 SimplePhysics::SimplePhysics():
18 target_speed(TrainControl::continuous("speed", -1000, 1000)),
25 void SimplePhysics::set_control(const string &name, float v)
30 signal_control_changed.emit(name, target_speed.value);
34 const TrainControl &SimplePhysics::get_control(const string &name) const
39 throw KeyError("Unknown control", name);
42 float SimplePhysics::get_braking_distance() const
44 return speed*speed/(2*accel);
47 void SimplePhysics::tick(const Time::TimeDelta &dt)
49 float secs = dt/Time::sec;
50 if(speed<target_speed.value)
53 if(speed>target_speed.value)
54 speed = target_speed.value;
56 else if(speed>target_speed.value)
59 if(speed<target_speed.value)
60 speed = target_speed.value;
64 } // namespace Marklin