grblHAL core  20240704
pid.h
Go to the documentation of this file.
1 /*
2  pid.h - An embedded CNC Controller with rs274/ngc (g-code) support
3 
4  PID algorithm for closed loop control
5 
6  NOTE: not referenced in the core grbl code
7 
8  Part of grblHAL
9 
10  Copyright (c) 2020-2023 Terje Io
11 
12  Grbl is free software: you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation, either version 3 of the License, or
15  (at your option) any later version.
16 
17  Grbl is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with Grbl. If not, see <http://www.gnu.org/licenses/>.
24 */
25 
26 #ifndef _PID_H_
27 #define _PID_H_
28 
29 #include <stdbool.h>
30 
31 typedef struct {
32  float p_gain;
33  float i_gain;
34  float d_gain;
35  float p_max_error;
36  float i_max_error;
37  float d_max_error;
38  float deadband;
39  float max_error;
40 } pid_values_t;
41 
42 typedef struct {
44  float deadband;
45  float i_error;
46  float d_error;
48  float error;
49  float max_error;
50 } pidf_t;
51 
52 void pidf_reset (pidf_t *pid);
53 void pidf_init(pidf_t *pid, pid_values_t *config);
54 bool pidf_config_changed (pidf_t *pid, pid_values_t *config);
55 float pidf (pidf_t *pid, float command, float actual, float sample_rate);
56 
57 #endif
void pidf_init(pidf_t *pid, pid_values_t *config)
Definition: pid.c:34
float pidf(pidf_t *pid, float command, float actual, float sample_rate)
Definition: pid.c:53
bool pidf_config_changed(pidf_t *pid, pid_values_t *config)
Definition: pid.c:40
void pidf_reset(pidf_t *pid)
Definition: pid.c:45
Definition: pid.h:31
float p_max_error
Definition: pid.h:35
float d_gain
Definition: pid.h:34
float d_max_error
Definition: pid.h:37
float deadband
Definition: pid.h:38
float max_error
Definition: pid.h:39
float i_gain
Definition: pid.h:33
float p_gain
Definition: pid.h:32
float i_max_error
Definition: pid.h:36
Definition: pid.h:42
pid_values_t cfg
Definition: pid.h:43
float i_error
Definition: pid.h:45
float sample_rate_prev
Definition: pid.h:47
float error
Definition: pid.h:48
float d_error
Definition: pid.h:46
float deadband
Definition: pid.h:44
float max_error
Definition: pid.h:49