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)
31 const TrainControl &SimplePhysics::get_control(const string &name) const
36 throw KeyError("Unknown control", name);
39 float SimplePhysics::get_braking_distance() const
41 return speed*speed/(2*accel);
44 void SimplePhysics::tick(const Time::TimeDelta &dt)
46 float secs = dt/Time::sec;
47 if(speed<target_speed.value)
50 if(speed>target_speed.value)
51 speed = target_speed.value;
53 else if(speed>target_speed.value)
56 if(speed<target_speed.value)
57 speed = target_speed.value;
61 } // namespace Marklin