hitl_tester.test_cases.bms.test_korad_charge

Test Korad power supply logging and control functionality.

Used in these test plans:

  • nicd_charge ⠀⠀⠀(bms/nicd_charge.plan)

Example Command (warning: test plan may run other test cases):

  • ./hitl_tester.py nicd_charge -DSAMPLE_RATE=2 -DVOLTAGE=3 -DCURRENT=0.5
 1"""
 2Test Korad power supply logging and control functionality.
 3"""
 4
 5import time
 6
 7import pytest
 8
 9from hitl_tester.modules.bms.bms_hw import BMSHardware
10from hitl_tester.modules.bms.csv_tables import NiCdKorad
11from hitl_tester.modules.logger import logger
12
13SAMPLE_RATE = 2
14VOLTAGE = 3
15CURRENT = 0.500
16
17bms_hardware = BMSHardware(pytest.flags)  # type: ignore[arg-type]
18bms_hardware.init()
19
20
21def log_data(elapsed_time, status, voltage, current, korad_id):
22    """Log data."""
23    logger.write_info_to_report(
24        f"Elapsed Time(s): {elapsed_time:.3f}, Status: {status}, Voltage (V): {voltage}, Current(A): {current}, "
25        f"ID: {korad_id}"
26    )
27
28
29def test_logs():
30    """Test if we can read data from the power supply."""
31    start_time = time.perf_counter()
32    for korad_id, korad in bms_hardware.korads.items():
33        korad.csv = NiCdKorad(bms_hardware)
34        korad.csv.create_file(postfix=f"_KORAD_{korad_id}")
35    while True:
36        for korad_id, korad in bms_hardware.korads.items():
37            korad.csv.record(
38                elapsed_time := time.perf_counter() - start_time,
39                status := str(korad.status),
40                current := korad.measured_amps,
41                voltage := korad.measured_volts,
42            )
43            log_data(elapsed_time, status, voltage, current, korad_id)
44        time.sleep(SAMPLE_RATE)
45
46
47def test_charge():
48    """Test if we can charge from the power supply."""
49    for korad in bms_hardware.korads.values():
50        korad.set_profile(VOLTAGE, CURRENT)
51        korad.enable()
52    test_logs()
SAMPLE_RATE = 2
VOLTAGE = 3
CURRENT = 0.5
def log_data(elapsed_time, status, voltage, current, korad_id):
22def log_data(elapsed_time, status, voltage, current, korad_id):
23    """Log data."""
24    logger.write_info_to_report(
25        f"Elapsed Time(s): {elapsed_time:.3f}, Status: {status}, Voltage (V): {voltage}, Current(A): {current}, "
26        f"ID: {korad_id}"
27    )

Log data.

def test_logs():
30def test_logs():
31    """Test if we can read data from the power supply."""
32    start_time = time.perf_counter()
33    for korad_id, korad in bms_hardware.korads.items():
34        korad.csv = NiCdKorad(bms_hardware)
35        korad.csv.create_file(postfix=f"_KORAD_{korad_id}")
36    while True:
37        for korad_id, korad in bms_hardware.korads.items():
38            korad.csv.record(
39                elapsed_time := time.perf_counter() - start_time,
40                status := str(korad.status),
41                current := korad.measured_amps,
42                voltage := korad.measured_volts,
43            )
44            log_data(elapsed_time, status, voltage, current, korad_id)
45        time.sleep(SAMPLE_RATE)

Test if we can read data from the power supply.

def test_charge():
48def test_charge():
49    """Test if we can charge from the power supply."""
50    for korad in bms_hardware.korads.values():
51        korad.set_profile(VOLTAGE, CURRENT)
52        korad.enable()
53    test_logs()

Test if we can charge from the power supply.