Source
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* pid.c PID controller for testing cooling devices
*
* Copyright (C) 2012 Intel Corporation. All rights reserved.
*
* Author Name Jacob Pan <jacob.jun.pan@linux.intel.com>
*/
/**************************************************************************
* PID (Proportional-Integral-Derivative) controller is commonly used in
* linear control system, consider the the process.
* G(s) = U(s)/E(s)
* kp = proportional gain
* ki = integral gain
* kd = derivative gain
* Ts
* We use type C Alan Bradley equation which takes set point off the
* output dependency in P and D term.
*
* y[k] = y[k-1] - kp*(x[k] - x[k-1]) + Ki*Ts*e[k] - Kd*(x[k]
* - 2*x[k-1]+x[k-2])/Ts
*
*
***********************************************************************/
struct pid_params p_param;
/* cached data from previous loop */
static double xk_1, xk_2; /* input temperature x[k-#] */
/*
* TODO: make PID parameters tuned automatically,
* 1. use CPU burn to produce open loop unit step response
* 2. calculate PID based on Ziegler-Nichols rule
*
* add a flag for tuning PID
*/
int init_thermal_controller(void)
{
int ret = 0;
/* init pid params */
p_param.ts = ticktime;
/* TODO: get it from TUI tuning tab */
p_param.kp = .36;
p_param.ki = 5.0;