2022-03-02 17:35:58 +01:00
|
|
|
#!/usr/bin/env python3
|
2025-01-15 04:22:56 +05:30
|
|
|
import numpy as np
|
2022-03-02 17:35:58 +01:00
|
|
|
from abc import ABC, abstractmethod
|
2022-04-18 17:55:23 -07:00
|
|
|
|
2024-06-05 15:58:00 -07:00
|
|
|
from openpilot.common.realtime import DT_HW
|
2023-12-06 17:27:51 -08:00
|
|
|
from openpilot.common.swaglog import cloudlog
|
2024-08-31 16:49:29 -07:00
|
|
|
from openpilot.common.pid import PIDController
|
2022-03-02 17:35:58 +01:00
|
|
|
|
|
|
|
|
class BaseFanController(ABC):
|
|
|
|
|
@abstractmethod
|
2023-05-16 07:23:22 -07:00
|
|
|
def update(self, cur_temp: float, ignition: bool) -> int:
|
2022-03-02 17:35:58 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TiciFanController(BaseFanController):
|
|
|
|
|
def __init__(self) -> None:
|
|
|
|
|
super().__init__()
|
|
|
|
|
cloudlog.info("Setting up TICI fan handler")
|
|
|
|
|
|
|
|
|
|
self.last_ignition = False
|
2024-06-05 15:58:00 -07:00
|
|
|
self.controller = PIDController(k_p=0, k_i=4e-3, k_f=1, rate=(1 / DT_HW))
|
2022-03-02 17:35:58 +01:00
|
|
|
|
2023-05-16 07:23:22 -07:00
|
|
|
def update(self, cur_temp: float, ignition: bool) -> int:
|
|
|
|
|
self.controller.neg_limit = -(100 if ignition else 30)
|
2022-03-02 17:35:58 +01:00
|
|
|
self.controller.pos_limit = -(30 if ignition else 0)
|
|
|
|
|
|
|
|
|
|
if ignition != self.last_ignition:
|
|
|
|
|
self.controller.reset()
|
|
|
|
|
|
2025-04-10 16:33:36 +02:00
|
|
|
error = 75 - cur_temp
|
2022-03-02 17:35:58 +01:00
|
|
|
fan_pwr_out = -int(self.controller.update(
|
2022-04-07 11:34:45 -07:00
|
|
|
error=error,
|
2025-01-15 04:22:56 +05:30
|
|
|
feedforward=np.interp(cur_temp, [60.0, 100.0], [0, -100])
|
2022-03-02 17:35:58 +01:00
|
|
|
))
|
|
|
|
|
|
|
|
|
|
self.last_ignition = ignition
|
|
|
|
|
return fan_pwr_out
|
|
|
|
|
|