-
Notifications
You must be signed in to change notification settings - Fork 1
/
README
150 lines (102 loc) · 4.82 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
RepRapPro Ltd Hot End Modelling Program
Adrian Bowyer
29 August 2012
This is a simple Java program to model the behaviour of a RepRap hot end (or
anything else that gets heated) to allow the parameters of a PID for controlling
it to be set automatically off-line.
To run this program from the command line, move to the directory in which
it is installed and type:
$ java -jar exe/hot-end-model.jar
The variables in the window that pops up have sensible defaults in them.
The variables are:
time increment (s)
The number of seconds between experimental temperature readings
end time (s)
How long your experiment ran
test power [0, 1]
The fraction of full power that your experiment used
D->A range
The maximum value that your D to A converter powering the heating
uses.
ODE a value
The power-in coefficient in the ordinary differential equation (see below).
ODE b value
The heat-loss coefficient in the ordinary differential equation (see below).
ODE lag value (s)
The time after heat is applied that it takes to have an effect.
target temperature (C)
The temperature that you want the PID to hit accurately quickly and stably.
heating time (s)
How long the PID can take to heat to that temperature.
PID Kp
The PID proportional coefficient.
PID Ki
The PID integral coefficient.
PID Kd
The PID differential coefficient.
PID integral clamp
The PID integral is not allowed to get bigger than this, or smaller
than minus this.
Experiment file name
The file with your experimental temperatures in.
ODE RMS error
Output: the mean residual sum of squares after the ODE parameters have been fitted.
PID RMS error
Output: the mean residual sum of squares after the PID parameters have been fitted.
The program runs in a loop till you hit Exit. Each time round it will report the
PID parameters it has computed in the boxes listed above (and also the ODE parameters).
The PID parameters are probably the ones you are interested in - it is those that you
need to copy into your temperature controlling firmware.
The PID looks like this in Java terms (easy to convert to C in firmware):
public double PID(double T, double[] pid)
{
eLast = e; // Old error: global variable
e = target - T; // Error now: global variable
double result = pid[Kp] * e + pid[Ki] * eIntegral + pid[Kd]
* (e - eLast) / dt; // dt is the time between calls: global variable
eIntegral += e * dt; // Error integral: global variable
if (eIntegral < -pid[clamp]) eIntegral = -pid[clamp];
if (eIntegral > pid[clamp]) eIntegral = pid[clamp];
if (result < 0) result = 0;
if (result > 1) result = 1;
return result;
}
T is the temperature now, and pid is a 4-element array with the PID parameters in got
from this program. The value returned is in the range [0,1]. It should be multiplied
by the D->A range value to get the number to send to the heater.
The file t04 in here is a samle set of experimental hot end results with the PWM set to 0.4*range
(where range is normally 255) run for four miniutes writing temperatures to the file every 0.4
seconds. You should obviously provide the equivalent data for your hot end.
-------------------------------------------------------------------------------
The Hot End is modelled as follows:
dT/dt = a*p + b*(T - T0) ----- (1)
t is time in seconds
T is temperature in C
p is the dimensionless input power.
T0 is room temperature
a and b are parameters that get set experimentally (see below).
For constant p, ODE (1) has the solution:
T = T0 + a*p*[1 - e^(b(tLag - t))]/b -----(2)
where tLag is the time between applying power and any change in temperature occurring.
p is changed to a PWM value in [0, range] internally.
Generally, the unknown values are a, b and tLag.
Referring to the graph sample-output.png, you run a simple experiment setting
the PWM into the heater constant (around 0.4*255-ish) and logging the
results every 0.4s (or whatever). This gives the red curve.
The program then does an iterative least-squares fit (the blue curve)
of the analytical solution of the differential equation that describes
the hot end to the experimental results. This gives all the hot end
parameters (response to input power, cooling, and time lag) automatically.
You then specify your ideal heating characteristic (the yellow curve).
The program then takes the hot end parameters it found plus the PID
controller terms and does another least-squares fit, this time keeping
the found hot-end parameters constant and optimising the PID
parameters to get the response as close as possible to the yellow
curve - the black curve.
The graph on the right in sample-output.png is the hot end running with
the computer PID parameters installed in the firmware. As you can see it
reproduces the black curve on the left well.
author Adrian Bowyer
RepRapPro Ltd
http://reprappro.com
Licence: GPL