openpilot/panda/tests/hitl/7_internal.py
Vehicle Researcher c5d5c5d1f3 openpilot v0.10.1 release
date: 2025-10-24T00:30:59
master commit: 405631baf9685e171a0dd19547cb763f1b163d18
2025-10-24 00:31:03 -07:00

40 lines
1.1 KiB
Python

import time
import pytest
from panda import Panda
pytestmark = [
pytest.mark.test_panda_types(Panda.INTERNAL_DEVICES),
pytest.mark.test_panda_types([Panda.HW_TYPE_TRES])
]
@pytest.mark.timeout(2*60)
def test_fan_curve(p):
# ensure fan curve is (roughly) linear
for power in (30, 50, 80, 100):
p.set_fan_power(0)
while p.get_fan_rpm() > 0:
time.sleep(0.1)
# wait until fan spins up, then wait a bit more for the RPM to converge
p.set_fan_power(power)
for _ in range(20):
time.sleep(1)
if p.get_fan_rpm() > 1000:
break
time.sleep(5)
expected_rpm = Panda.MAX_FAN_RPMs[bytes(p.get_type())] * power / 100
assert 0.75 * expected_rpm <= p.get_fan_rpm() <= 1.25 * expected_rpm
def test_fan_cooldown(p):
# if the fan cooldown doesn't work, we get high frequency noise on the tach line
# while the rotor spins down. this makes sure it never goes beyond the expected max RPM
p.set_fan_power(100)
time.sleep(3)
p.set_fan_power(0)
for _ in range(5):
assert p.get_fan_rpm() <= Panda.MAX_FAN_RPMs[bytes(p.get_type())]
time.sleep(0.5)