-
Notifications
You must be signed in to change notification settings - Fork 1
reprappro/HotEndModel
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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
About
RepRap Hot-End/Heated-bed modelling program.
Resources
Stars
Watchers
Forks
Releases
No releases published