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_FCA_CAN_PEDAL_LUT_H
00036 #define _DBW_FCA_CAN_PEDAL_LUT_H
00037 #include <math.h>
00038
00039 namespace dbw_fca_can
00040 {
00041
00042 static const struct {float pedal; float torque;} BRAKE_TABLE[] = {
00043
00044 {0.150, 0},
00045 {0.166, 0},
00046 {0.168, 4},
00047 {0.200, 56},
00048 {0.225, 194},
00049 {0.250, 456},
00050 {0.300, 1312},
00051 {0.350, 2352},
00052 {0.400, 3716},
00053 {0.434, 4740},
00054 {0.566, 6888},
00055 {0.600, 6888},
00056 };
00057 static const struct {float pedal; float percent;} THROTTLE_TABLE[] = {
00058
00059 {0.080, 0.000},
00060 {0.114, 0.001},
00061 {0.497, 0.500},
00062 {0.890, 0.998},
00063 {0.892, 1.000},
00064 };
00065 static inline float brakeTorqueFromPedal(float pedal) {
00066 const unsigned int size = sizeof(BRAKE_TABLE) / sizeof(BRAKE_TABLE[0]);
00067 if (pedal <= BRAKE_TABLE[0].pedal) {
00068 return BRAKE_TABLE[0].torque;
00069 } else if (pedal >= BRAKE_TABLE[size - 1].pedal) {
00070 return BRAKE_TABLE[size - 1].torque;
00071 } else {
00072 for (unsigned int i = 1; i < size; i++) {
00073 if (pedal < BRAKE_TABLE[i].pedal) {
00074 float start = BRAKE_TABLE[i - 1].torque;
00075 float dinput = pedal - BRAKE_TABLE[i - 1].pedal;
00076 float dtorque = BRAKE_TABLE[i].torque - BRAKE_TABLE[i - 1].torque;
00077 float dpedal = BRAKE_TABLE[i].pedal - BRAKE_TABLE[i - 1].pedal;
00078 if (fabsf(dpedal) > (float)1e-6) {
00079 return start + (dinput * dtorque / dpedal);
00080 } else {
00081 return start + (dtorque / 2);
00082 }
00083 }
00084 }
00085 }
00086 return 0.0;
00087 }
00088 static inline float brakePedalFromTorque(float torque) {
00089 const unsigned int size = sizeof(BRAKE_TABLE) / sizeof(BRAKE_TABLE[0]);
00090 if (torque <= BRAKE_TABLE[0].torque) {
00091 return BRAKE_TABLE[0].pedal;
00092 } else if (torque >= BRAKE_TABLE[size - 1].torque) {
00093 return BRAKE_TABLE[size - 1].pedal;
00094 } else {
00095 for (unsigned int i = 1; i < size; i++) {
00096 if (torque < BRAKE_TABLE[i].torque) {
00097 float start = BRAKE_TABLE[i - 1].pedal;
00098 float dinput = torque - BRAKE_TABLE[i - 1].torque;
00099 float dpedal = BRAKE_TABLE[i].pedal - BRAKE_TABLE[i - 1].pedal;
00100 float dtorque = BRAKE_TABLE[i].torque - BRAKE_TABLE[i - 1].torque;
00101 if (fabsf(dtorque) > (float)1e-6) {
00102 return start + (dinput * dpedal / dtorque);
00103 } else {
00104 return start + (dpedal / 2);
00105 }
00106 }
00107 }
00108 }
00109 return 0.0;
00110 }
00111 static inline float brakePedalFromPercent(float percent) {
00112 return brakePedalFromTorque(percent * 5000.0);
00113 return brakePedalFromTorque(percent * BRAKE_TABLE[sizeof(BRAKE_TABLE) / sizeof(BRAKE_TABLE[0]) - 1].torque);
00114 }
00115 static inline float throttlePedalFromPercent(float percent) {
00116 const unsigned int size = sizeof(THROTTLE_TABLE) / sizeof(THROTTLE_TABLE[0]);
00117 if (percent <= THROTTLE_TABLE[0].percent) {
00118 return THROTTLE_TABLE[0].pedal;
00119 } else if (percent >= THROTTLE_TABLE[size - 1].percent) {
00120 return THROTTLE_TABLE[size - 1].pedal;
00121 } else {
00122 for (unsigned int i = 1; i < size; i++) {
00123 if (percent < THROTTLE_TABLE[i].percent) {
00124 float start = THROTTLE_TABLE[i - 1].pedal;
00125 float dinput = percent - THROTTLE_TABLE[i - 1].percent;
00126 float dpedal = THROTTLE_TABLE[i].pedal - THROTTLE_TABLE[i - 1].pedal;
00127 float dpercent = THROTTLE_TABLE[i].percent - THROTTLE_TABLE[i - 1].percent;
00128 if (fabsf(dpercent) > (float)1e-6) {
00129 return start + (dinput * dpedal / dpercent);
00130 } else {
00131 return start + (dpedal / 2);
00132 }
00133 }
00134 }
00135 }
00136 return 0.0;
00137 }
00138
00139 static inline float throttlePercentFromPedal(float pedal) {
00140 const unsigned int size = sizeof(THROTTLE_TABLE) / sizeof(THROTTLE_TABLE[0]);
00141 if (pedal <= THROTTLE_TABLE[0].pedal) {
00142 return THROTTLE_TABLE[0].percent;
00143 } else if (pedal >= THROTTLE_TABLE[size - 1].pedal) {
00144 return THROTTLE_TABLE[size - 1].percent;
00145 } else {
00146 for (unsigned int i = 1; i < size; i++) {
00147 if (pedal < THROTTLE_TABLE[i].pedal) {
00148 float start = THROTTLE_TABLE[i - 1].percent;
00149 float dinput = pedal - THROTTLE_TABLE[i - 1].pedal;
00150 float dpercent = THROTTLE_TABLE[i].percent - THROTTLE_TABLE[i - 1].percent;
00151 float dpedal = THROTTLE_TABLE[i].pedal - THROTTLE_TABLE[i - 1].pedal;
00152 if (fabsf(dpedal) > (float) 1e-6) {
00153 return start + (dinput * dpercent / dpedal);
00154 } else {
00155 return start + (dpercent / 2);
00156 }
00157 }
00158 }
00159 }
00160 return 0.0;
00161 }
00162
00163 }
00164
00165 #endif // _DBW_FCA_CAN_PEDAL_LUT_H
00166