You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					39 lines
				
				1.1 KiB
			
		
		
			
		
	
	
					39 lines
				
				1.1 KiB
			| 
								 
											4 years ago
										 
									 | 
							
								#!/usr/bin/env python3
							 | 
						||
| 
								 | 
							
								from abc import ABC, abstractmethod
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											1 year ago
										 
									 | 
							
								from openpilot.common.realtime import DT_HW
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								from openpilot.common.numpy_fast import interp
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								from openpilot.common.swaglog import cloudlog
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								from openpilot.selfdrive.controls.lib.pid import PIDController
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								class BaseFanController(ABC):
							 | 
						||
| 
								 | 
							
								  @abstractmethod
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								  def update(self, cur_temp: float, ignition: bool) -> int:
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    pass
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class TiciFanController(BaseFanController):
							 | 
						||
| 
								 | 
							
								  def __init__(self) -> None:
							 | 
						||
| 
								 | 
							
								    super().__init__()
							 | 
						||
| 
								 | 
							
								    cloudlog.info("Setting up TICI fan handler")
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    self.last_ignition = False
							 | 
						||
| 
								 
											1 year ago
										 
									 | 
							
								    self.controller = PIDController(k_p=0, k_i=4e-3, k_f=1, rate=(1 / DT_HW))
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								  def update(self, cur_temp: float, ignition: bool) -> int:
							 | 
						||
| 
								 | 
							
								    self.controller.neg_limit = -(100 if ignition else 30)
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    self.controller.pos_limit = -(30 if ignition else 0)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    if ignition != self.last_ignition:
							 | 
						||
| 
								 | 
							
								      self.controller.reset()
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    error = 70 - cur_temp
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    fan_pwr_out = -int(self.controller.update(
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								                      error=error,
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								                      feedforward=interp(cur_temp, [60.0, 100.0], [0, -100])
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								                    ))
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    self.last_ignition = ignition
							 | 
						||
| 
								 | 
							
								    return fan_pwr_out
							 | 
						||
| 
								 | 
							
								
							 |