8.2: Model-Free Dual-PID Mini-Segway Control System Architecture

Mechatronics: Fundamentals, Design, Integration, and Validation · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    8.2: Model-Free Dual-PID Mini-Segway Control System Architecture
    Learning Objectives

    After completing this section, you will be able to:

    1. Describe the dual-PID control architecture of the mini-Segway.
    2. Provide the advantage and disadvantage of the mini-Segway’s dual-PID loop control.
    3. Explain the reason for setting the integration gain of one of the dual PID controllers to zero.
    4. Improve control performance by utilizing the anti-windup function for both continuous- and discrete-time PID controllers.

    This section introduces the mini-Segway’s dual-PID control. The detailed PID (proportional-integral-derivative) control technique and its control parameter tuning methods were addressed in Section 3.4 and reference [5]. Here, we will first review the PID controller in both continuous- and discrete-time forms. Let \(e\left(t\right)\) be a continuous-time error signal (reference minus measured control target). Then, in the time domain, we can describe a continuous-time PID control law with \(u_{PID}\left(t\right)\) as the PID control output.

    \[u_{PID}\left(t\right)=K_pe\left(t\right)+K_i\int^t_0{e\left(τ\right)dτ}+K_d\dfrac{de(t)}{dt} \label{8.37}\]

    where \(K_p\), \(K_i\), and \(K_d\) are continuous-time proportional, integral, and derivative gains, respectively. Its Laplace transform is shown below.

    \[U_{PID}\left(s\right)=\left(K_p+\dfrac{K_i}{s}+K_ds\right)E\left(s\right)=C_{PID}\left(s\right)E(s) \label{8.38}\]

    where \(U_{PID}(s)\) and \(E(s)\) are Laplace transforms of \(u_{PID}(t)\) and \(e(t)\), repectively; and \(C_{PID}(s)\) is the PID controller transfer function. For details of the Laplace transform, see Section 2.1. A continuous-time PID controller cannot be efficiently implemented into a microcontroller because continuous-time integration and derivative calculations are inefficient. To implement the PID controller in discrete-time, we must use discrete-time integration and derivative operations to replace the continuous-time ones. The real-time Simulink software for the Arduino family microcontroller allows direct use of the continuous-time transfer function, where these transfer functions are converted into associated digital operations during the software compiling process. Practically, the derivative operation in the PID controller often amplifies the high-frequency components in the error signal normally from the measured feedback signal. This leads to noisy control output. Often, a low-pass filter in the form of \({\left(T_ds+1\right)}^{-1}\)is placed before the derivative operation shown below as a modified PID controller, where \(T_d\) is the time constant of the low-pass filter.

    \[U_{PID}\left(s\right)=\left(K_p+\dfrac{K_i}{s}+\dfrac{K_ds}{T_ds+1}\right)E\left(s\right) \label{8.39}\]

    The time constant \(T_d\) is selected so that the corner frequency of the low-pass filter, \(ω_c=\)\(T^{-1}_d\)is at least five times the dynamic system bandwidth. Physical actuators have limitations such as maximum armature voltage for a DC motor corresponding to its maximum stalled torque and no-load speed (see Section 5.2). In this case, a saturation operation may be required to limit the PID control output to meet the limitation requirement. However, with the implementation of saturation on the PID control output, the integration windup phenomenon could occur, leading to slow PID control response [4], [14], [15]. The windup occurs when the PID controller output is saturated and the integrator continuously integrates the error, making the saturation worse. When the error signal sign is reversed, it takes a long time to get the integration output to reflect it. This causes a slow PID control response [4], [14], and [15]. To avoid integration windup of PID controllers, an anti-windup logic was developed in references [4] and [14]; it modified the PID controller described in equation \ref{8.37} as follows, with \(l_{max}\) and \(l_{min}\) (\(l_{max}>l_{min}\)) as the saturation maximum and minimum limits, respectively.

    \[u_{PID}\left(t\right)=K_pe\left(t\right)+g_iK_i\int^t_0{e\left(τ\right)dτ}+K_d\dfrac{de(t)}{dt} \label{8.40}\]

    where \(g_i\) is a gain coefficient used to enable or disable the integration action. It is defined below.

    \[\ g_i=\left\{ \begin{array}{cc} 0, & if\ u_{PID}\left(t\right)\ge l_{max}\ \&\ e(t)>0\ or\ u_{PID}\left(t\right)\le l_{min}\ \&\ e(t)<0 \\ 1, & else \ \end{array} \right. \label{8.41}\]

    The numerical logic in equation \ref{8.41} disables the integration operation (by setting \(g_i=0\)) in two conditions. The first is when PID control output \(u_{PID}\left(t\right)\) is greater than or equal to PID control output upper limit \(l_{max}\ \)with PID control input error\(\ e(t)\) greater than zero (positive). The second is when PID control output \(u_{PID}\left(t\right)\) is less than or equal to PID control output lower limit \(l_{min}\ \)with PID control input error\(\ e(t)\) less than zero (negative). The intension is that if the PID control output \(u_{PID}\left(t\right)\) is saturated from above, the integration action is enabled only when the PID input error \(e(t)\) is negative. The control output \(u_{PID}\left(t\right)\) can then be reduced. If the PID control output \(u_{PID}\left(t\right)\) is saturated from below, the integration action is enabled only when the PID input error \(e(t)\) is positive. The control output \(u_{PID}\left(t\right)\) can then be increased. Finally, if the PID control output \(u_{PID}\left(t\right)\) is between the lower saturation limit \(l_{min}\) and upper saturation limit \(l_{max}\), the integration action is always enabled. Figure 8.10 shows a Simulink implementation of continuous-time PID control with anti-windup capability; all parameters are as defined before, assuming the integration gain \(K_i\) is positive.

    A Simulink block diagram showing the implementation of continuous-time anti-windup PID controller that stops positive integration when the output is saturated above and negative integration when the output is saturated below.
    Figure 8.10: Continuous-time Simulink implementation of anti-windup PID controller.

    Another form of the PID controller is defined in the discrete-time domain as below.

    \[u_{PID}\left(k\right)=K_pe\left(k\right)+K_iT_s\sum^k_{n=0}{e(k)}+K_d\dfrac{e\left(k\right)-e(k-1)}{T_s} \label{8.42}\]

    where \(K_p\), \(K_i\), and \(K_d\) are discrete-time equivalent proportional, integral, and derivative gains, respectively; \(T_s\) is the sample period of the discrete-time PID controller; and \(e\left(k\right)\) and \(u_{PID}\left(k\right)\) are discrete-time error and PID control signals at sample step \(k\), respectively. Then, in the discrete frequency domain (also called \(z\)-domain), we can describe a discrete-time PID control law \ref{8.42} in the form of a \(z\)-transform, where \(z=e^{sT_s}\) (see Section 4.4).

    \[U_{PID}\left(z\right)=\left(K_p+\dfrac{K_iT_s}{1-z^{-1}}+\dfrac{K_d}{T_s}(1-z^{-1})\right)E\left(z\right)=C_{PID}\left(z\right)E(z) \label{8.43}\]

    where \(U_{PID}(z)\) and \(E(z)\) are \(z\)-transforms of \(u_{PID}(k)\) and \(e(k)\), respectively; \(C_{PID}(z)\) is the discrete-time PID controller transfer function; \({T_s\left(1-z^{-1}\right)}^{-1}\) is the \(z\)-transform of the discrete-time integration; and \((1-z^{-1})/T_s\) is the \(z\)-transform of the discrete-time time derivative (that is, the continuous-time derivative is replaced by the discrete-time difference operation). For the discrete-time transfer function, \(z^{-1}\) is a one-step delay operator; if inversed \(z\)-transform \({\mathcal{Z}}^{-1}\left[E\left(z\right)\right]\) equals to \(e(k)\), then inversed \(z\)-transform of \({\mathcal{Z}}^{-1}\left[z^{-1}E\left(z\right)\right]\) is \(e(k-1)\). Similarly, we can place a low-pass digital filter in the form of \((1-e^{-T_s/T_d}){\left(1-e^{-T_s/T_d}z^{-1}\right)}^{-1}\) before the derivative operation shown below as a modified PID controller, where \(T_d\) is the time constant of the low-pass filter in a continuous-time domain.

    \[U_{PID}\left(z\right)=\left(K_p+\dfrac{K_iT_s}{1-z^{-1}}+\dfrac{K_d(1-e^{-T_s/T_d})(1-z^{-1})}{T_s(1-e^{-T_s/T_d}z^{-1})}\right)E\left(z\right) \label{8.44}\]

    To avoid integration windup of PID controllers, an anti-windup logic similar to the continuous-time one can be employed, as below.

    \[u_{PID}\left(t\right)=K_pe\left(k\right)+{g_iK}_iT_s\sum^k_{n=0}{e(k)}+K_d\dfrac{e\left(k\right)-e(k-1)}{T_s} \label{8.45}\]

    where \(g_i\) is a gain coefficient used to enable or disable the integration action and is defined below.

    \[\ g_i=\left\{ \begin{array}{cc} 0, & if\ u_{PID}\left(k\right)\ge l_{max}\ \&\ e(k)>0\ or\ u_{PID}\left(k\right)\le l_{min}\ \&\ e(k)<0 \\ 1, & else \ \end{array} \right. \label{8.46}\]

    Figure 8.11 shows a Simulink implementation of discrete-time PID control with anti-windup capability, with all parameters defined before except for \(a=e^{-T_s/T_d}\), \(d=\) \((1-a)/T_s\), and \(K=1\).

    A Simulink block diagram showing the implementation of discrete-time anti-windup PID controller that stops positive integration when the output is saturated above and negative integration when the output is saturated below.
    Figure 8.11: Discrete-time Simulink implementation of anti-windup PID controller.

    Now, we are ready to discuss the dual-PID control architecture for the mini-Segway system. Two PID controllers are used to stabilize the mini-Segway pendulum and follow the given cart speed reference (forward and backward), respectively. The mini-Segway turning motion is controlled in an open-loop; see Figure 8.12 for its control system architecture. The mini-Segway turning motion can also be controlled in a closed-loop by using PID controllers to make two wheels (left and right) follow their reference speeds. In this case, the left and right wheel speeds are controlled independently. If the reference speeds for both wheels are the same, the mini-Segway will move forward or backward. If the left and right wheel reference speeds are different, the mini-Segway will turn. This strategy allows the mini-Segway turning while driving forward or backward. The three-wheel cart system discussed in Chapter 9 adopts this approach.

    Figure 8.12 illustrates the entire architecture of the dual-PID control system. It shows all associated hardware including two DC motors, two wheel-speed encoders, and the MPU 6050 three-axis accelerometers and rate-gyros. The cart linear speed (\({\dot{x}}_{cart}\)) is calculated by converting the hall-effect sensor pulse-trains of both left and right wheels into the numbers of counts for the left and right encoders over the given sample period \(T_s\), then into two-wheel angular speed signals, and in turn into the cart speed signal. It multiplies the wheel effective radius by the averaged wheel speed, assuming that there is no wheel slip between wheel and road surface. (See Section 6.2 for the detailed speed calculation formula.) The pendulum angle (\(θ_p\)) is calculated based upon the sensor fusion technology discussed in Section 6.5; it utilizes both three-axis accelerometer and rate-gyro signals provided by the MPU 6050, a MEMS sensor. Both PID controller analog outputs are converted into PWM signals in the Arduino MKR motor carrier board. The two H-bridge DC motor drive circuits in the Arduino MKR motor carrier board are used to drive both left and right DC motors mounted on the mini-Segway.

    A block diagram showing the architecture of dual-PID control strategy for the mini-Segway with one stabilizing the mini-Segway pendulum and other controlling the mini-Segway speed.
    Figure 8.12: Dual-PID control architecture of a mini-Segway.

    The mini-Segway pitch angle (\(θ_p\)) and cart speed (\({\dot{x}}_{cart}\)) dynamics are NOT independent. Thus, the two PID controllers for these two coupled dynamic subsystems will influence each other, even though they are implemented in two independent control loops. Double integration operations in two PID controllers could lead to computational integration overflow, also called windup (Figure 8.12). To avoid this, one of the PID integration gains must be set to zero. Comparing the mini-Segway pendulum angle (\(θ_p\)) dynamics with the cart speed (\({\dot{x}}_{cart}\)) dynamics, the pendulum dynamics are much faster; they require fast reaction to stabilize the inversed pendulum. As a result, the PID integration gain of the pendulum angle (\(θ_p\)) will not help much to improve the pendulum stability. In fact, in this case, the derivative gain is critical. Therefore, the PID integration gain for stabilizing pendulum angle (\(θ_p\)) is set to zero.

    Control gains of two PID controllers can be tuned iteratively. Thus, we fix the first PID controller gains and tune the other one. Then we fix the tuned gains of the second PID controller and tune the first PID controller gains. This process can be repeated iteratively until we achieve satisfactory performance. The individual PID gain tuning method is introduced in Section 3.4 with the direct-tuning method, the Ziegler-Nichols step response and ultimate sensitivity methods. The detailed tuning method for Ziegler-Nichols methods can also be found in references [3] and [16]. PID gain tuning based upon the machine learning method [17] can also be used for gain tuning. If two independent PID controllers are used for controlling two individual motors (actuators), the PID control gain tuning will be even more challenge. This is one of the drawbacks mentioned earlier.

    Section Summary

    With the mini-Segway nonlinear model developed, this section proposes an architecture of using two independent PID controllers [3], [4], [5]. One PID controller is used to stabilize the mini-Segway pendulum position and maintain it in the upright position. The other controls the mini-Segway’s forward and backward motions in cart \(x\) direction. The coupling dynamics (Problems P8.2 and P8.4) of pendulum angular displacement, forward/backward, and turning motions are not considered. To ensure that the two integrators of these two PID controllers do not fight each other, which could lead to unbounded integration values, we set the integration gain of the PID controller for stabilizing the mini-Segway pendulum at the upright position to zero. The effect of integration action for stabilizing the pendulum position is moderate because of the integration operation’s slow action.

    Section Keywords

    Practice Problems

    1. For PID control laws of continuous- and discrete-time, which method is preferred for implementation into a microcontroller for real-time control, continuous or discrete?
    2. Assume you want to reduce the noise amplification of a derivative operation in a PID controller. For a physical system with its highest frequency component at \(f_h\), what of the following is a proper low-pass filter corner frequency? Select the correct answer.
      1. \(f_h\)
      2. \(2f_h\)
      3. \({6f}_h\)
    3. For the anti-windup logic used in the PID controller shown in Figure 8.10, select from the following list the three cases that the integration action is allowed.
      1. If the PID control output \(u_{PID}\left(t\right)\) is saturated from above and the PID input error \(e(t)\) is negative.
      2. If the PID control output \(u_{PID}\left(t\right)\) is saturated from below and the PID input error \(e(t)\) is positive.
      3. If the PID control output \(u_{PID}\left(t\right)\) is saturated from above and the PID input error \(e(t)\) is positive.
      4. If the PID control output \(u_{PID}\left(t\right)\) is between the lower saturation limit \(l_{min}\) and upper saturation limit \(l_{max}\).
    4. For the dual-PID control architecture for the mini-Segway, select from the following list the correct control targets for the two PID controllers.
    5. Mini-Segway pendulum angle and cart speed.
    6. Mini-Segway pendulum angle and turning speed.
    7. Mini-Segway cart and turning speeds.

    This page titled 8.2: Model-Free Dual-PID Mini-Segway Control System Architecture was last modified on Thu, 23 Jul 2026 03:57:16 GMT and is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Guoming Zhu (Co-DREAM OER) .