matlabsimulinkpid-controller

How to use Simlink PID tools to implement a controller in matlab


I was wondering if it is possible to use simlink's PID architecture in matlab to actually control hardware - rather than modelling it.

I have been playing around a little with the PID tuning in matlab - and have worked out the correct gains for my system (or at least good enough).

Now I want to implement the actual control loop in matlab using the real hardware. In this case I am tying to stabilise a laser using a measurement from a wavemeter - although from the point of view of matlab essentially I have two functions - one which returns the current wavelength, and another which alters the wavelength with an input from 0-100.

How do I get the fancy PID objects to work in a loop where for example I input data each loop, and get the required output to stabilise things given my gains - or should I just hardcode the equations in?

I have tried looking through some of the simlink examples - but there doesn't seem to me much actual implementation - mostly just modelling.

Thanks in advance for any advice.


Solution

  • MATLAB (without Simulink, or with Simulink in purely a simulation mode) is not a real-time environment. Trying to use it to control hardware in real-time won't work unless you have very slow sample rates.

    If you do have slow sample rates, then you'd connect to your hardware to MATLAB using device drivers such as those in the Data Acquisition Toolbox

    You haven't found any info on real-time implementation in the Simulink documentation because from Simulink the mechanism for real-time implementation is via Simulink Coder. You would need to use it in conjunction with a real-time environment such as Simulink Desktop Real-Time (if your sample rates are relatively slow), Simulink Real-Time, or one of many other 3rd party real-time form factors.