mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-18 20:03:53 +08:00
* misc system/hardware/ cleanup * lil more * pc is kinda base * lil more * lil more * lil more * int * lil more?
24 lines
724 B
Python
Executable File
24 lines
724 B
Python
Executable File
#!/usr/bin/env python3
|
|
import numpy as np
|
|
|
|
from openpilot.common.pid import PIDController
|
|
|
|
|
|
class FanController:
|
|
def __init__(self, rate: int) -> None:
|
|
self.last_ignition = False
|
|
self.controller = PIDController(k_p=0, k_i=4e-3, rate=rate)
|
|
|
|
def update(self, cur_temp: float, ignition: bool) -> int:
|
|
self.controller.pos_limit = 100 if ignition else 30
|
|
self.controller.neg_limit = 30 if ignition else 0
|
|
|
|
if ignition != self.last_ignition:
|
|
self.controller.reset()
|
|
self.last_ignition = ignition
|
|
|
|
return int(self.controller.update(
|
|
error=(cur_temp - 75), # temperature setpoint in C
|
|
feedforward=np.interp(cur_temp, [60.0, 100.0], [0, 100])
|
|
))
|