00001
00002
00003
00004
00005 #include <gtest/gtest.h>
00006
00007
00008 #include <dbw_mkz_can/pedal_lut.h>
00009 using namespace dbw_mkz_can;
00010
00011
00012 TEST(pedal_lut, brakeTorqueFromPedal)
00013 {
00014
00015 EXPECT_EQ((float) 0, brakeTorqueFromPedal(-INFINITY));
00016 EXPECT_EQ((float) 0, brakeTorqueFromPedal(-1.00));
00017 EXPECT_EQ((float) 0, brakeTorqueFromPedal(0.000));
00018 EXPECT_EQ((float)3412, brakeTorqueFromPedal(1.000));
00019 EXPECT_EQ((float)3412, brakeTorqueFromPedal(2.000));
00020 EXPECT_EQ((float)3412, brakeTorqueFromPedal(INFINITY));
00021
00022
00023 EXPECT_EQ((float) 0, brakeTorqueFromPedal(0.150));
00024 EXPECT_EQ((float) 0, brakeTorqueFromPedal(0.160));
00025 EXPECT_EQ((float)3412, brakeTorqueFromPedal(0.328));
00026 EXPECT_EQ((float)3412, brakeTorqueFromPedal(0.330));
00027
00028
00029 EXPECT_NEAR((float) 520.0, brakeTorqueFromPedal(0.22), (float)1.0);
00030 EXPECT_NEAR((float) 668.5, brakeTorqueFromPedal(0.24), (float)1.0);
00031 EXPECT_NEAR((float)1749.5, brakeTorqueFromPedal(0.28), (float)1.0);
00032 EXPECT_NEAR((float)2435.0, brakeTorqueFromPedal(0.30), (float)1.0);
00033 }
00034
00035
00036 TEST(pedal_lut, brakePedalFromTorque)
00037 {
00038
00039 EXPECT_EQ((float)0.150, brakePedalFromTorque(-INFINITY));
00040 EXPECT_EQ((float)0.150, brakePedalFromTorque(-1));
00041 EXPECT_EQ((float)0.330, brakePedalFromTorque(9999));
00042 EXPECT_EQ((float)0.330, brakePedalFromTorque(INFINITY));
00043
00044
00045 EXPECT_EQ((float)0.150, brakePedalFromTorque(0));
00046 EXPECT_EQ((float)0.330, brakePedalFromTorque(3412));
00047
00048
00049 EXPECT_NEAR((float)0.150, brakePedalFromTorque(0.0000), (float)0.0000);
00050 EXPECT_NEAR((float)0.175, brakePedalFromTorque(0.0001), (float)0.0001);
00051
00052
00053 EXPECT_NEAR((float)0.326, brakePedalFromTorque(3411.999), (float)0.0001);
00054 EXPECT_NEAR((float)0.330, brakePedalFromTorque(3412.000), (float)0.0000);
00055
00056
00057 EXPECT_NEAR((float)0.195, brakePedalFromTorque( 50), (float)0.001);
00058 EXPECT_NEAR((float)0.253, brakePedalFromTorque(1000), (float)0.001);
00059 EXPECT_NEAR((float)0.288, brakePedalFromTorque(2000), (float)0.001);
00060 }
00061
00062
00063 TEST(pedal_lut, brakePedalFromPercent)
00064 {
00065
00066 EXPECT_EQ((float)0.150, brakePedalFromPercent(-INFINITY));
00067 EXPECT_EQ((float)0.150, brakePedalFromPercent(-1));
00068 EXPECT_EQ((float)0.330, brakePedalFromPercent(2));
00069 EXPECT_EQ((float)0.330, brakePedalFromPercent(INFINITY));
00070
00071
00072 EXPECT_EQ((float)0.150, brakePedalFromPercent(0));
00073 EXPECT_EQ((float)0.330, brakePedalFromPercent(1));
00074
00075
00076 EXPECT_NEAR((float)0.150, brakePedalFromPercent(0.000000), (float)0.0000);
00077 EXPECT_NEAR((float)0.175, brakePedalFromPercent(0.000001), (float)0.0001);
00078
00079
00080 EXPECT_NEAR((float)0.326, brakePedalFromPercent(0.9999), (float)0.0001);
00081 EXPECT_NEAR((float)0.330, brakePedalFromPercent(1.0000), (float)0.0000);
00082
00083
00084 EXPECT_NEAR((float)0.254, brakePedalFromPercent(0.3), (float)0.001);
00085 EXPECT_NEAR((float)0.278, brakePedalFromPercent(0.5), (float)0.001);
00086 EXPECT_NEAR((float)0.299, brakePedalFromPercent(0.7), (float)0.001);
00087 }
00088
00089
00090 TEST(pedal_lut, throttlePedalFromPercent)
00091 {
00092
00093 EXPECT_EQ((float)0.150, throttlePedalFromPercent(-INFINITY));
00094 EXPECT_EQ((float)0.150, throttlePedalFromPercent(-1));
00095 EXPECT_EQ((float)0.800, throttlePedalFromPercent(2));
00096 EXPECT_EQ((float)0.800, throttlePedalFromPercent(INFINITY));
00097
00098
00099 EXPECT_EQ((float)0.150, throttlePedalFromPercent(0));
00100 EXPECT_EQ((float)0.800, throttlePedalFromPercent(1));
00101
00102
00103 EXPECT_EQ((float)0.150, throttlePedalFromPercent(0.000));
00104 EXPECT_EQ((float)0.165, throttlePedalFromPercent(0.001));
00105
00106
00107 EXPECT_NEAR((float)0.347, throttlePedalFromPercent(0.3), (float)0.001);
00108 EXPECT_NEAR((float)0.477, throttlePedalFromPercent(0.5), (float)0.001);
00109 EXPECT_NEAR((float)0.606, throttlePedalFromPercent(0.7), (float)0.001);
00110 }
00111
00112
00113 TEST(pedal_lut, throttlePercentFromPedal)
00114 {
00115
00116 EXPECT_EQ((float)0.0, throttlePercentFromPedal(-INFINITY));
00117 EXPECT_EQ((float)0.0, throttlePercentFromPedal(-1));
00118 EXPECT_EQ((float)1.0, throttlePercentFromPedal(1));
00119 EXPECT_EQ((float)1.0, throttlePercentFromPedal(INFINITY));
00120
00121
00122 EXPECT_EQ((float)0.0, throttlePercentFromPedal(0.15));
00123 EXPECT_EQ((float)1.0, throttlePercentFromPedal(0.80));
00124
00125
00126 EXPECT_NEAR((float)0.3, throttlePercentFromPedal(0.347), (float)0.001);
00127 EXPECT_NEAR((float)0.5, throttlePercentFromPedal(0.477), (float)0.001);
00128 EXPECT_NEAR((float)0.7, throttlePercentFromPedal(0.606), (float)0.001);
00129 }
00130
00131 int main(int argc, char **argv)
00132 {
00133 testing::InitGoogleTest(&argc, argv);
00134 return RUN_ALL_TESTS();
00135 }
00136