hitl_tester.test_cases.bms.test_chroma_sim

Activate and use the cell simulators to confirm the hardware is working.

Used in these test plans:

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

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

  • ./hitl_tester.py chroma
 1"""
 2Activate and use the cell simulators to confirm the hardware is working.
 3"""
 4
 5import pytest
 6
 7from hitl_tester.modules.bms.bms_hw import BMSHardware
 8from hitl_tester.modules.bms.chroma_sim import ChromaCell
 9from hitl_tester.modules.logger import logger
10
11_bms = BMSHardware(pytest.flags)  # type: ignore[arg-type]
12_bms.init()
13
14
15class AllCells:
16    """Apply commands to all cells."""
17
18    def measured_volts(self) -> str:
19        """Get voltages."""
20        assert isinstance(_bms.cells[1], ChromaCell)
21        return str(_bms.cells[1].query("SIM:MEAS:CELL:VOLT? 1,1,16"))
22
23    def amps(self) -> str:
24        """Get currents."""
25        assert isinstance(_bms.cells[1], ChromaCell)
26        return str(_bms.cells[1].query("SIM:MEAS:CELL:CURR? 1,1,16"))
27
28
29cells = _bms.cells
30all_cells = AllCells()
31
32
33def docs():
34    """Output command info."""
35    logger.write_info_to_report(
36        '\nUse the "cells" dict to access all 16 cells.\n\n'
37        "Usage:\n"
38        "   Output: cells[1].enable(), cells[1].disable()\n"
39        "   Measurements: cells[1].amps, cells[1].measured_volts, all_cells.amps, all_cells.measured_volts\n"
40        "   Settings: cells[1].amps = 0.020, cells[1].volts = 1.2\n"
41        '   VISA access: cells[1].query("SYSTem:ERRor?"), cells[1].write("SIM:OUTP OFF"),\n'
42        "                cells.output_status(), cells.testing_status()\n\n"
43        'Useful VISA commands: "SYSTem:ERRor?", "SIM:MEAS:BMS:PROT?"\n\n'
44        "Hints:\n"
45        "    * Enable the output before setting amps/volts.\n"
46        '    * Set many cells at once with "for i in range(1,16): cells[i].amps = 2".\n'
47        '    * Enter and exit editor mode with "interact" & "CTRL-D".\n'
48        '    * Exit the test with "continue" or "CTRL-D".\n'
49        '    * The dir function can be used to see available functions, like "dir(cells[1])."\n\n'
50        'Type "docs()" to see this message anytime, and "continue" to exit...'
51    )
52
53
54def test_cell_sim():
55    """Activate and measure cell properties."""
56
57    logger.write_info_to_report("Dropping into pdb")
58    docs()
59    breakpoint()  # pylint: disable=forgotten-debug-statement
60    logger.write_info_to_report("Exiting pdb")
61
62    # for cell in _bms.cells.values():
63    #     logger.write_info_to_report(f"Setting cell voltage {cell.id}")
64    #     cell.volts = 3.8002
65    #     logger.write_info_to_report(f"Enabling cell {cell.id}")
66    #     cell.enable()
67    # while True:
68    #     logger.write_info_to_report("Scanning")
69    #     for i, cell in _bms.cells.items():
70    #         logger.write_info_to_report(f"Cell {i}: {cell.ohms}, {cell.volts}, {cell.amps}")
71    #     sleep(0.5)
class AllCells:
16class AllCells:
17    """Apply commands to all cells."""
18
19    def measured_volts(self) -> str:
20        """Get voltages."""
21        assert isinstance(_bms.cells[1], ChromaCell)
22        return str(_bms.cells[1].query("SIM:MEAS:CELL:VOLT? 1,1,16"))
23
24    def amps(self) -> str:
25        """Get currents."""
26        assert isinstance(_bms.cells[1], ChromaCell)
27        return str(_bms.cells[1].query("SIM:MEAS:CELL:CURR? 1,1,16"))

Apply commands to all cells.

def measured_volts(self) -> str:
19    def measured_volts(self) -> str:
20        """Get voltages."""
21        assert isinstance(_bms.cells[1], ChromaCell)
22        return str(_bms.cells[1].query("SIM:MEAS:CELL:VOLT? 1,1,16"))

Get voltages.

def amps(self) -> str:
24    def amps(self) -> str:
25        """Get currents."""
26        assert isinstance(_bms.cells[1], ChromaCell)
27        return str(_bms.cells[1].query("SIM:MEAS:CELL:CURR? 1,1,16"))

Get currents.

cells = {}
all_cells = <AllCells object>
def docs():
34def docs():
35    """Output command info."""
36    logger.write_info_to_report(
37        '\nUse the "cells" dict to access all 16 cells.\n\n'
38        "Usage:\n"
39        "   Output: cells[1].enable(), cells[1].disable()\n"
40        "   Measurements: cells[1].amps, cells[1].measured_volts, all_cells.amps, all_cells.measured_volts\n"
41        "   Settings: cells[1].amps = 0.020, cells[1].volts = 1.2\n"
42        '   VISA access: cells[1].query("SYSTem:ERRor?"), cells[1].write("SIM:OUTP OFF"),\n'
43        "                cells.output_status(), cells.testing_status()\n\n"
44        'Useful VISA commands: "SYSTem:ERRor?", "SIM:MEAS:BMS:PROT?"\n\n'
45        "Hints:\n"
46        "    * Enable the output before setting amps/volts.\n"
47        '    * Set many cells at once with "for i in range(1,16): cells[i].amps = 2".\n'
48        '    * Enter and exit editor mode with "interact" & "CTRL-D".\n'
49        '    * Exit the test with "continue" or "CTRL-D".\n'
50        '    * The dir function can be used to see available functions, like "dir(cells[1])."\n\n'
51        'Type "docs()" to see this message anytime, and "continue" to exit...'
52    )

Output command info.

def test_cell_sim():
55def test_cell_sim():
56    """Activate and measure cell properties."""
57
58    logger.write_info_to_report("Dropping into pdb")
59    docs()
60    breakpoint()  # pylint: disable=forgotten-debug-statement
61    logger.write_info_to_report("Exiting pdb")
62
63    # for cell in _bms.cells.values():
64    #     logger.write_info_to_report(f"Setting cell voltage {cell.id}")
65    #     cell.volts = 3.8002
66    #     logger.write_info_to_report(f"Enabling cell {cell.id}")
67    #     cell.enable()
68    # while True:
69    #     logger.write_info_to_report("Scanning")
70    #     for i, cell in _bms.cells.items():
71    #         logger.write_info_to_report(f"Cell {i}: {cell.ohms}, {cell.volts}, {cell.amps}")
72    #     sleep(0.5)

Activate and measure cell properties.