test_pedal_lut.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * C++ unit test for dbw_mkz_can/pedal_lut.h
3  *********************************************************************/
4 
5 #include <gtest/gtest.h>
6 
7 // File under test
9 using namespace dbw_mkz_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)3412, brakeTorqueFromPedal(1.000));
19  EXPECT_EQ((float)3412, brakeTorqueFromPedal(2.000));
20  EXPECT_EQ((float)3412, 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)3412, brakeTorqueFromPedal(0.328));
26  EXPECT_EQ((float)3412, brakeTorqueFromPedal(0.330));
27 
28  // Normal values
29  EXPECT_NEAR((float) 520.0, brakeTorqueFromPedal(0.22), (float)1.0);
30  EXPECT_NEAR((float) 668.5, brakeTorqueFromPedal(0.24), (float)1.0);
31  EXPECT_NEAR((float)1749.5, brakeTorqueFromPedal(0.28), (float)1.0);
32  EXPECT_NEAR((float)2435.0, brakeTorqueFromPedal(0.30), (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.330, brakePedalFromTorque(9999));
42  EXPECT_EQ((float)0.330, brakePedalFromTorque(INFINITY));
43 
44  // Extreme values
45  EXPECT_EQ((float)0.150, brakePedalFromTorque(0));
46  EXPECT_EQ((float)0.330, brakePedalFromTorque(3412));
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.175, brakePedalFromTorque(0.0001), (float)0.0001);
51 
52  // Jump near max
53  EXPECT_NEAR((float)0.326, brakePedalFromTorque(3411.999), (float)0.0001);
54  EXPECT_NEAR((float)0.330, brakePedalFromTorque(3412.000), (float)0.0000);
55 
56  // Normal values
57  EXPECT_NEAR((float)0.195, brakePedalFromTorque( 50), (float)0.001);
58  EXPECT_NEAR((float)0.253, brakePedalFromTorque(1000), (float)0.001);
59  EXPECT_NEAR((float)0.288, brakePedalFromTorque(2000), (float)0.001);
60 }
61 
62 // Test converting from brake percent to brake pedal position
64 {
65  // Out of range
66  EXPECT_EQ((float)0.150, brakePedalFromPercent(-INFINITY));
67  EXPECT_EQ((float)0.150, brakePedalFromPercent(-1));
68  EXPECT_EQ((float)0.330, brakePedalFromPercent(2));
69  EXPECT_EQ((float)0.330, brakePedalFromPercent(INFINITY));
70 
71  // Extreme values
72  EXPECT_EQ((float)0.150, brakePedalFromPercent(0));
73  EXPECT_EQ((float)0.330, brakePedalFromPercent(1));
74 
75  // Jump from zero to non-zero
76  EXPECT_NEAR((float)0.150, brakePedalFromPercent(0.000000), (float)0.0000);
77  EXPECT_NEAR((float)0.175, brakePedalFromPercent(0.000001), (float)0.0001);
78 
79  // Jump near max
80  EXPECT_NEAR((float)0.326, brakePedalFromPercent(0.9999), (float)0.0001);
81  EXPECT_NEAR((float)0.330, brakePedalFromPercent(1.0000), (float)0.0000);
82 
83  // Normal values
84  EXPECT_NEAR((float)0.254, brakePedalFromPercent(0.3), (float)0.001);
85  EXPECT_NEAR((float)0.278, brakePedalFromPercent(0.5), (float)0.001);
86  EXPECT_NEAR((float)0.299, brakePedalFromPercent(0.7), (float)0.001);
87 }
88 
89 // Test converting from throttle percent to throttle pedal position
91 {
92  // Out of range
93  EXPECT_EQ((float)0.150, throttlePedalFromPercent(-INFINITY));
94  EXPECT_EQ((float)0.150, throttlePedalFromPercent(-1));
95  EXPECT_EQ((float)0.800, throttlePedalFromPercent(2));
96  EXPECT_EQ((float)0.800, throttlePedalFromPercent(INFINITY));
97 
98  // Extreme values
99  EXPECT_EQ((float)0.150, throttlePedalFromPercent(0));
100  EXPECT_EQ((float)0.800, throttlePedalFromPercent(1));
101 
102  // Jump from zero to non-zero
103  EXPECT_EQ((float)0.150, throttlePedalFromPercent(0.000));
104  EXPECT_EQ((float)0.165, throttlePedalFromPercent(0.001));
105 
106  // Normal values
107  EXPECT_NEAR((float)0.347, throttlePedalFromPercent(0.3), (float)0.001);
108  EXPECT_NEAR((float)0.477, throttlePedalFromPercent(0.5), (float)0.001);
109  EXPECT_NEAR((float)0.606, throttlePedalFromPercent(0.7), (float)0.001);
110 }
111 
112 // Test converting from throttle pedal position to throttle percent
114 {
115  // Out of range
116  EXPECT_EQ((float)0.0, throttlePercentFromPedal(-INFINITY));
117  EXPECT_EQ((float)0.0, throttlePercentFromPedal(-1));
118  EXPECT_EQ((float)1.0, throttlePercentFromPedal(1));
119  EXPECT_EQ((float)1.0, throttlePercentFromPedal(INFINITY));
120 
121  // Extreme values
122  EXPECT_EQ((float)0.0, throttlePercentFromPedal(0.15));
123  EXPECT_EQ((float)1.0, throttlePercentFromPedal(0.80));
124 
125  // Normal values
126  EXPECT_NEAR((float)0.3, throttlePercentFromPedal(0.347), (float)0.001);
127  EXPECT_NEAR((float)0.5, throttlePercentFromPedal(0.477), (float)0.001);
128  EXPECT_NEAR((float)0.7, throttlePercentFromPedal(0.606), (float)0.001);
129 }
130 
131 int main(int argc, char **argv)
132 {
133  testing::InitGoogleTest(&argc, argv);
134  return RUN_ALL_TESTS();
135 }
136 
static float brakeTorqueFromPedal(float pedal)
Definition: pedal_lut.h:64
static float brakePedalFromPercent(float percent)
Definition: pedal_lut.h:110
int main(int argc, char **argv)
static float throttlePercentFromPedal(float pedal)
Definition: pedal_lut.h:136
static float throttlePedalFromPercent(float percent)
Definition: pedal_lut.h:113
TEST(pedal_lut, brakeTorqueFromPedal)
static float brakePedalFromTorque(float torque)
Definition: pedal_lut.h:87


dbw_mkz_can
Author(s): Kevin Hallenbeck
autogenerated on Fri May 14 2021 02:47:08