robot

Dependencies:   FastPWM3 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ThrottleMapper.cpp Source File

ThrottleMapper.cpp

00001 #include "ThrottleMapper.h"
00002 #include "derived.h"
00003 #include "prefs.h"
00004 
00005 float DrivingThrottleMapper::map(float throttle, float w) {
00006     if (throttle < 0.0f) throttle = 0.0f;
00007     
00008     float z = getZeroTqThrottle(w);
00009     float tq, tqmax;
00010     
00011     if (throttle > z) tqmax = getMaxTqpctPlus(w);
00012     if (throttle <= z) tqmax = getMaxTqpctMinus(w);
00013     
00014     if (throttle > z) tq = (throttle - z) / (1.0f - z);
00015     if (throttle <= z) tq = (throttle - z) / z;
00016     
00017     if (tq > tqmax) tq = tqmax;
00018     return tq;
00019 }
00020 
00021 float DrivingThrottleMapper::getMaxTqpctPlus(float w) {
00022     return _MAX_TQPCT_PLUS;
00023 }
00024 
00025 float DrivingThrottleMapper::getMaxTqpctMinus(float w) {
00026     return _MAX_TQPCT_MINUS;
00027 }
00028 
00029 float DrivingThrottleMapper::getZeroTqThrottle(float w) {
00030     float tmp = w / _W_MAX;
00031     return tmp < 1.0f ? tmp : 1.0f;
00032 }
00033 
00034 LimitingThrottleMapper::LimitingThrottleMapper(float wmax) {
00035     __wmax = wmax;
00036     __wlim = 0.95f * __wmax;
00037 }
00038 
00039 float LimitingThrottleMapper::map(float throttle, float w) {
00040     if (throttle < 0.0f) throttle = 0.0f;
00041     
00042     if (w <= __wlim) {
00043         return throttle;
00044     }
00045     if (w > __wmax) {
00046         w = __wmax;
00047     }
00048     return (__wmax - w) / (__wmax - __wlim) * throttle;
00049 }
00050 
00051 float AutoThrottleMapper::map(float throttle, float w) {
00052     if (throttle < 0.5f) return 0.0f;
00053     val += 1.0f / _period / _rate;
00054     if (val > 1.0f) val = 0.0f;
00055     return val;
00056 }