first
Dependents: 17robo_fuzi 17robo_tokyo_kaede
Diff: accelerator.cpp
- Revision:
- 0:e7a61140ec7d
diff -r 000000000000 -r e7a61140ec7d accelerator.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/accelerator.cpp Wed Sep 20 07:06:29 2017 +0000 @@ -0,0 +1,19 @@ + +#include "accelerator.h" +#include "mbed.h" + +void Accelerator::setup(float Acceleration, float time){ + a = Acceleration*time; + v = 0; +} + +float Accelerator::duty(float target){ + if (fabs(target-v) <= a) { + v = target; + } else if (v < target) { + v = v + a; + } else if (v > target) { + v = v - a; + } + return v; +} \ No newline at end of file