Opening the book…
After completing this lab section, you will be able to:
- Tune the pitch angle PID controller gains for the mini-Segway hardware.
- Tune the cart speed PID controller gains for the mini-Segway hardware.
This lab session provides the real-time Simulink mini-Segway control model so that the PID control gains can be tuned with the mini-Segway hardware in feedback loops. The locations of the parameters for two PID controllers in the real-time Simulink control model are marked with two red boxes in Figure B.89. These two PID controller parameters were tuned for the mathematical Simulink model in Lab B.7. Now they can be used as the initial gains for the PID gain tuning process for the mini-Segway hardware.
Before beginning the tuning process, visually inspect your mini-Segway to check if the following hardware connections and battery location are correct:
- All pins and cables of the boards are connected properly without any loose or distort connections.
- The battery is connected to the Arduino through the interconnector of the mini-Segway.
- The battery was placed close to the mass center of the mini-Segway without obvious deflection.
Each time, when you tune the parameters, you need to complete the following two steps:
- Compile and upload the Simulink model software to the mini-Segway hardware (MKR 1000 Wi-Fi board) in the Wi-Fi mode. Select the same router for the host computer with the USB cable connected from the host computer to the mini-Segway. While compiling and uploading the software, the mini-Segway should be laid down to ensure that the wheels not spinning during the process (the mini-Segway will be active when pitch angle is less than 45 degrees).
- After successfully uploading the Simulink model into the mini-Segway, disconnect the USB cable. Then lift and hold the mini-Segway in the vertical position, with zero pitch angle, to activate software.
Pitch Angle PID Controller Gain Tuning
Use the following steps to tune pitch angle PID gains (P and D gains). The I gain of the pitch angle PID controller is set to zero to avoid integration value windup.
- At this point, when tuning the pitch angle PID controller gains, all cart speed PID gains are set to zero.
- Set both I and D gains to zero and tune the P gain first. Use the tuned P gain based upon the mini-Segway model from Lab B.7 as the initial P gain.
- If the mini-Segway is unstable with large oscillations, reduce the P gain.
- If the mini-Segway inclines to the forward (or backward) direction and falls down directly, the P gain is too small. Thus, increase the P gain.
Tune the P gain until the mini-Segway has a backward tendency–before the mini-Segway begins to move forward.
- Set the I gain to 1.5 temporarily and keep it unchanged until the end of this section. From Lab B.7, the integration gain of the pitch angle PID controller is set to zero so that the I gain is used only for the cart speed control. However, to make the D gain tuning easy in the next step, temporarily set the I gain to a nonzero value.
- Tune the D gain.
- If the mini-Segway still moves forward, the D gain is still too small; therefore, increase it.
- If the mini-Segway becomes unstable with large oscillations, the D gain is too large; therefore, decrease it.
- Tune the D gain until the mini-Segway can stand stably.
- Reset I gain back to zero.
Cart Speed PID Controller Gain Tuning
Use the following steps to tune cart speed PID gains (P, I, and D gains).
- The reference speed inputs from the push buttons “Forward” and “Backward” need to be set to \(0.1\) and \(-0.1\ \)(m/s).
- Tune the P gain first
- Press the forward button. If the cart does not move, the P gain is too small, and increase it.
- Press the forward button. If the cart moves too fast, the P gain is too large, and decrease it.
- Find a P gain so that the cart can move forward steadily.
- Try the backward button.
- Tune the I gain
The I gain for the cart motion control will also affect the performance of pitch angle motion. Choose an “I” gain so that the mini-Segway can stand and move stably.
- Tune the D gain
- The D gain will not affect the performance much when you press the forward button. However, releasing the button will affect the stability of the mini-Segway.
- If the D gain is too large, the mini-Segway will also oscillate significantly.
- Consider choosing a small D gain while maintaining stability. Also, try to use a negative D gain for improved pitch angle stability during the beginning and ending of driving.
After you finish tuning the PID gains for both pitch angle and cart speed PID controllers, try to make your model as clean and simple as you can so that you can always find any block interested in the model. Because both pitch angle and cart speed motions are coupled, tune both controller gains iteratively for improved performance.
In your report, document the tuning processes for both pitch angle and cart speed PID control-gain tuning processes, along with the suggested iterative tuning process. In addition, present the tuned gains for both PID controllers as well as the associated time responses in the report.
These tuned PID gains can be affected by the ground surface condition (or friction coefficient between wheel and ground) and the set point of cart speed from the “Forward” and “Backward” push buttons. After these PID controller gains are successfully tuned, you can increase the reference speed input from \(0.1\) (m/s) to \(0.2\) \(\ \)(m/s). Find out if both PID controller gains need to be retuned so that the mini-Segway moves stably. In addition, during Lab B.9 show whether these PID gains need to be retuned for different floors (carpet, hard wood, plastic, etc.)
This page titled 11.8: PID Tuning for Mini-Segway Hardware System was last modified on Thu, 23 Jul 2026 05:10:03 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.