MCU
Loading...
Searching...
No Matches
Classes | Functions
drivetrain_system_test.h File Reference
#include "DrivetrainSystem.h"
Include dependency graph for drivetrain_system_test.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  InverterCommand
 
class  InverterMock
 

Functions

 TEST (DrivetrainSystemTesting, test_drivetrain_startup)
 
 TEST (DrivetrainSystemTesting, test_drivetrain_init_timeout)
 
 TEST (DrivetrainSystemTesting, test_drivetrain_inverter_comms)
 

Function Documentation

◆ TEST() [1/3]

TEST ( DrivetrainSystemTesting  ,
test_drivetrain_init_timeout   
)

Definition at line 117 of file drivetrain_system_test.h.

118{
119 InverterMock inv_fl, inv_fr, inv_rl, inv_rr;
120 MCUInterface mcu;
121 DrivetrainSystem<InverterMock> dt({&inv_fl, &inv_fr, &inv_rl, &inv_rr}, &mcu, 1000);
122 unsigned long sys_time = 1000;
123 // test and make sure that normally the drivetrain doesnt timeout when changing the time
124 EXPECT_FALSE(dt.handle_inverter_startup(sys_time));
125 inv_fl.system_ready_ = true;
126 inv_fr.system_ready_ = true;
127 inv_rl.system_ready_ = true;
128 inv_rr.system_ready_ = true;
129 sys_time += 10;
130 // tick to request hv enable
131 EXPECT_FALSE(dt.handle_inverter_startup(sys_time));
132
133 sys_time += 10;
134 // tick to request enable inverters
135 EXPECT_FALSE(dt.handle_inverter_startup(sys_time));
136
137 sys_time += 10;
138 // tick to check inverters status
139 EXPECT_TRUE(dt.handle_inverter_startup(sys_time));
140 EXPECT_FALSE(dt.inverter_init_timeout(sys_time));
141
142 // test timeout
143 InverterMock inv_fl2, inv_fr2, inv_rl2, inv_rr2;
144 DrivetrainSystem<InverterMock> dt2({&inv_fl2, &inv_fr2, &inv_rl2, &inv_rr2}, &mcu,1000);
145 unsigned long sys_time2 = 1000;
146
147 EXPECT_FALSE(dt2.handle_inverter_startup(sys_time2));
148 // inv_fl.system_ready_ = true;
149 inv_fr2.system_ready_ = true;
150 inv_rl2.system_ready_ = true;
151 inv_rr2.system_ready_ = true;
152 sys_time2 += 1050;
153 EXPECT_TRUE(dt.inverter_init_timeout(sys_time2));
154}

◆ TEST() [2/3]

TEST ( DrivetrainSystemTesting  ,
test_drivetrain_inverter_comms   
)

Definition at line 156 of file drivetrain_system_test.h.

157{
158
159 InverterMock inv_fl, inv_fr, inv_rl, inv_rr;
160 MCUInterface mcu;
161 DrivetrainSystem<InverterMock> dt({&inv_fl, &inv_fr, &inv_rl, &inv_rr}, &mcu, 1000);
162 dt.command_drivetrain({{1000.0, 1001.0, 1002.0, 1003.0}, {2000.0, 2001.0, 2002.0, 2003.0}});
163
164 // torque_setpoint_nm_
165 // speed_setpoint_rpm_
166 // ensure that without ticking the inverters dont get the data
167 // as of 3/13/24 this isnt being handled by the drivetrain rn
168 // EXPECT_EQ(inv_fl.speed_setpoint_rpm_, 0.0);
169 // EXPECT_EQ(inv_fl.torque_setpoint_nm_, 0);
170
171 // EXPECT_EQ(inv_fr.torque_setpoint_nm_, 0);
172 // EXPECT_EQ(inv_fr.speed_setpoint_rpm_, 0);
173
174 // EXPECT_EQ(inv_rl.torque_setpoint_nm_, 0);
175 // EXPECT_EQ(inv_rl.speed_setpoint_rpm_, 0);
176
177 // EXPECT_EQ(inv_rr.torque_setpoint_nm_, 0);
178 // EXPECT_EQ(inv_rr.speed_setpoint_rpm_, 0);
179 SysClock clock;
180 auto micros = 1000000;
181 dt.tick(clock.tick(micros));
182 dt.command_drivetrain({{1000.0, 1001.0, 1002.0, 1003.0}, {10.0, 11.0, 12.0, 13.0}});
183 EXPECT_EQ(inv_fl.speed_setpoint_rpm_, 1000.0);
184 EXPECT_EQ(inv_fl.torque_setpoint_nm_, 10.0);
185
186 EXPECT_EQ(inv_fr.torque_setpoint_nm_, 11.0);
187 EXPECT_EQ(inv_fr.speed_setpoint_rpm_, 1001.0);
188
189 EXPECT_EQ(inv_rl.torque_setpoint_nm_, 12.0);
190 EXPECT_EQ(inv_rl.speed_setpoint_rpm_, 1002.0);
191
192 EXPECT_EQ(inv_rr.torque_setpoint_nm_, 13.0);
193 EXPECT_EQ(inv_rr.speed_setpoint_rpm_, 1003.0);
194
195 // testing to ensure that these extra general commands dont get through the period filter
196 // as of 3/13/24, the inverter sending rate is being handled at the inverter interface
197 // TODO decide if we want to add this back into the drivetrain
198 // micros += (20 * 1000);
199 // dt.tick(clock.tick(micros));
200 // dt.command_drivetrain({{1000.0, 1001.0, 1002.0, 1003.0}, {2000.0, 2001.0, 2002.0, 2003.0}});
201 // dt.command_drivetrain({{1000.0, 1001.0, 1002.0, 1003.0}, {2000.0, 2001.0, 2002.0, 2003.0}});
202 // dt.command_drivetrain({{1000.0, 1001.0, 1002.0, 1003.0}, {2000.0, 2001.0, 2002.0, 2003.0}});
203 // EXPECT_EQ(inv_rl.cmd_general_count_, 1);
204 // micros += (20 * 1000);
205 // dt.tick(clock.tick(micros));
206 // dt.command_drivetrain({{1000.0, 1001.0, 1002.0, 1003.0}, {2000.0, 2001.0, 2002.0, 2003.0}});
207 // EXPECT_EQ(inv_rl.cmd_general_count_, 2);
208}
void command_drivetrain(const DrivetrainCommand_s &data)

◆ TEST() [3/3]

TEST ( DrivetrainSystemTesting  ,
test_drivetrain_startup   
)

Definition at line 78 of file drivetrain_system_test.h.

79{
80
81 InverterMock inv_fl, inv_fr, inv_rl, inv_rr;
82 MCUInterface mcu;
83 DrivetrainSystem<InverterMock> dt({&inv_fl, &inv_fr, &inv_rl, &inv_rr}, &mcu, 1000);
84 unsigned long sys_time = 1000;
85 // inverters are not ready so an inverter startup call shouldnt send any requests to the inverter
86 // to start the initialization process
87 EXPECT_FALSE(dt.handle_inverter_startup(sys_time));
88 EXPECT_EQ(inv_fl.request_enable_hv_count_, 0);
89 EXPECT_EQ(inv_fr.request_enable_hv_count_, 0);
90 EXPECT_EQ(inv_rl.request_enable_hv_count_, 0);
91 EXPECT_EQ(inv_rr.request_enable_hv_count_, 0);
92
93 inv_fl.system_ready_ = true;
94 inv_fr.system_ready_ = true;
95 inv_rl.system_ready_ = true;
96 inv_rr.system_ready_ = true;
97
98 // this should enable the drivetrain hv
99 EXPECT_FALSE(dt.handle_inverter_startup(sys_time));
100
101 EXPECT_TRUE(inv_fl.dc_quit_on_);
102 EXPECT_TRUE(inv_fr.dc_quit_on_);
103 EXPECT_TRUE(inv_rl.dc_quit_on_);
104 EXPECT_TRUE(inv_rr.dc_quit_on_);
105
106 // im just gonna test one from now on for this type of stuff
107 EXPECT_EQ(inv_rr.request_enable_hv_count_, 1);
108 EXPECT_EQ(inv_rr.request_enable_inverter_count_, 0); // this should enable the inverters
109 EXPECT_FALSE(dt.handle_inverter_startup(sys_time));
110
111 EXPECT_EQ(inv_rr.request_enable_hv_count_, 1);
112 EXPECT_EQ(inv_rr.request_enable_inverter_count_, 1);
113
114 EXPECT_TRUE(dt.handle_inverter_startup(sys_time));
115}