test_pedal_lut.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * C++ unit test for dbw_fca_can/pedal_lut.h
3  *********************************************************************/
4 
5 #include <gtest/gtest.h>
6 
7 // File under test
9 using namespace dbw_fca_can;
10 
11 // Test converting from brake pedal position to brake torque
13 {
14  // Out of range
15  EXPECT_EQ((float) 0, brakeTorqueFromPedal(-INFINITY));
16  EXPECT_EQ((float) 0, brakeTorqueFromPedal(-1.00));
17  EXPECT_EQ((float) 0, brakeTorqueFromPedal(0.000));
18  EXPECT_EQ((float)6888, brakeTorqueFromPedal(1.000));
19  EXPECT_EQ((float)6888, brakeTorqueFromPedal(2.000));
20  EXPECT_EQ((float)6888, brakeTorqueFromPedal(INFINITY));
21 
22  // Extreme values
23  EXPECT_EQ((float) 0, brakeTorqueFromPedal(0.150));
24  EXPECT_EQ((float) 0, brakeTorqueFromPedal(0.160));
25  EXPECT_EQ((float)6888, brakeTorqueFromPedal(0.570));
26  EXPECT_EQ((float)6888, brakeTorqueFromPedal(0.600));
27 
28  // Normal values
29  EXPECT_NEAR((float) 166.4, brakeTorqueFromPedal(0.22), (float)1.0);
30  EXPECT_NEAR((float) 969.6, brakeTorqueFromPedal(0.28), (float)1.0);
31  EXPECT_NEAR((float)1728.0, brakeTorqueFromPedal(0.32), (float)1.0);
32  EXPECT_NEAR((float)3170.4, brakeTorqueFromPedal(0.38), (float)1.0);
33 }
34 
35 // Test converting from brake torque to brake pedal position
37 {
38  // Out of range
39  EXPECT_EQ((float)0.150, brakePedalFromTorque(-INFINITY));
40  EXPECT_EQ((float)0.150, brakePedalFromTorque(-1));
41  EXPECT_EQ((float)0.600, brakePedalFromTorque(9999));
42  EXPECT_EQ((float)0.600, brakePedalFromTorque(INFINITY));
43 
44  // Extreme values
45  EXPECT_EQ((float)0.150, brakePedalFromTorque(0));
46  EXPECT_EQ((float)0.600, brakePedalFromTorque(6888));
47 
48  // Jump from zero to non-zero
49  EXPECT_NEAR((float)0.150, brakePedalFromTorque(0.0000), (float)0.0000);
50  EXPECT_NEAR((float)0.166, brakePedalFromTorque(0.0001), (float)0.0001);
51 
52  // Jump near max
53  EXPECT_NEAR((float)0.566, brakePedalFromTorque(6887.999), (float)0.0001);
54  EXPECT_NEAR((float)0.600, brakePedalFromTorque(6888.000), (float)0.0000);
55 
56  // Normal values
57  EXPECT_NEAR((float)0.196, brakePedalFromTorque( 50), (float)0.001);
58  EXPECT_NEAR((float)0.282, brakePedalFromTorque(1000), (float)0.001);
59  EXPECT_NEAR((float)0.333, brakePedalFromTorque(2000), (float)0.001);
60 }
61 
62 // Test converting from brake percent to brake pedal position
63 #if 0
64 TEST(pedal_lut, brakePedalFromPercent)
65 {
66  // Out of range
67  EXPECT_EQ((float)0.150, brakePedalFromPercent(-INFINITY));
68  EXPECT_EQ((float)0.150, brakePedalFromPercent(-1));
69  EXPECT_EQ((float)0.600, brakePedalFromPercent(2));
70  EXPECT_EQ((float)0.600, brakePedalFromPercent(INFINITY));
71 
72  // Extreme values
73  EXPECT_EQ((float)0.150, brakePedalFromPercent(0));
74  EXPECT_EQ((float)0.600, brakePedalFromPercent(1));
75 
76  // Jump from zero to non-zero
77  EXPECT_NEAR((float)0.150, brakePedalFromPercent(0.000000), (float)0.0000);
78  EXPECT_NEAR((float)0.600, brakePedalFromPercent(0.000001), (float)0.0001);
79 
80  // Jump near max
81  EXPECT_NEAR((float)0.566, brakePedalFromPercent(0.9999), (float)0.0001);
82  EXPECT_NEAR((float)0.600, brakePedalFromPercent(1.0000), (float)0.0000);
83 
84  // Normal values
85  EXPECT_NEAR((float)0.000, brakePedalFromPercent(0.3), (float)0.001);
86  EXPECT_NEAR((float)0.000, brakePedalFromPercent(0.5), (float)0.001);
87  EXPECT_NEAR((float)0.000, brakePedalFromPercent(0.7), (float)0.001);
88 }
89 #endif
90 
91 // Test converting from throttle percent to throttle pedal position
93 {
94  // Out of range
95  EXPECT_EQ((float)0.080, throttlePedalFromPercent(-INFINITY));
96  EXPECT_EQ((float)0.080, throttlePedalFromPercent(-1));
97  EXPECT_EQ((float)0.892, throttlePedalFromPercent(2));
98  EXPECT_EQ((float)0.892, throttlePedalFromPercent(INFINITY));
99 
100  // Extreme values
101  EXPECT_EQ((float)0.080, throttlePedalFromPercent(0));
102  EXPECT_EQ((float)0.892, throttlePedalFromPercent(1));
103 
104  // Jump from zero to non-zero
105  EXPECT_EQ((float)0.080, throttlePedalFromPercent(0.000));
106  EXPECT_EQ((float)0.114, throttlePedalFromPercent(0.001));
107 
108  // Normal values
109  EXPECT_NEAR((float)0.343, throttlePedalFromPercent(0.3), (float)0.001);
110  EXPECT_NEAR((float)0.497, throttlePedalFromPercent(0.5), (float)0.001);
111  EXPECT_NEAR((float)0.655, throttlePedalFromPercent(0.7), (float)0.001);
112 }
113 
114 // Test converting from throttle pedal position to throttle percent
116 {
117  // Out of range
118  EXPECT_EQ((float)0.0, throttlePercentFromPedal(-INFINITY));
119  EXPECT_EQ((float)0.0, throttlePercentFromPedal(-1.0));
120  EXPECT_EQ((float)1.0, throttlePercentFromPedal(1.0));
121  EXPECT_EQ((float)1.0, throttlePercentFromPedal(INFINITY));
122 
123  // Extreme values
124  EXPECT_EQ((float)0.0, throttlePercentFromPedal(0.080));
125  EXPECT_EQ((float)1.0, throttlePercentFromPedal(0.892));
126 
127  // Normal values
128  EXPECT_NEAR((float)0.3, throttlePercentFromPedal(0.343), (float)0.001);
129  EXPECT_NEAR((float)0.5, throttlePercentFromPedal(0.497), (float)0.001);
130  EXPECT_NEAR((float)0.7, throttlePercentFromPedal(0.655), (float)0.001);
131 }
132 
133 int main(int argc, char **argv)
134 {
135  testing::InitGoogleTest(&argc, argv);
136  return RUN_ALL_TESTS();
137 }
138 
int main(int argc, char **argv)
static float brakePedalFromPercent(float percent)
Definition: pedal_lut.h:111
static float brakeTorqueFromPedal(float pedal)
Definition: pedal_lut.h:65
TEST(pedal_lut, brakeTorqueFromPedal)
static float brakePedalFromTorque(float torque)
Definition: pedal_lut.h:88
static float throttlePedalFromPercent(float percent)
Definition: pedal_lut.h:115
static float throttlePercentFromPedal(float pedal)
Definition: pedal_lut.h:139


dbw_fca_can
Author(s): Kevin Hallenbeck
autogenerated on Wed May 12 2021 02:14:05