|
|
@ -62,23 +62,19 @@ class TestPowerMonitoring(unittest.TestCase): |
|
|
|
# Test to see that it integrates with discharging battery |
|
|
|
# Test to see that it integrates with discharging battery |
|
|
|
@parameterized.expand(ALL_PANDA_TYPES) |
|
|
|
@parameterized.expand(ALL_PANDA_TYPES) |
|
|
|
def test_offroad_integration_discharging(self, hw_type): |
|
|
|
def test_offroad_integration_discharging(self, hw_type): |
|
|
|
BATT_VOLTAGE = 4 |
|
|
|
POWER_DRAW = 4 |
|
|
|
BATT_CURRENT = 1 |
|
|
|
with pm_patch("HARDWARE.get_current_power_draw", POWER_DRAW): |
|
|
|
with pm_patch("HARDWARE.get_battery_voltage", BATT_VOLTAGE * 1e6), pm_patch("HARDWARE.get_battery_current", BATT_CURRENT * 1e6), \ |
|
|
|
|
|
|
|
pm_patch("HARDWARE.get_battery_status", "Discharging"), pm_patch("HARDWARE.get_current_power_draw", None): |
|
|
|
|
|
|
|
pm = PowerMonitoring() |
|
|
|
pm = PowerMonitoring() |
|
|
|
for _ in range(TEST_DURATION_S + 1): |
|
|
|
for _ in range(TEST_DURATION_S + 1): |
|
|
|
pm.calculate(self.mock_peripheralState(hw_type), False) |
|
|
|
pm.calculate(self.mock_peripheralState(hw_type), False) |
|
|
|
expected_power_usage = ((TEST_DURATION_S/3600) * (BATT_VOLTAGE * BATT_CURRENT) * 1e6) |
|
|
|
expected_power_usage = ((TEST_DURATION_S/3600) * POWER_DRAW * 1e6) |
|
|
|
self.assertLess(abs(pm.get_power_used() - expected_power_usage), 10) |
|
|
|
self.assertLess(abs(pm.get_power_used() - expected_power_usage), 10) |
|
|
|
|
|
|
|
|
|
|
|
# Test to check positive integration of car_battery_capacity |
|
|
|
# Test to check positive integration of car_battery_capacity |
|
|
|
@parameterized.expand(ALL_PANDA_TYPES) |
|
|
|
@parameterized.expand(ALL_PANDA_TYPES) |
|
|
|
def test_car_battery_integration_onroad(self, hw_type): |
|
|
|
def test_car_battery_integration_onroad(self, hw_type): |
|
|
|
BATT_VOLTAGE = 4 |
|
|
|
POWER_DRAW = 4 |
|
|
|
BATT_CURRENT = 1 |
|
|
|
with pm_patch("HARDWARE.get_current_power_draw", POWER_DRAW): |
|
|
|
with pm_patch("HARDWARE.get_battery_voltage", BATT_VOLTAGE * 1e6), pm_patch("HARDWARE.get_battery_current", BATT_CURRENT * 1e6), \ |
|
|
|
|
|
|
|
pm_patch("HARDWARE.get_battery_status", "Discharging"), pm_patch("HARDWARE.get_current_power_draw", None): |
|
|
|
|
|
|
|
pm = PowerMonitoring() |
|
|
|
pm = PowerMonitoring() |
|
|
|
pm.car_battery_capacity_uWh = 0 |
|
|
|
pm.car_battery_capacity_uWh = 0 |
|
|
|
for _ in range(TEST_DURATION_S + 1): |
|
|
|
for _ in range(TEST_DURATION_S + 1): |
|
|
@ -89,10 +85,8 @@ class TestPowerMonitoring(unittest.TestCase): |
|
|
|
# Test to check positive integration upper limit |
|
|
|
# Test to check positive integration upper limit |
|
|
|
@parameterized.expand(ALL_PANDA_TYPES) |
|
|
|
@parameterized.expand(ALL_PANDA_TYPES) |
|
|
|
def test_car_battery_integration_upper_limit(self, hw_type): |
|
|
|
def test_car_battery_integration_upper_limit(self, hw_type): |
|
|
|
BATT_VOLTAGE = 4 |
|
|
|
POWER_DRAW = 4 |
|
|
|
BATT_CURRENT = 1 |
|
|
|
with pm_patch("HARDWARE.get_current_power_draw", POWER_DRAW): |
|
|
|
with pm_patch("HARDWARE.get_battery_voltage", BATT_VOLTAGE * 1e6), pm_patch("HARDWARE.get_battery_current", BATT_CURRENT * 1e6), \ |
|
|
|
|
|
|
|
pm_patch("HARDWARE.get_battery_status", "Discharging"), pm_patch("HARDWARE.get_current_power_draw", None): |
|
|
|
|
|
|
|
pm = PowerMonitoring() |
|
|
|
pm = PowerMonitoring() |
|
|
|
pm.car_battery_capacity_uWh = CAR_BATTERY_CAPACITY_uWh - 1000 |
|
|
|
pm.car_battery_capacity_uWh = CAR_BATTERY_CAPACITY_uWh - 1000 |
|
|
|
for _ in range(TEST_DURATION_S + 1): |
|
|
|
for _ in range(TEST_DURATION_S + 1): |
|
|
@ -103,29 +97,25 @@ class TestPowerMonitoring(unittest.TestCase): |
|
|
|
# Test to check negative integration of car_battery_capacity |
|
|
|
# Test to check negative integration of car_battery_capacity |
|
|
|
@parameterized.expand(ALL_PANDA_TYPES) |
|
|
|
@parameterized.expand(ALL_PANDA_TYPES) |
|
|
|
def test_car_battery_integration_offroad(self, hw_type): |
|
|
|
def test_car_battery_integration_offroad(self, hw_type): |
|
|
|
BATT_VOLTAGE = 4 |
|
|
|
POWER_DRAW = 4 |
|
|
|
BATT_CURRENT = 1 |
|
|
|
with pm_patch("HARDWARE.get_current_power_draw", POWER_DRAW): |
|
|
|
with pm_patch("HARDWARE.get_battery_voltage", BATT_VOLTAGE * 1e6), pm_patch("HARDWARE.get_battery_current", BATT_CURRENT * 1e6), \ |
|
|
|
|
|
|
|
pm_patch("HARDWARE.get_battery_status", "Discharging"), pm_patch("HARDWARE.get_current_power_draw", None): |
|
|
|
|
|
|
|
pm = PowerMonitoring() |
|
|
|
pm = PowerMonitoring() |
|
|
|
pm.car_battery_capacity_uWh = CAR_BATTERY_CAPACITY_uWh |
|
|
|
pm.car_battery_capacity_uWh = CAR_BATTERY_CAPACITY_uWh |
|
|
|
for _ in range(TEST_DURATION_S + 1): |
|
|
|
for _ in range(TEST_DURATION_S + 1): |
|
|
|
pm.calculate(self.mock_peripheralState(hw_type), False) |
|
|
|
pm.calculate(self.mock_peripheralState(hw_type), False) |
|
|
|
expected_capacity = CAR_BATTERY_CAPACITY_uWh - ((TEST_DURATION_S/3600) * (BATT_VOLTAGE * BATT_CURRENT) * 1e6) |
|
|
|
expected_capacity = CAR_BATTERY_CAPACITY_uWh - ((TEST_DURATION_S/3600) * POWER_DRAW * 1e6) |
|
|
|
self.assertLess(abs(pm.get_car_battery_capacity() - expected_capacity), 10) |
|
|
|
self.assertLess(abs(pm.get_car_battery_capacity() - expected_capacity), 10) |
|
|
|
|
|
|
|
|
|
|
|
# Test to check negative integration lower limit |
|
|
|
# Test to check negative integration lower limit |
|
|
|
@parameterized.expand(ALL_PANDA_TYPES) |
|
|
|
@parameterized.expand(ALL_PANDA_TYPES) |
|
|
|
def test_car_battery_integration_lower_limit(self, hw_type): |
|
|
|
def test_car_battery_integration_lower_limit(self, hw_type): |
|
|
|
BATT_VOLTAGE = 4 |
|
|
|
POWER_DRAW = 4 |
|
|
|
BATT_CURRENT = 1 |
|
|
|
with pm_patch("HARDWARE.get_current_power_draw", POWER_DRAW): |
|
|
|
with pm_patch("HARDWARE.get_battery_voltage", BATT_VOLTAGE * 1e6), pm_patch("HARDWARE.get_battery_current", BATT_CURRENT * 1e6), \ |
|
|
|
|
|
|
|
pm_patch("HARDWARE.get_battery_status", "Discharging"), pm_patch("HARDWARE.get_current_power_draw", None): |
|
|
|
|
|
|
|
pm = PowerMonitoring() |
|
|
|
pm = PowerMonitoring() |
|
|
|
pm.car_battery_capacity_uWh = 1000 |
|
|
|
pm.car_battery_capacity_uWh = 1000 |
|
|
|
for _ in range(TEST_DURATION_S + 1): |
|
|
|
for _ in range(TEST_DURATION_S + 1): |
|
|
|
pm.calculate(self.mock_peripheralState(hw_type), False) |
|
|
|
pm.calculate(self.mock_peripheralState(hw_type), False) |
|
|
|
estimated_capacity = 0 - ((1/3600) * (BATT_VOLTAGE * BATT_CURRENT) * 1e6) |
|
|
|
estimated_capacity = 0 - ((1/3600) * POWER_DRAW * 1e6) |
|
|
|
self.assertLess(abs(pm.get_car_battery_capacity() - estimated_capacity), 10) |
|
|
|
self.assertLess(abs(pm.get_car_battery_capacity() - estimated_capacity), 10) |
|
|
|
|
|
|
|
|
|
|
|
# Test to check policy of stopping charging after MAX_TIME_OFFROAD_S |
|
|
|
# Test to check policy of stopping charging after MAX_TIME_OFFROAD_S |
|
|
@ -151,11 +141,9 @@ class TestPowerMonitoring(unittest.TestCase): |
|
|
|
# Test to check policy of stopping charging when the car voltage is too low |
|
|
|
# Test to check policy of stopping charging when the car voltage is too low |
|
|
|
@parameterized.expand(ALL_PANDA_TYPES) |
|
|
|
@parameterized.expand(ALL_PANDA_TYPES) |
|
|
|
def test_car_voltage(self, hw_type): |
|
|
|
def test_car_voltage(self, hw_type): |
|
|
|
BATT_VOLTAGE = 4 |
|
|
|
POWER_DRAW = 0 # To stop shutting down for other reasons |
|
|
|
BATT_CURRENT = 0 # To stop shutting down for other reasons |
|
|
|
|
|
|
|
TEST_TIME = 100 |
|
|
|
TEST_TIME = 100 |
|
|
|
with pm_patch("HARDWARE.get_battery_voltage", BATT_VOLTAGE * 1e6), pm_patch("HARDWARE.get_battery_current", BATT_CURRENT * 1e6), \ |
|
|
|
with pm_patch("HARDWARE.get_current_power_draw", POWER_DRAW): |
|
|
|
pm_patch("HARDWARE.get_battery_status", "Discharging"), pm_patch("HARDWARE.get_current_power_draw", None): |
|
|
|
|
|
|
|
pm = PowerMonitoring() |
|
|
|
pm = PowerMonitoring() |
|
|
|
pm.car_battery_capacity_uWh = CAR_BATTERY_CAPACITY_uWh |
|
|
|
pm.car_battery_capacity_uWh = CAR_BATTERY_CAPACITY_uWh |
|
|
|
ignition = False |
|
|
|
ignition = False |
|
|
@ -168,12 +156,10 @@ class TestPowerMonitoring(unittest.TestCase): |
|
|
|
|
|
|
|
|
|
|
|
# Test to check policy of not stopping charging when DisablePowerDown is set |
|
|
|
# Test to check policy of not stopping charging when DisablePowerDown is set |
|
|
|
def test_disable_power_down(self): |
|
|
|
def test_disable_power_down(self): |
|
|
|
BATT_VOLTAGE = 4 |
|
|
|
POWER_DRAW = 0 # To stop shutting down for other reasons |
|
|
|
BATT_CURRENT = 0 # To stop shutting down for other reasons |
|
|
|
|
|
|
|
TEST_TIME = 100 |
|
|
|
TEST_TIME = 100 |
|
|
|
params.put_bool("DisablePowerDown", True) |
|
|
|
params.put_bool("DisablePowerDown", True) |
|
|
|
with pm_patch("HARDWARE.get_battery_voltage", BATT_VOLTAGE * 1e6), pm_patch("HARDWARE.get_battery_current", BATT_CURRENT * 1e6), \ |
|
|
|
with pm_patch("HARDWARE.get_current_power_draw", POWER_DRAW): |
|
|
|
pm_patch("HARDWARE.get_battery_status", "Discharging"), pm_patch("HARDWARE.get_current_power_draw", None): |
|
|
|
|
|
|
|
pm = PowerMonitoring() |
|
|
|
pm = PowerMonitoring() |
|
|
|
pm.car_battery_capacity_uWh = CAR_BATTERY_CAPACITY_uWh |
|
|
|
pm.car_battery_capacity_uWh = CAR_BATTERY_CAPACITY_uWh |
|
|
|
ignition = False |
|
|
|
ignition = False |
|
|
@ -186,11 +172,9 @@ class TestPowerMonitoring(unittest.TestCase): |
|
|
|
|
|
|
|
|
|
|
|
# Test to check policy of not stopping charging when ignition |
|
|
|
# Test to check policy of not stopping charging when ignition |
|
|
|
def test_ignition(self): |
|
|
|
def test_ignition(self): |
|
|
|
BATT_VOLTAGE = 4 |
|
|
|
POWER_DRAW = 0 # To stop shutting down for other reasons |
|
|
|
BATT_CURRENT = 0 # To stop shutting down for other reasons |
|
|
|
|
|
|
|
TEST_TIME = 100 |
|
|
|
TEST_TIME = 100 |
|
|
|
with pm_patch("HARDWARE.get_battery_voltage", BATT_VOLTAGE * 1e6), pm_patch("HARDWARE.get_battery_current", BATT_CURRENT * 1e6), \ |
|
|
|
with pm_patch("HARDWARE.get_current_power_draw", POWER_DRAW): |
|
|
|
pm_patch("HARDWARE.get_battery_status", "Discharging"), pm_patch("HARDWARE.get_current_power_draw", None): |
|
|
|
|
|
|
|
pm = PowerMonitoring() |
|
|
|
pm = PowerMonitoring() |
|
|
|
pm.car_battery_capacity_uWh = CAR_BATTERY_CAPACITY_uWh |
|
|
|
pm.car_battery_capacity_uWh = CAR_BATTERY_CAPACITY_uWh |
|
|
|
ignition = True |
|
|
|
ignition = True |
|
|
@ -203,11 +187,9 @@ class TestPowerMonitoring(unittest.TestCase): |
|
|
|
|
|
|
|
|
|
|
|
# Test to check policy of not stopping charging when harness is not connected |
|
|
|
# Test to check policy of not stopping charging when harness is not connected |
|
|
|
def test_harness_connection(self): |
|
|
|
def test_harness_connection(self): |
|
|
|
BATT_VOLTAGE = 4 |
|
|
|
POWER_DRAW = 0 # To stop shutting down for other reasons |
|
|
|
BATT_CURRENT = 0 # To stop shutting down for other reasons |
|
|
|
|
|
|
|
TEST_TIME = 100 |
|
|
|
TEST_TIME = 100 |
|
|
|
with pm_patch("HARDWARE.get_battery_voltage", BATT_VOLTAGE * 1e6), pm_patch("HARDWARE.get_battery_current", BATT_CURRENT * 1e6), \ |
|
|
|
with pm_patch("HARDWARE.get_current_power_draw", POWER_DRAW): |
|
|
|
pm_patch("HARDWARE.get_battery_status", "Discharging"), pm_patch("HARDWARE.get_current_power_draw", None): |
|
|
|
|
|
|
|
pm = PowerMonitoring() |
|
|
|
pm = PowerMonitoring() |
|
|
|
pm.car_battery_capacity_uWh = CAR_BATTERY_CAPACITY_uWh |
|
|
|
pm.car_battery_capacity_uWh = CAR_BATTERY_CAPACITY_uWh |
|
|
|
|
|
|
|
|
|
|
|