Electrical – Setting up a PID controller in Simulink for an Arduino example project

arduinocontrolMATLABpid controllersimulink

On the internet I found this "Arduino PID Example Lab" as an introduction to PID-contole. I set up the hardware and it is working like it is described in the document.
enter image description here
Since it is possible to connect Simulink with the Arduino as it is shown here, it would be nice to simulate the PID-control in Simulink. The needed Support Package for the Arduino is published here. After simulating the contole it could be connected to the Arduino to change the parameter while running. I managed to interface the arduino (read analog / digital values) and sent digital (PWM) signals. The main problem is about setting up the PID:

\$u(t)=MV(t)=K_pe(t)+K_i\int_o^t \!e(\tau)d\tau*K_d\frac{d}{dt}e(t)\$

src: Arduino PID Example Lab (1.1)

And to make it compatible with the analog input and the PWM output to the board.
So far this is what i got:
simulink model

Status-update:
status

Best Answer

The philosophy behind a PID controller (PID stands for Proportional Integral Derivative) is that you use the difference between the output of your system and and the desired output to generate a corrective input.

e(t) would be equal to the difference between the setpoint and the measured signal, that is e(t) = setpoint - measured_signal(t). Then you just apply the formula, inside your digital PID block. The derivative is optional, if you have a way of obtaining it, use it in your PID. If not, it's not a big deal. PI implementation You should get something similar to the image above, you will need the "Gain" block, the "Integrator" block and the sum. The error is the input, the output is the control input for the Arduino.

Kp and Ki are most easily usually obtained empirically, through manual tuning. Just begin with a small Kp and increase it until the response seems acceptable. Ki is used to kill any offset you have on the output, but slows down the response of the system. Again, you tune it manually, starting with a small Ki. If you want, you can try the Ziegler Nichols method (https://en.wikipedia.org/wiki/Ziegler%E2%80%93Nichols_method)

Related Topic