Opening the book…
After completing this section, you will be able to:
- Create a PID controller in Simulink.
- Tune the pitch angle and cart speed PID controller gains.
Creating Customized PID Controller
This lab session looks at the mini-Segway Simulink model discussed in Section 8.1. We want to complete tuning gains of both stabilization (pitch angle) and driving (cart speed) PID controllers for the mini-Segway model shown in Figure B.82 as SEGWAY PLANT.
This linear model provides seven output ports. They are the control input signal, cart displacement (CarDisplacement), cart speed (CarSpeed), pitch angle (PitchAngle), pitch angular speed (PitchAngleSpeed), cart turning angle (CartTuningAngle), and cart turning speed (CartTuningSpeed). The pitch angle and cart speed are considered as system outputs for feedback control purpose. The control inputs (armature voltages of left \(u_{aL}\) and right \(u_{aR}\) motors) are realized through PWM control (see Section 5.3), where percentages of duty-cycle are actual control inputs.
As discussed in Section 3.4, PID control can deal only with single-input and single-output (SISO) systems. For the mini-Segway system, two PID controllers are used to control mini-Segway pitch angle and cart speed, respectively. A closed-loop PID control system block diagram (see Figure B.83) needs to be designed in Simulink. Here, the output of the PID controller is fed to the mini-Segway system plant as input. The PID controller input is the error between the reference and actual plant output (reference pitch and actual angles).
Refer to the following steps to create two customized PID controllers for pitch angle and cart speed control, respectively. Present both in the lab report.
- Select the correct Simulink blocks from the corresponding Simulink library to realize the PID controller with its time-domain dynamic equation (B.13). For practical applications, a low-pass filter in the form of \(a/(s+a)\) needs to be added ahead of the derivative operation. This reduces its sensitivity to high frequency noise in the error signal \(e(t)\) (Hint: You will need the Sum, Constant, Product, Integrator, and Derivative blocks.) \[u(t)=K_pe(t)+K_i\int^t_0{e\left(τ\right)dτ}+K_d\dfrac{de(t)}{dt} \label{B.13}\]
- The error input of the pitch angle PID controller is the negative pitch angle output of the mini-Segway plant. Because the reference input is zero, pitch angle PID control is to keep the mini-Segway inverted pendulum standing vertically at its neutral position. Once the pitch angle is deviated from zero, both DC motors are energized to turn both wheels in the same direction to pull the mini-Segway pendulum back. This is the pitch angle stabilizing process of the mini-Segway.
- Recall the mini-Segway hardware protection process adopted for both motors and their Motor carrier board in Lab B.4. For each PID controller, a Saturation block is used to limit the control output magnitude to be within \(\pm 255\) counts.
- Connect the pitch angle error to the input port of the PID controller.
- Connect the PID controller output to a Goto block. Its name should be consistent with what is shown in the red box of Figure B.83.
- Figure B.84 shows the reference PID controller model. However, a low-pass filter needs to be added after the block \(\Delta u/\Delta t\) highlighted by the red box (see Step 1). Creating a subsystem makes the PID controller model look simple and clean. (Hint: For the pitch angle controller, \(a\) can be set to \(200\)).
- Use the same logic to build the cart speed PID controller with \(a\ =\ 100\) for the low-pass filter; the cart speed has much slower dynamics than that of pitch angle. Use the step function (Step block in Simulink) as the input reference cart speed. The associated parameter configuration window is shown in Figure B.85.
- Before calculating the error between the plant output (cart speed) and the reference input, we must add a low-pass filter with \(a=5\) in order to filter out the high frequency noise of cart speed signal. The error input of controller is calculated as shown in Figure B.86.
PID Control-Gain Tuning for Pitch Angle Regulation
The pitch angle PID control gains need to be tuned so that the mini-Segway pendulum is stabilized at its upright position. The pitch angle control-gain tuning process follows steps below.
- Double-click the Manual Switch blocks as shown in any red circle in Figure B.82. The switch will then move when you double-click it. Configure the manual switch as shown in Figure B.87 so that the pitch angle PID control gains can be tuned.
- Tune the P gain firstly and keep both the I and D gains at zero. If the P gain is too small, the pitch angle cannot be stabilized because the motor output torque is too small to stabilize. Start from the P gain of 6; increase it until the pitch angle becomes stable. What do you find when you increase the P gain? (Hint: compare the maximum amplitude and oscillation of control signal with a different P gain). Note that the P gain needs to be small but large enough to stabilize the pitch angle motion.
- As discussed in Chapter 8, the pitch angle and mini-Segway speed dynamics are NOT independent. To avoid double integration, the integration (I) gain of the pitch angle PID controller must be set to zero due to its fast dynamics.
- Although the pitch angle becomes stable as the P gain increases, it leads to an increased number of oscillations before it is stabilized. Tuning the D gain can reduce the oscillation level. Start from a D gain of 0.03; increase it till that the pitch angle can be stabilized within 0.1 second.
Document the pitch angle PID control-gain tuning process and the associated resulting gains.
PID Controller for Cart Speed Regulation
Cart speed PID control gains can be tuned for smooth and stable cart speed tracking by using the following steps.
- Double-click the manual switch blocks as shown in the red circle in Figure B.82. The switch will move once you double-click it. Configure the manual switch as shown in Figure B.88 so that the cart speed PID control gains can be tuned under the influence of the pitch angle PID control. Because of the coupling effect of the pitch angle and cart speed motions, tuning the cart speed PID control gains can be challenging.
- Referring to the same logic shown in Section B7.2, tune one PID gain and fix the others. Then fix the tuned gain and tune the others using the PID gain tuning method discussed in Section 3.4.
- For the P gain, start from 100 and increase it till the following two goals are achieved. First, the steady-state error is less than 0.1. Second, the rise time (see Section 3.2) is less than 1 second, with the final P gain as small as possible.
- For the I gain, start from 8. Then increase it until the steady-state error is less than 0.002.
- The D gain is used to predict the tendency of change. An actual physical system has measurement noise. Because a large D gain could lead to instability, select a small D gain for this model. In addition, to help pitch angle stabilization (as discussed early in Section 8.5), a negative derivative gain helps improve performance.
Document both the cart speed PID control-gain tuning process and the resulting gains.
This page titled 11.7: PID Tuning for Mini-Segway Simulink Model was last modified on Thu, 23 Jul 2026 05:09:22 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) .
The book could not be loaded just now.