From: Mikko Rasa Date: Fri, 6 Feb 2015 21:55:14 +0000 (+0200) Subject: Use max/min for range capping X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=0a7f23a01e45f1313b9f6f7f703da10aab8d060d;p=r2c2.git Use max/min for range capping --- diff --git a/source/libr2c2/sensor.cpp b/source/libr2c2/sensor.cpp index ecd0647..83dcb6d 100644 --- a/source/libr2c2/sensor.cpp +++ b/source/libr2c2/sensor.cpp @@ -2,6 +2,7 @@ #include "layout.h" #include "sensor.h" +using namespace std; using namespace Msp; namespace R2C2 { @@ -42,14 +43,13 @@ void Sensor::tick(const Time::TimeDelta &dt) { if(state_confirm_timeout) { - state_confirm_timeout -= dt; + state_confirm_timeout = max(state_confirm_timeout-dt, Time::zero); if(state_confirm_timeout<=Time::zero) { if(state==MAYBE_INACTIVE) state = INACTIVE; else if(state==MAYBE_ACTIVE) state = ACTIVE; - state_confirm_timeout = Time::zero; signal_state_changed.emit(state); } } diff --git a/source/libr2c2/simplecontroller.cpp b/source/libr2c2/simplecontroller.cpp index d04acab..df828d5 100644 --- a/source/libr2c2/simplecontroller.cpp +++ b/source/libr2c2/simplecontroller.cpp @@ -61,17 +61,9 @@ void SimpleController::tick(const Time::TimeDelta &dt) { float secs = dt/Time::sec; if(speedtarget_speed.value) - speed = target_speed.value; - } + speed = min(speed+secs*accel, target_speed.value); else if(speed>target_speed.value) - { - speed -= secs*accel; - if(speed