P, PI, PID tuning for controlling physical models


This article is about practical aspects of tuning linear controllers in models and maintaining awareness of the physical implications of the results, without delving into the theory. We’ll look at a well-behaved model, which nonetheless illustrates a few features available in the MSL, such as:

  1. A PID block with and output limiter: MSL.Blocks.Continuous.LimPID
  2. Time-tables
  3. Sensors

There are several aspects to take into consideration when tuning your PID gain and time constant values. These include:

  • Physical feasibility in general (avoiding applying forces & currents you later realise couldn’t be used)
  • Numerical problems (depending on the model, spikes, zero-crossings, and other numerical occurrences can sometimes prevent smooth operation!)
  • Signal processing (the real world requires measurements to take place & some are easier than others e.g. shaft torque can be non-trivial to measure)
  • Engineering specifications (making it easy to create your design without needless cost or difficulty when the modelling is over)

In this article we’ll pay attention to some of these considerations under controlled conditions.

Physical system model example requiring control

We will use the model of a DC electric motor with heat and friction losses driving a rotational inertia. The PID controller will control the voltage source to try and match the desired angular velocity profile of the motor shaft that is supplied via timeTable. The current state of the motor shaft angular velocity is fed back to the controller via a speed sensor. The PID output should be limited to the maximum voltage the DC motor can work with. An internal limiter to the PID can be used for these purposes and parameterised via the PID GUI.

Physical model requiring PID controller tuning to match a desired reference dynamic prescribed in the time table.

Figure 1: Physical model requiring PID controller tuning to match a desired reference dynamic prescribed in the time table.

Configuring and tuning the PID:

Proportional Control (PID.k)

As the name suggests, proportional control means the control action will be proportional to how far the measured variable has deviated from a desired state.

Physically, this is just like creating the effect of a “spring” between your target output, and the actual measured value of that output.

Exactly like a spring, making it stiffer will cause the output you’re interested in to be arrested more quickly, but depending on how the dynamics of your system work, it might cause “ringing” in the same way as a real spring would “ping” into place, but then buzz around the equilibrium position.

Results of Excessive Proportional Gain

In this first example the PID block is set to be used as a P (k=100) controller. The I and D related control are disabled. Observing the top plot in Figure 2, we might say that the model responds well – stably, and with fast damping, to an outsize gain. This in principle could seem a pretty successful way to tune the P controller. However, if we intend to implement or process the results in practice, it may be necessary to be more aware of the energy being deployed to control the system and assess whether this is conducive to robust operation.

First example: the PID block is set to be used as a P (k=100) controller.


Figure 2. PID.k = 100. From top: 1: demand u_s (blue) vs system response u_m (red), 2: PID output signal and equal to voltage source value, 3: Motor shaft torque, 4: Derivative of motor shaft torque

For example, it can be seen that with this high gain, the torque and its derivative shown in the third to fourth plot down in Figure 2 show significant spikes at particular points in the simulation. These points correspond to controlled changes in speed of the rotating shaft. Figure 3 shows the locally highly uneven output from the PID block, which could cause problems in later modelling and lead to potentially unnecessarily (numerically) “stiff” systems. Furthermore, shocking physical systems with the kinds of rates of change of torque shown is likely to generate other difficulties like excessive mount excitation and fatigue generating effects. The target angular velocity prescribed in the table is an idealised angular velocity profile that results in discrete changes in the acceleration demand of the shaft. In practice, it will not be possible to control a physical system such as the one described in Figure 2 to perfectly match the discrete changes in angular acceleration. We should expect a smoothed speed profile in these areas.

Zoomed section of controller and plant variables showing the undesired torque and torque derivative ripples

Figure 3. Zoomed section of controller and plant variables showing the undesired torque and torque derivative ripples at the points where there is a sudden change in acceleration demand that the controller strives to meet.

As we are concerned with the physical implications of using the control block, we should also note that while we’ve directly measured torque & it’s rate of change in the model, verifying these quantities may be non-trivial in a lab test. More importantly for now, is the relative difficulty in measuring high-frequency changes in signals such as those seen above. Creating an unverifiable model can cause practical problems in itself, and so bearing in mind what measurements are likely to be possible is critical in controller modelling, from the perspectives of validation, implementation, and repeatability.

Sensible Gain Value

If the gain k is reduced from 100 to 3 for example, we find that the outputs look a little bit more familiar, and the motor shaft dynamics are still close to the demand whilst reducing the torque and torque derivative spike magnitudes. The slight mismatch we see between the demand (PID.u_s) and response (PID.u_m) in the top subplot of Figure 4 can be reduced by introducing the Integral control.

Plots of controller and plant model variables using a reduced P controller "k" value

Figure 4. Plots of controller and plant model variables using a reduced P controller “k” value

Integral Control (PID.Ti)

Integral control is the process of using the average of the deviation from the desired result, over time, to add an additional control signal. This means that if the controlled variable is on one side of the demanded value, the controller will increase the signal, to correct the error. Integral control is expressed as a time-constant in the Dymola block, according to the expression:

By maintaining or slightly reducing the value of k and adding an integral control (for example: Ti = 0.5 – Note Td is still disabled) we can reduce the system response error while keeping modest gains. The effect on the torque and torque rate can be seen below with the previous attempt (k=3 with Ti disabled).

Effects of enabling the integral gain in the PID block

Figure 6. Effects of enabling the integral gain in the PID block. Errors in the system response vs. the demand are reduced. PI and P in the legends denote which parts of the PID block have been enabled.

Larger version of the top subplot in Figure 6.

Figure 7. Larger version of the top subplot in Figure 6. The plot shows the system response using a P controller (dashed line) and PI controller (solid black line) and the highlighted “setpoint” or demand (red).

Derivative Control (PID.Td)

Derivative control works by pushing back against rapid change in the output from which the feedback signal is coming. It’s most useful when there’s not sufficient existing tendency in the system dynamics to damp out vibrations and settle, or indeed if you’ve needed to use such a high level of integral control that it’s created oscillations.

In this case it isn’t a necessity but we will demonstrate the effects. The Td value isn’t as intuitive as Ti; a bigger effect is created as Td is increased. That tendency to take energy out of the system by tuning Td, can “soften” spikes, and prevent the controller making changes too quickly (bottom subplot in Figure 8).

If the output could be affected by sudden disturbances, derivative control is helpful, because it will start arresting the deviation caused by that immediately, before the output has gone far from the demand (k), or spent any time residing far from the demand (Ti).

Plot of the controller and plant model variables using a PID block with P and I enabled (blue) and P, I and D (Td = 0.1) enabled (red)

Figure 8. Plot of the controller and plant model variables using a PID block with P and I enabled (blue) and P, I and D (Td = 0.1) enabled (red)

As we proceed through introducing I and D to the P control we started with, it can sometimes be useful to adjust k to a lower value (thus weakening) and increase (thus weaken) Ti to a larger value to reduce the chance of oscillations in the system’s response.

In summary:

First, test the system response to following a step change or transient to inform the tuning.

  • P is enabled. I and D are turned off
  • Carry out tuning of P until the system response is just less than oscillatory (also check energy related variable dynamics such as in this case the torque and its derivative)
  • Consider a slight reduction of k (noting down the previous tuning as an upper limit for later fine-tuning). Introduce I and begin Ti tuning so that the error between demand and response goes to zero in a reasonable time for the system.
  • If you want to further improve the system response particularly in relation to derivatives you may want to introduce the derivative term D
    • Reduce k and increase Ti before tuning Td.

Different types of systems respond better to different P,I and D gain tuning. So for some systems you may just use PD, PI and for others PID. In most cases we deal with, PI controllers yield sufficient plant model control. In practice, PD control is uncommon because measuring the derivative of a measurement can be awkward (noisy, for example) while only integral control eliminates steady-state errors, that is, errors that do not diminish in time.

Written by: Sas Harrison – Systems Engineer


Please get in touch if you have any questions or have got a topic in mind that you would like us to write about. You can submit your questions / topics via: Tech Blog Questions / Topic Suggestion


Got a question? Just fill in this form and send it to us and we'll get back to you shortly.


© Copyright 2010-2022 Claytex Services Ltd All Rights Reserved

Log in with your credentials

Forgot your details?

Rolex Replica Watches Best Replica Watches