Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions configurations/config_system_hil_attached.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
{"dut":{"connector":"J1","pin":10}, "hil":{"device":"FrontTester", "port":"DAC2"}},
{"dut":{"connector":"J1","pin":11}, "hil":{"device":"FrontTester", "port":"POT1"}},
{"dut":{"connector":"J1","pin":12}, "hil":{"device":"FrontTester", "port":"POT2"}}
]},
{"board":"Discharge", "harness_connections":[
{"dut":{"connector":"P7","pin":3}, "hil":{"device":"RearTester", "port":"DI3"}},
{"dut":{"connector":"P1","pin":1}, "hil":{"device":"RearTester", "port":"AI1"}},
{"dut":{"connector":"P2","pin":10}, "hil":{"device":"RearTester", "port":"RLY1"}}
]}
],
"hil_devices":[
Expand Down
56 changes: 56 additions & 0 deletions scripts/node_specific/scripts/test_discharge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from os import sys, path
# adds "./HIL-Testing" to the path, basically making it so these scripts were run one folder level higher
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))

from hil.hil import HIL
import hil.utils as utils
import time
from scripts.common.constants.rules_constants import *
from scripts.common.constants.vehicle_constants import *

import pytest_check as check
import pytest


# ---------------------------------------------------------------------------- #
@pytest.fixture(scope="session")
def hil():
hil_instance = HIL()

# TODO: new config file
hil_instance.load_config("config_system_hil_attached.json")
hil_instance.load_pin_map("per_24_net_map.csv", "stm32f407_pin_map.csv")

hil_instance.init_can()

yield hil_instance

hil_instance.shutdown()
# ---------------------------------------------------------------------------- #


# ---------------------------------------------------------------------------- #
@pytest.mark.parametrize("tsms_set, hv_plus_set, discharge_plus_expected", [
(1, 0, 0), # TSMS low = relay open, HV+ low -> discharge disconnected (0)
(0, 0, 0), # TSMS high = relay closed, HV+ low -> discharge connected but no voltage (0)
(1, 1, 0), # TSMS low = relay open, HV+ high -> discharge disconnected (0)
(0, 1, 1), # TSMS high = relay closed, HV+ high -> discharge connected with voltage (1)
])
def test_main_relay(hil, tsms_set, hv_plus_set, discharge_plus_expected):
# HIL outputs (hil writes)

# WIRING NOTE: SDC15 - TSMS is 24V logic, Arudino max voltage is 5V
# So instead, HIL will control the relay and 24V will be wired through the relay
tsms_hil_relay = hil.dout("Discharge", "SDC15 - TSMS")
hv_plus = hil.dout("Discharge", "HV+")

# HIL inputs (hil reads)
discharge_plus = hil.din("Discharge", "discharge+")

tsms_hil_relay.state = not tsms_set # HIL relay is inverted
hv_plus.state = hv_plus_set
time.sleep(0.2)

message = f"TSMS: {tsms_set}, HV+: {hv_plus_set} -> Discharge+: {discharge_plus_expected}"
check.equal(discharge_plus.state, discharge_plus_expected, message)
# ---------------------------------------------------------------------------- #