Opening the book…
After completing this section, you will be able to:
- Explain the hardware architecture of the mini-Segway system.
- Describe the Simulink-based software architecture of the mini-Segway system, along with the signal processing of pendulum angle and cart speed.
- Conduct the experimental validation of the dual-PID control strategy.
This section focuses on experimental studies of the dual-PID control strategy. First, however, we discuss the mini-Segway system hardware architecture along with its sensors and actuators used to generate feedback control signals and to drive the mini-Segway, respectively. Next, we introduce the dual-PID real-time control software in MATLAB/Simulink, along with the wheel speed signal processing and motor driving software. Last, we introduce the overall software architecture to clarify that the Simulink model of dual-PID control strategy is running within the host computer. Also, the Arduino MKR 1000 Wi-Fi microcontroller collects the sensor signals and executes the motor drive commands. Now, let’s discuss the hardware architecture of the mini-Segway.
Figure 8.33 shows a mini-Segway picture and its hardware structural diagram. The mini-Segway has two main sensor sources. These include hall-effect encodes mounted on both Segway wheels through gearboxes (see Section 6.2) and MPU 6050 three-axis accelerometer and rate-gyro MEMS sensors mounted on the mini-Segway pendulum. Two DC motors (see Section 5.2) drive the mini-Segway. The two motors spin in the opposite direction when the mini-Segway drives in a straight line. An MKR motor carrier board (see Section 7.4) drives both DC motors utilizing the on-board H-bridge PWM drive circuits (see Section 5.3) and to collect pulse counts for both hall-effect encoders (see Section 6.2) mounted on the motor/wheel axes. The Arduino MKR 1000 Wi-Fi board can be inserted onto the MKR motor shield board directly without manual connection required.
The control hardware of the mini-Segway consists of the Arduino MKR 1000 Wi-Fi microcontroller board. It reads MPU 6050 three-axis acceleration and rotational speed signals though the I2C serial bus and also the wheel rotational speed signals from the Arduino MKR motor carrier board through I2C. Two motor control commands in PWM duty-cycle are also sent through the I2C link. We will discuss later how the Arduino MKR 1000 Wi-Fi microcontroller constantly communicates with it host computer.
Figure 8.34 shows the electronic hardware architecture with key connections. The connections from the MKR motor carrier board to both DC motors and to the Arduino MKR 100 Wi-Fi board are the same as those in Figure 7.30. The MPU 6050 three-axis accelerometer and rate-gyro are the additional hardware in Figure 8.34. In order to connect this sensor board to the Wi-Fi board, a custom interface board (see the left-most picture) was made to slide the interface board into the Wi-Fi board; the MPU 6050 can be plugged into the interface board. The interface and MPU 6050 boards are powered by the MKR motor carrier board and communicate with the Wi-Fi board through a I2C bus.
Figure 8.35 shows a top layer Simulink implementation of the mini-Segway real-time control strategy utilizing the dual-PID control architecture. This figure shows six blocks of the control strategies, including a) PID controller for stabilization (pendulum position); b) PID controller for driving; c) Segway protection logics, turning, and motor drives; d) cart speed and displacement calculation; e) pendulum angular position calculation; and f) driving pushing bottoms.
Figure 8.36 shows the details of a Simulink model for a PID controller used to regulate the pendulum position regulation, also part a) in Figure 8.35. Instead of using an anti-windup PID controller, it uses an enabled PID controller to prevent the integration windup and to ensure the integration value is zero at the startup. The PID controller Simulink block is shown in the left graph and the enabled PID controller is shown in the right graph. From the top of the left graph, we can see that the pendulum PID controller is enabled only when the pendulum angle is less than \({45}^{^\circ }\). This prevents the wheel spinning when the mini-Segway is laid down. In addition, the pendulum position control output will be set to zero when the pendulum angle is greater than \({45}^{^\circ }\).
Figure 8.36: PID controller for mini-Segway stabilization (pendulum position).Figure 8.37 shows the details of the Simulink model of a PID controller for cart driving. Instead of using an anti-windup PID controller, it uses an enabled PID controller (yellow block on the right graph) to prevent the integration windup and to ensure the integration value is zero at the startup. In addition, when the pendulum angle is greater than \({45}^{^\circ }\), the cart driving controller output is set to zero.
The PID controller Simulink block diagram is shown on the left graph as a trigged PID controller in Figure 8.37. From the top of the left graph, we can see that the cart driving PID controller is trigged by the zero-crossing detection so that the PID integration will be reset when a zero-crossing is detected. In addition, a low-pass filter with time constant of \(0.2\) second (\(0.6\) second 5% settling time) is used to filter the cart speed feedback signal. Both PID controller gains shown are zeros. We will address the gain turning later during the experimental study.
Next, we will look at part c), the Simulink mini-Segway control diagram for Segway protection logics, turning, and motor drives (the lower-right diagram in Figure 8.35). The pendulum angle stabilization is activated only when the pendulum angle is less than \({45}^{^\circ }\) and the battery voltage is greater than \(10.5\) volts. In addition, it will take eight seconds to activate the pendulum stabilization (see Figure 8.38). These features are mainly for protecting the mini-Segway from activation motor control logics.
From Figure 8.35, we can see that the control signals of the pendulum angle and cart driving PID control outputs are in an opposite direction with the pendulum angle control signal multiplied by negative one, which can be interpreted directly. When the cart is driving in the forward direction with both motors running in the forward direction, the pendulum will lean backward. As a result, the pendulum stabilization requires both motors to run in the backward direction. The turning command is added after both pendulum stabilization and cart driving signals are combined. The positive and negative gains of one are used to ensure both mini-Segway wheels rotate in the opposite direction when the turning command is zero. Both left and right motor blocks are associated with the Simulink Arduino software for motor drives utilizing the Arduino MKR 100 Wi-Fi board and the MKR motor carrier board. The associated software will be executed in the Arduino MKR 1000 Wi-Fi board while the rest of software is running within the host computer.
Figure 8.39 shows part d), the mini-Segway for cart speed and displacement calculations with details. The Simulink block is located in the upper-right corner of Figure 8.35. We can see that the two most left blocks are the software that reads the left and right motor encoders; their outputs are the pulse counts of the left and right wheel hall-effect sensors. The top and bottom block rows convert the pulse counts to the associated wheel linear displacement with a gain \(k=2π\times 0.034/1320\). The cart displacement is the average of the two-wheel linear displacement signals. Note that \(0.034\ (m)\) is the radius of the mini-Segway wheel and \(1320\) is the number of pulses per wheel revolution. The middle two rows in Figure 8.39 calculate the individual wheel linear speed signals. The cart speed is the average of the two-wheel linear speed signals. The two gains in the middle two rows are defined in Section 6.2, with the sample period of \(T_s=0.01\). second. The conversion gain from pulse per second (PS) to revolution per minute (RPM) is \(k=60/1320\), The conversion gain from revolution per minute to linear wheel speed in (m/s) is \(k=2π\times 0.034/60\). Similar to the case of the motor drive blocks in Figure 8.38, the hall-effect sensor pulse counting software in Figure 8.39 is executed within the motor carrier board while the rest of software is running within the host computer.
Figure 8.40 shows the calculation for mini-Segway pendulum displacement (angle), where the control block for part e) of the Simulink simulation is located in the upper-middle part of Figure 8.35. We can see that the left-most block represents the software associated with the MEMS sensor MPU 6050, which provides the three-axis acceleration and rotational angle signals for the mini-Segway pendulum. This part of the software is executed in MPU 6050 and the Arduino MKR 1000 Wi-Fi board. The MPU 6050 block has three output groups: three-axis acceleration signals, three-axis rational angular rates, and the MPU sensor temperature for compensation. The pendulum angular position is calculated based upon the sensor fusion method introduced in Section 6.5 (see the top two rows in Figure 8.40). Pendulum angular speed and MPU 6050 temperature are the direct outputs of the MPU 6050.
Part f) of the mini-Segway software is for the control buttons shown on Figure 8.35. The forward and backward bottoms change the Cart_Sped_Ref value from zero to a calibrated value of \(0.1\ (m/s)\) for forward driving and \(-0.1\ (m/s)\) for backward driving. The left and right bottoms change the Turning_CMD value from zero to a calibrated value of \(25\ (count)\) for left turn and \(-25\ (count)\) for right turn. The maximum count number for motor PWM input is \(255\), and \(25\ (count)\) is equivalent to about \(1.1\ \)(volts), assuming a battery voltage of \(11.5\) volts.
Now, let’s discuss the software structure of the mini-Segway operated under the operational mode of XCP on Wi-Fi. Here, most of the Simulink blocks in the real-time control model shown on Figure 8.35 are executed by the real-time Simulink software in the host computer. Only these blocks associated with left and right motors, left and right encoders, and MPU 6050 are running on the mini-Segway hardware. The motor control commands are sent from the real-time Simulink software to the Arduino MKR 100 board through Wi-Fi communication. They are then sent to the MKR motor carrier board through the I2C serial link within the mini-Segway. Meanwhile, the sampled left and right encoder counts and the MPU 6050 signals are sent to the Simulink software through the Wi-Fi communication from Arduino MKR 1000 Wi-Fi to the host computer. The mini-Segway cart speed and pendulum position are processed for feedback control in the host computer. Figure 8.41 demonstrates these relationships.
The mini-Segway control software is implemented in MATLAB/Simulink. See Figure 8.35 for Simulink implementation details, along with the detailed subsystem diagrams discussed above. We will now conduct two experimental studies: pendulum stabilization and cart driving.
The first study is for pendulum stabilization. After carefully tuning the stabilization PID control gains; see the Simulink control diagram shown in Figure 8.36 for detail. Table 8.3 lists the tuned gains. The integral gain is intentionally set to zero to avoid integration windup. Only one of the PID integral gains for pendulum stabilization and cart driving PID controllers can be nonzero; see Section 8.5 for details.
| Proportional gain | Integral gain | Derivative gain |
|---|---|---|
| \(12\) | \(0\) | \(0.8\) |
These PID proportional and derivative control gains are much larger than these used in the simulation; see Table 8.2. Note that the control input to the Simulink DC-motor block has a range between \(-255\) and \(255\) (PWM duty-cycle count with \(\pm 255\) corresponding to \(\pm 100\%\) duty-cycle) whereas in the simulation, the input to the DC motor in Section 8.5 is armature voltage of \(\pm 12\) volts. Assuming that the battery voltage is 11.5 volts, there is a conversion ratio of \(k_{cv}=255/11.5=22.17\). In addition, the angular displacement unit of implemented experimental software is in degree and radius for simulations. There is a conversion ratio of \(k_{dr}=π/180=0.01745\). With a combined conversion ratio of \(k_{cv}k_{dr}=0.387\), the tuned proportional gain [GrindEQ__12_] is close to converted simulation gain of \(3/0.387=7.75\), which is about one and half times larger than the simulation one. The derivative gain is about seven times smaller, which could be due to the unconsidered nonlinearity (such as Coulomb friction) and sensor noises in the actual system, which prevents using high derivative gain for the pendulum stabilization.
Figure 8.42 shows the stabilization control responses. The left column of Figure 8.42 shows the mini-Segway cart speed, speed control count, and pendulum position (angle) from top to bottom. The right column shows the mini-Segway pendulum position control count, and left and right motor total control counts from top to bottom. This is a stabilization experiment, so the reference cart speed is always zero. From the bottom-left pendulum position plot, the mini-Segway pendulum was lifted to the vertical stabilization slightly before the 13th second. When the pendulum angle \(θ_p\) is reduced to \({45}^{^\circ }\), the Segway control is activated. It takes about two seconds (from 12.8 to 14.8 second) for the mini-Segway to stabilize and remain in the upright position with \(θ_p\) close to zero. However, after the pendulum angle is stabilized, the cart remains moving for an additional two seconds until the 17th second. This can be observed from the cart speed plot in the top-left of Figure 8.42. After the 17th second, both the cart speed and pendulum position remain close to zero. The associated motor control for both left and right motor control counts are close to zero (see the middle and bottom plots on the right of Figure 8.42).
The second study is for simultaneous cart driving and pendulum stabilization. After careful tuning, the cart driving PID control gains with the same stabilization gains; see the Simulink control diagram in Figure 8.37. The tuned cart driving gains are listed in Table 8.4. Normally an iterative tuning process is required due to coupled dynamics. In addition, the derivative gain has an opposite sign to proportional and integral gains for improved performance; see the result of dual-PID simulation results in Section 8.5.
| Proportional gain | Integral gain | Derivative gain |
|---|---|---|
| \(320\) | \(10\) | \(-2\) |
The PID control gains seen in Table 8.4 are much larger than those used in the simulation study (see Table 8.2) in Section 8.5, where the equivalent proportional gain is 300/\(22.17=13.53\). After considering the conversion ratio \(k_{cv}\), the tuned proportional and integral gains are about four and half times greater than the simulation ones; and derivative gain is about the same as the simulation one. Similarly, this could be due to the unconsidered nonlinearity (such as Coulomb friction), modeling error, and PWM conversion error (especially at low duty-cycle level) in the actual system.
Figure 8.43 shows the cart driving control responses with stabilization of pendulum position. The left column shows the mini-Segway cart speed, speed control count, and pendulum position (angle) from top to bottom. The right column shows the mini-Segway pendulum position control count, left and right motor total control counts from top to bottom. This is a stabilization and cart driving experiment. From the bottom-left pendulum position plot, the mini-Segway pendulum was lifted to the vertical stabilization slightly before the 12th second. When the pendulum angle \(θ_p\) is reduced to \({45}^{^\circ }\) (marked by the red vertical line), the segway control is activated. It takes about one second (from 13 to 14 second) for the mini-Segway to stabilize and remain in the upright position with \(θ_p\) close to zero with the cart speed slightly above zero. The cart reference speed changes from zero to \(0.1\ (m/s)\ \)at around 24.5th second, from \(0.1\ (m/s)\) to zero at around 25.5th second, from zero to \(0.1\ (m/s)\ \)at around 26.5th second, from \(0.1\ (m/s)\) to zero at around 27.2nd second, from zero to \(0.1\ (m/s)\ \)at around 28.0th second, from \(0.1\ (m/s)\) to zero at around 29.0th second, and from zero to \(0.1\ (m/s)\ \)at around 29.8th second, from \(0.1\ (m/s)\) to zero at around 31.8th second. For all four cart-speed activations, the cart speed control count increases immediately. The pendulum angle control count oscillates to maintain the pendulum angle at zero (upright position). After a few oscillations, cart speed reaches its reference speed of \(0.1\ (m/s)\). After the 32nd second, with reference cart speed equal to zero, both cart speed and pendulum position remains close to zero after some correctional actions. The associated motor controls for both left and right motor control counts are close to zero after around 33.5th second; see the middle and bottom plots on the right of Figure 8.43.
As a summary, the tuned gains for simulation and experimental studies could be quite different due to system nonlinearity, sensor noise, modeling error, and PWM approximation at a low duty-cycle level. The interactions between stabilization and cart motion control for experiments is heavier than that for the simulation study. This could be due to the unmodeled nonlinear friction in the linear simulation study.
Section Summary
This section validates the dual-PID mini-Segway control strategy through experiments. First, it discusses the mini-Segway system hardware architecture, along with its sensors and actuators used to generate feedback signals and drive the mini-Segway motors, respectively. Next, the section introduces the dual-PID real-time control software in MATLAB/Simulink, along with the wheel speed signal processing and motor driving software. Reminder that the pendulum angle is calculated by utilizing both accelerometer and rate-gyro signals from MPU 6050. The wheel speed is calculated based upon the hall-effect sensors mounted on the wheel axes. The section then introduces the overall software architecture in Simulink. The Simulink model of the dual-PID control strategy runs within the host computer. The Arduino MKR 1000 Wi-Fi microcontroller collects the sensor signals and executes the motor drive commands on the mini-Segway, where communication between the host computer and the Wi-Fi microcontroller is through the Wi-Fi at a frequency of 100 Hz. Last, the section conducts an experimental study of the mini-Segway to validate the mini-Segway dual-PID control strategy.
Section Keywords
Practice Problems
- Select all correct answers below to complete the sentence: The enabled PID controller (see Figure 8.36) used for pendulum stabilization is due to the following reasons.
- Enable PID control as needed.
- Protect the mini-Segway so that the PID controller is activated only when the pendulum angle is less than \({45}^{^\circ }\).
- Prevent integration windup.
- Complete the sentence by selecting correct answer below. The MPU 6050 sensor signals (three-axis acceleration and rotational speed signals) are communicated with Arduino MKR 1000 Wi-Fi through:
- Wi-Fi communication.
- SPI link.
- I2C bus link.
- The large difference between simulation and experimental students of the tuned PID gains for pendulum position and cart driving control is due to the following reasons. Select all associated reasons from the list below.
- The controller output unit difference (armature voltage vs. PWM duty-cycle count).
- Mini-Segway nonlinearity such as Coulomb friction.
- Modeling errors of DC-motor and pendulum dynamics (assumption of a uniform bar).
- Consider the difference in the control input units (armature voltage for simulation model and duty-cycle count for experimental study). When implement the designed model-based controller, is it required to have a correction factor for the model-based controller? If so, what is the factor?
This page titled 8.7: Experimental Study of the Mini-Segway Model-Free Control was last modified on Mon, 24 Aug 2026 21:10:33 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.