Fri, 20 Mar 2015 16:56:07 +0100
Added support for all 1-wire temperature sensors that are in the Linux kernel source.
316
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /***************************************************************************** |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * Copyright (C) 2015 |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * Michiel Broek <mbroek at mbse dot eu> |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | * This file is part of the mbsePi-apps |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * This is free software; you can redistribute it and/or modify it |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * under the terms of the GNU General Public License as published by the |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * Free Software Foundation; either version 2, or (at your option) any |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * later version. |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * mbsePi-apps is distributed in the hope that it will be useful, but |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | * General Public License for more details. |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | * |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | * You should have received a copy of the GNU General Public License |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | * along with ThermFerm; see the file COPYING. If not, write to the Free |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | *****************************************************************************/ |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | #include "thermferm.h" |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | #include "pid.h" |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
26 | |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
27 | double UpdatePID(pid_var *pid, double error, double position) |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
28 | { |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | double pTerm, dTerm, iTerm; |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | pTerm = pid->pGain * error; |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
32 | |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
33 | /* |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | * Calculate the integral state with appopriate limiting |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | */ |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | pid->iState += error; |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | if (pid->iState > pid->iMax) |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | pid->iState = pid->iMax; |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
39 | else if (pid->iState < pid->iMin) |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
40 | pid->iState = pid->iMin; |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
42 | iTerm = pid->iGain * pid->iState; |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
43 | |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
44 | dTerm = pid->dGain * (pid->dState - position); |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
45 | pid->dState = position; |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
46 | |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
47 | return pTerm + dTerm + iTerm; |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
48 | } |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
49 | |
73cd31dc6ce1
Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
50 |