Rapid design, prototyping of PID controllers

Computer models can simulate processes, allowing you to design and refine PID controller action before it is implemented and deployed.


PID (proportional-integral-derivative) controllers are ubiquitous. Designing and tuning them may appear simple in theory, but it can be difficult and time-consuming in practice. A common method of tuning PID controllers is to adjust controller gains manually while the controller runs the plant. This time-consuming method requires access to the plant hardware and can lead to plant damage if chosen gain values result in unstable plant behavior. In this article we show how a development process can be improved by using model-based design to design, test, and implement PID controllers systematically on programmable logic controllers (PLCs), programmable automation controllers (PACs), and microprocessors. 

With model-based design we use a block-diagram environment to create system models of the plant and controller. These models can be simulated, allowing us to iterate and refine controller design quickly before it is implemented and deployed. The need for access to plant hardware is reduced because we can do a lot of testing through simulations instead of involving the plant. Early verification through simulation ensures that the controller performs as expected when deployed to the actual plant. This type of simulation and analysis is possible using a number of different software platforms from various vendors. In this particular case, our team used Simulink from MathWorks.

Model-based design of PID controllers involves the following four steps:

  • Creating the plant model;
  • Designing the PID controller;
  • Testing controller in real-time; and
  • Implementing the design.

Using a digital-motion control system as an example, we describe how to apply model-based design for rapid design and prototyping of a PID controller.

Digital motion control system

Figure 1 shows the plant, or the physical system, that we are trying to control. That plant consists of a power amplifier driving a dc motor and two rotary optical encoders for measuring the position of the motor shaft and the load. The motor is connected to the load through a small flexible shaft to approximate the compliance found between the actuator and the load in many motion control systems. The control system ensures that the load follows the specified trajectory by measuring the error between the commanded and measured load angle. It then uses a PID controller to calculate and send a voltage request to the motor. Our design is to improve machine performance from the current maximum speed of 150 rad/sec and acceleration of 2,000 rad/sec2 to new speed and acceleration targets of 250 rad/sec and 5000 rad/sec2, respectively. We want to achieve these performance gains without losing any position accuracy. Specifically, we want the error between commanded and measured load angle to be less than one degree. The existing controller design does not meet the new performance specifications, as shown in Figure 2.

Instead of manually tuning PID gains on the actual plant hardware, we can use model-based design to develop, test, and implement the controller.

Creating the plant model

There are two primary approaches for creating a plant model: data-driven modeling and first-principles modeling.

With data-driven modeling we create a plant model that fits measured input-output test data. We want to operate the controller during data collection to ensure minimal disruption of plant operation. To collect the input-output data, we add as our input signal a random white noise signal onto the voltage fed to the dc motor. Our output signal is the overall voltage that the controller commands to the dc motor. After we collect this input-output data, we can calculate the frequency response of the closed-loop system. And because we know the exact gains in our current controller design (the one we are trying to improve), we can obtain the frequency response of the plant. Finally, to be able to simulate our controller in the time domain, we use the frequency response of the plant to estimate the plant transfer function using system identification techniques.

With first-principles modeling we create the underlying dynamic equations of the plant using standard block-diagram modeling by connecting together gain, summation, and integrator blocks.

When modeling mechanical and electrical systems, it is often more convenient to create a plant model by taking “physical” components, such as inertia, stiffness, damping, resistance, and inductance, and connecting them, just as we would draw a mechanical diagram or electric circuit of the system. This variation of first-principles modeling technique, called physical modeling, enables us to create plant models without deriving the underlying equations of plant dynamics.

Often it is beneficial to blend these two distinct modeling approaches (data-driven and first-principles). To do this, we use measured input-output data from the actual system to adjust parameters of the physical model (Figure 5). Parameters (motor and load inertias, stiffness, and damping) are adjusted by using numerical optimization techniques. We play the measured input through the model and compare the model output to the measured output from the actual system. We iteratively adjust model parameters until we get the best possible fit between the output of the calibrated model and measured output. This iterative adjustment is completely automated using optimization techniques.

Designing the PID controller

PID design and tuning is easy once the plant model is available. We add a PID controller block to the block diagram model of our plant to create a closed-loop system model. It is parameterized with proportional, integral, and derivative gains that need to be updated to achieve the desired system performance. Rather than manually tuning these gains, we use an automatic PID tuning method, shown in Figure 6, that automatically calculates PID gains for our plant model. To speed up our controller, we use an interactive slider for a faster response time.

When we attempt to increase the controller speed, we notice that the system becomes unstable. Further analysis of the system in frequency domain reveals a resonant peak that is causing unstable behavior.

Such instability is a well-known issue in motion control systems and is easily fixed by using a notch filter to cancel the resonance. We can add the notch filter by using the interactive control design tool that lets us interactively place a notch filter on top of the resonant peak. Doing this allows us to stabilize the system and increase controller speed, as shown in Figure 8.

We now test our design (retuned PID controller and a notch filter) by running the nonlinear simulation of our closed-loop system on our desktop. This nonlinear model includes saturation effects in the motor. Running the simulation with the reference speed corresponding to the new desired system performance confirms that the new design meets the specifications, as shown in Figure 9.

Use of simulation enables us to see the issue with the control system—increasing the PID gains in this case was not sufficient to meet the performance specifications. We need a notch filter to cancel the resonant peak. Automated PID tuning allows us to find stabilizing controller gains and fine-tune the design quickly to meet desired performance targets. If we tried to tune our PID controller on the actual machine, we’d run into an unstable regime of operation that could have damaged our machine.

Testing the controller in real time

After the controller design has been validated via desktop simulation, the next step is to test the controller in real time. First we need to establish a real-time testing platform, which includes a real-time target computer with I/O boards, as shown in Figure 10. These IO boards are typically connected to the actual sensors and actuators on the machine (or machine prototype). We now reuse our controller model and automatically generate C code for the PID controller and the notch filter, and then download this C code to the real-time target computer. We now have our controller code running in real time on the target computer and directly controlling the operation of the plant via inputs and outputs from plant sensors and actuators. Real-time testing lets us confirm that the entire system works properly under realistic conditions with realistic inputs and outputs before we go through the effort of implementing the controller on production hardware, such as PLCs or PACs. This is sometimes known as rapid control prototyping. We are also able to verify that real-time controller performance is still in line with what we observed in the desktop simulation. If we find any discrepancies, we’re at an early enough stage in the development process and can diagnose and fix the problem quickly and easily in the simulation model, and then verify that the controller works properly in real time.

Implementing the design

Our last step is to deploy our controller to a target PLC, PAC, or microprocessor. We do that by automatically generating IEC 61131 structured text from our controller model. This structured text is generated in PLCopen XML and other file formats that are supported by widely used integrated development environments (IDEs). As a result, we can compile and deploy our controller to numerous PLC and PAC devices. If the final target is a microcontroller, we can instead automatically generate C code.

Using these techniques of plant modeling, closed-loop simulation, and automatic PID tuning allows us to tune and test our PID controller in desktop simulation. Our simulation model gives us the ability to identify a resonance in the system and to develop and test a notch filter to solve this problem. Real-time testing confirms that our control design matches desktop simulation results and meets design specifications. Implementation through automatic code generation means we are able to implement our design quickly on a PLC or microprocessor. Finally, the use of model-based design allows us to develop, test, and prototype our design quickly, without damaging plant hardware or disrupting its operation.

Arkadiy Turevskiy and Brian McKay are technical marketing managers at MathWorks, and Doug Eastern and Paul Lambrechts are senior application engineers for MathWorks.

The Top Plant program honors outstanding manufacturing facilities in North America. View the 2015 Top Plant.
The Product of the Year program recognizes products newly released in the manufacturing industries.
Each year, a panel of Control Engineering and Plant Engineering editors and industry expert judges select the System Integrator of the Year Award winners in three categories.
Doubling down on digital manufacturing; Data driving predictive maintenance; Electric motors and generators; Rewarding operational improvement
2017 Lubrication Guide; Software tools; Microgrids and energy strategies; Use robots effectively
Prescriptive maintenance; Hannover Messe 2017 recap; Reduce welding errors
The cloud, mobility, and remote operations; SCADA and contextual mobility; Custom UPS empowering a secure pipeline
Infrastructure for natural gas expansion; Artificial lift methods; Disruptive technology and fugitive gas emissions
Mobility as the means to offshore innovation; Preventing another Deepwater Horizon; ROVs as subsea robots; SCADA and the radio spectrum
Research team developing Tesla coil designs; Implementing wireless process sensing
Commissioning electrical systems; Designing emergency and standby generator systems; Paralleling switchgear generator systems
Natural gas engines; New applications for fuel cells; Large engines become more efficient; Extending boiler life

Annual Salary Survey

Before the calendar turned, 2016 already had the makings of a pivotal year for manufacturing, and for the world.

There were the big events for the year, including the United States as Partner Country at Hannover Messe in April and the 2016 International Manufacturing Technology Show in Chicago in September. There's also the matter of the U.S. presidential elections in November, which promise to shape policy in manufacturing for years to come.

But the year started with global economic turmoil, as a slowdown in Chinese manufacturing triggered a worldwide stock hiccup that sent values plummeting. The continued plunge in world oil prices has resulted in a slowdown in exploration and, by extension, the manufacture of exploration equipment.

Read more: 2015 Salary Survey

Maintenance and reliability tips and best practices from the maintenance and reliability coaches at Allied Reliability Group.
The One Voice for Manufacturing blog reports on federal public policy issues impacting the manufacturing sector. One Voice is a joint effort by the National Tooling and Machining...
The Society for Maintenance and Reliability Professionals an organization devoted...
Join this ongoing discussion of machine guarding topics, including solutions assessments, regulatory compliance, gap analysis...
IMS Research, recently acquired by IHS Inc., is a leading independent supplier of market research and consultancy to the global electronics industry.
Maintenance is not optional in manufacturing. It’s a profit center, driving productivity and uptime while reducing overall repair costs.
The Lachance on CMMS blog is about current maintenance topics. Blogger Paul Lachance is president and chief technology officer for Smartware Group.
The maintenance journey has been a long, slow trek for most manufacturers and has gone from preventive maintenance to predictive maintenance.
Featured articles highlight technologies that enable the Industrial Internet of Things, IIoT-related products and strategies to get data more easily to the user.
This digital report will explore several aspects of how IIoT will transform manufacturing in the coming years.
Maintenance Manager; California Oils Corp.
Associate, Electrical Engineering; Wood Harbinger
Control Systems Engineer; Robert Bosch Corp.
This course focuses on climate analysis, appropriateness of cooling system selection, and combining cooling systems.
This course will help identify and reveal electrical hazards and identify the solutions to implementing and maintaining a safe work environment.
This course explains how maintaining power and communication systems through emergency power-generation systems is critical.
click me