Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef _DBW_MKZ_CAN_PEDAL_LUT_H
00036 #define _DBW_MKZ_CAN_PEDAL_LUT_H
00037 #include <math.h>
00038
00039 namespace dbw_mkz_can
00040 {
00041
00042 static const struct {float pedal; float torque;} BRAKE_TABLE[] = {
00043
00044 {0.150, 0},
00045 {0.175, 0},
00046 {0.184, 4},
00047 {0.208, 108},
00048 {0.211, 519},
00049 {0.234, 521},
00050 {0.246, 816},
00051 {0.283, 1832},
00052 {0.305, 2612},
00053 {0.323, 3316},
00054 {0.326, 3412},
00055 {0.330, 3412},
00056 };
00057 static const struct {float pedal; float percent;} THROTTLE_TABLE[] = {
00058
00059 {0.150, 0.000},
00060 {0.165, 0.001},
00061 {0.166, 0.020},
00062 {0.800, 1.000},
00063 };
00064 static inline float brakeTorqueFromPedal(float pedal) {
00065 const unsigned int size = sizeof(BRAKE_TABLE) / sizeof(BRAKE_TABLE[0]);
00066 if (pedal <= BRAKE_TABLE[0].pedal) {
00067 return BRAKE_TABLE[0].torque;
00068 } else if (pedal >= BRAKE_TABLE[size - 1].pedal) {
00069 return BRAKE_TABLE[size - 1].torque;
00070 } else {
00071 for (unsigned int i = 1; i < size; i++) {
00072 if (pedal < BRAKE_TABLE[i].pedal) {
00073 float start = BRAKE_TABLE[i - 1].torque;
00074 float dinput = pedal - BRAKE_TABLE[i - 1].pedal;
00075 float dtorque = BRAKE_TABLE[i].torque - BRAKE_TABLE[i - 1].torque;
00076 float dpedal = BRAKE_TABLE[i].pedal - BRAKE_TABLE[i - 1].pedal;
00077 if (fabsf(dpedal) > (float)1e-6) {
00078 return start + (dinput * dtorque / dpedal);
00079 } else {
00080 return start + (dtorque / 2);
00081 }
00082 }
00083 }
00084 }
00085 return 0.0;
00086 }
00087 static inline float brakePedalFromTorque(float torque) {
00088 const unsigned int size = sizeof(BRAKE_TABLE) / sizeof(BRAKE_TABLE[0]);
00089 if (torque <= BRAKE_TABLE[0].torque) {
00090 return BRAKE_TABLE[0].pedal;
00091 } else if (torque >= BRAKE_TABLE[size - 1].torque) {
00092 return BRAKE_TABLE[size - 1].pedal;
00093 } else {
00094 for (unsigned int i = 1; i < size; i++) {
00095 if (torque < BRAKE_TABLE[i].torque) {
00096 float start = BRAKE_TABLE[i - 1].pedal;
00097 float dinput = torque - BRAKE_TABLE[i - 1].torque;
00098 float dpedal = BRAKE_TABLE[i].pedal - BRAKE_TABLE[i - 1].pedal;
00099 float dtorque = BRAKE_TABLE[i].torque - BRAKE_TABLE[i - 1].torque;
00100 if (fabsf(dtorque) > (float)1e-6) {
00101 return start + (dinput * dpedal / dtorque);
00102 } else {
00103 return start + (dpedal / 2);
00104 }
00105 }
00106 }
00107 }
00108 return 0.0;
00109 }
00110 static inline float brakePedalFromPercent(float percent) {
00111 return brakePedalFromTorque(percent * BRAKE_TABLE[sizeof(BRAKE_TABLE) / sizeof(BRAKE_TABLE[0]) - 1].torque);
00112 }
00113 static inline float throttlePedalFromPercent(float percent) {
00114 const unsigned int size = sizeof(THROTTLE_TABLE) / sizeof(THROTTLE_TABLE[0]);
00115 if (percent <= THROTTLE_TABLE[0].percent) {
00116 return THROTTLE_TABLE[0].pedal;
00117 } else if (percent >= THROTTLE_TABLE[size - 1].percent) {
00118 return THROTTLE_TABLE[size - 1].pedal;
00119 } else {
00120 for (unsigned int i = 1; i < size; i++) {
00121 if (percent < THROTTLE_TABLE[i].percent) {
00122 float start = THROTTLE_TABLE[i - 1].pedal;
00123 float dinput = percent - THROTTLE_TABLE[i - 1].percent;
00124 float dpedal = THROTTLE_TABLE[i].pedal - THROTTLE_TABLE[i - 1].pedal;
00125 float dpercent = THROTTLE_TABLE[i].percent - THROTTLE_TABLE[i - 1].percent;
00126 if (fabsf(dpercent) > (float)1e-6) {
00127 return start + (dinput * dpedal / dpercent);
00128 } else {
00129 return start + (dpedal / 2);
00130 }
00131 }
00132 }
00133 }
00134 return 0.0;
00135 }
00136 static inline float throttlePercentFromPedal(float pedal) {
00137 const unsigned int size = sizeof(THROTTLE_TABLE) / sizeof(THROTTLE_TABLE[0]);
00138 if (pedal <= THROTTLE_TABLE[0].pedal) {
00139 return THROTTLE_TABLE[0].percent;
00140 } else if (pedal >= THROTTLE_TABLE[size - 1].pedal) {
00141 return THROTTLE_TABLE[size - 1].percent;
00142 } else {
00143 for (unsigned int i = 1; i < size; i++) {
00144 if (pedal < THROTTLE_TABLE[i].pedal) {
00145 float start = THROTTLE_TABLE[i - 1].percent;
00146 float dinput = pedal - THROTTLE_TABLE[i - 1].pedal;
00147 float dpercent = THROTTLE_TABLE[i].percent - THROTTLE_TABLE[i - 1].percent;
00148 float dpedal = THROTTLE_TABLE[i].pedal - THROTTLE_TABLE[i - 1].pedal;
00149 if (fabsf(dpedal) > (float) 1e-6) {
00150 return start + (dinput * dpercent / dpedal);
00151 } else {
00152 return start + (dpercent / 2);
00153 }
00154 }
00155 }
00156 }
00157 return 0.0;
00158 }
00159
00160 }
00161
00162 #endif // _DBW_MKZ_CAN_PEDAL_LUT_H
00163