robot

Dependencies:   FastPWM3 mbed

Revision:
56:c681001dfa46
Parent:
42:030e0ec4eac5
Child:
111:451e40aed753
--- a/ThrottleMapper/ThrottleMapper.cpp	Wed Jan 25 02:41:17 2017 +0000
+++ b/ThrottleMapper/ThrottleMapper.cpp	Wed Jan 25 22:19:55 2017 +0000
@@ -29,4 +29,19 @@
 float DrivingThrottleMapper::getZeroTqThrottle(float w) {
     float tmp = w / W_MAX;
     return tmp < 1.0f ? tmp : 1.0f;
+}
+
+LimitingThrottleMapper::LimitingThrottleMapper(float wmax) {
+    __wmax = wmax;
+    __wlim = 0.95f * __wmax;
+}
+
+float LimitingThrottleMapper::map(float throttle, float w) {
+    if (w <= __wlim) {
+        return throttle;
+    }
+    if (w > __wmax) {
+        w = __wmax;
+    }
+    return (__wmax - w) / (__wmax - __wlim) * throttle;
 }
\ No newline at end of file