00001
00002
00003
00004
00005 #include <gtest/gtest.h>
00006
00007
00008 #include <dbw_fca_can/pedal_lut.h>
00009 using namespace dbw_fca_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)6888, brakeTorqueFromPedal(1.000));
00019 EXPECT_EQ((float)6888, brakeTorqueFromPedal(2.000));
00020 EXPECT_EQ((float)6888, brakeTorqueFromPedal(INFINITY));
00021
00022
00023 EXPECT_EQ((float) 0, brakeTorqueFromPedal(0.150));
00024 EXPECT_EQ((float) 0, brakeTorqueFromPedal(0.160));
00025 EXPECT_EQ((float)6888, brakeTorqueFromPedal(0.570));
00026 EXPECT_EQ((float)6888, brakeTorqueFromPedal(0.600));
00027
00028
00029 EXPECT_NEAR((float) 166.4, brakeTorqueFromPedal(0.22), (float)1.0);
00030 EXPECT_NEAR((float) 969.6, brakeTorqueFromPedal(0.28), (float)1.0);
00031 EXPECT_NEAR((float)1728.0, brakeTorqueFromPedal(0.32), (float)1.0);
00032 EXPECT_NEAR((float)3170.4, brakeTorqueFromPedal(0.38), (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.600, brakePedalFromTorque(9999));
00042 EXPECT_EQ((float)0.600, brakePedalFromTorque(INFINITY));
00043
00044
00045 EXPECT_EQ((float)0.150, brakePedalFromTorque(0));
00046 EXPECT_EQ((float)0.600, brakePedalFromTorque(6888));
00047
00048
00049 EXPECT_NEAR((float)0.150, brakePedalFromTorque(0.0000), (float)0.0000);
00050 EXPECT_NEAR((float)0.166, brakePedalFromTorque(0.0001), (float)0.0001);
00051
00052
00053 EXPECT_NEAR((float)0.566, brakePedalFromTorque(6887.999), (float)0.0001);
00054 EXPECT_NEAR((float)0.600, brakePedalFromTorque(6888.000), (float)0.0000);
00055
00056
00057 EXPECT_NEAR((float)0.196, brakePedalFromTorque( 50), (float)0.001);
00058 EXPECT_NEAR((float)0.282, brakePedalFromTorque(1000), (float)0.001);
00059 EXPECT_NEAR((float)0.333, brakePedalFromTorque(2000), (float)0.001);
00060 }
00061
00062
00063 #if 0 ///@TODO
00064 TEST(pedal_lut, brakePedalFromPercent)
00065 {
00066
00067 EXPECT_EQ((float)0.150, brakePedalFromPercent(-INFINITY));
00068 EXPECT_EQ((float)0.150, brakePedalFromPercent(-1));
00069 EXPECT_EQ((float)0.600, brakePedalFromPercent(2));
00070 EXPECT_EQ((float)0.600, brakePedalFromPercent(INFINITY));
00071
00072
00073 EXPECT_EQ((float)0.150, brakePedalFromPercent(0));
00074 EXPECT_EQ((float)0.600, brakePedalFromPercent(1));
00075
00076
00077 EXPECT_NEAR((float)0.150, brakePedalFromPercent(0.000000), (float)0.0000);
00078 EXPECT_NEAR((float)0.600, brakePedalFromPercent(0.000001), (float)0.0001);
00079
00080
00081 EXPECT_NEAR((float)0.566, brakePedalFromPercent(0.9999), (float)0.0001);
00082 EXPECT_NEAR((float)0.600, brakePedalFromPercent(1.0000), (float)0.0000);
00083
00084
00085 EXPECT_NEAR((float)0.000, brakePedalFromPercent(0.3), (float)0.001);
00086 EXPECT_NEAR((float)0.000, brakePedalFromPercent(0.5), (float)0.001);
00087 EXPECT_NEAR((float)0.000, brakePedalFromPercent(0.7), (float)0.001);
00088 }
00089 #endif
00090
00091
00092 TEST(pedal_lut, throttlePedalFromPercent)
00093 {
00094
00095 EXPECT_EQ((float)0.080, throttlePedalFromPercent(-INFINITY));
00096 EXPECT_EQ((float)0.080, throttlePedalFromPercent(-1));
00097 EXPECT_EQ((float)0.892, throttlePedalFromPercent(2));
00098 EXPECT_EQ((float)0.892, throttlePedalFromPercent(INFINITY));
00099
00100
00101 EXPECT_EQ((float)0.080, throttlePedalFromPercent(0));
00102 EXPECT_EQ((float)0.892, throttlePedalFromPercent(1));
00103
00104
00105 EXPECT_EQ((float)0.080, throttlePedalFromPercent(0.000));
00106 EXPECT_EQ((float)0.114, throttlePedalFromPercent(0.001));
00107
00108
00109 EXPECT_NEAR((float)0.343, throttlePedalFromPercent(0.3), (float)0.001);
00110 EXPECT_NEAR((float)0.497, throttlePedalFromPercent(0.5), (float)0.001);
00111 EXPECT_NEAR((float)0.655, throttlePedalFromPercent(0.7), (float)0.001);
00112 }
00113
00114
00115 TEST(pedal_lut, throttlePercentFromPedal)
00116 {
00117
00118 EXPECT_EQ((float)0.0, throttlePercentFromPedal(-INFINITY));
00119 EXPECT_EQ((float)0.0, throttlePercentFromPedal(-1.0));
00120 EXPECT_EQ((float)1.0, throttlePercentFromPedal(1.0));
00121 EXPECT_EQ((float)1.0, throttlePercentFromPedal(INFINITY));
00122
00123
00124 EXPECT_EQ((float)0.0, throttlePercentFromPedal(0.080));
00125 EXPECT_EQ((float)1.0, throttlePercentFromPedal(0.892));
00126
00127
00128 EXPECT_NEAR((float)0.3, throttlePercentFromPedal(0.343), (float)0.001);
00129 EXPECT_NEAR((float)0.5, throttlePercentFromPedal(0.497), (float)0.001);
00130 EXPECT_NEAR((float)0.7, throttlePercentFromPedal(0.655), (float)0.001);
00131 }
00132
00133 int main(int argc, char **argv)
00134 {
00135 testing::InitGoogleTest(&argc, argv);
00136 return RUN_ALL_TESTS();
00137 }
00138