Performance Improvement of an NMP Mini Segway Using Sample and Hold Inputs

: Early analytical work showed that it is possible to discretize a continuous-time non-minimum phase (NMP) system using special sample and hold inputs (SHIs) and obtain a discrete-time minimum phase (MP) system with a higher sampling rate than that of conventional zero-order sample and hold. As a result, high-gain discrete-time control law can be used to further improve closed-loop system performance since the resulting discrete-time system is MP. In this paper, this technique is adopted for performance improvement on a mini-Segway (MS), a developed robot equipped with an extremely low-cost microcontroller (Arduino). A dual-loop control tuning method was developed to optimize the overall closed-loop system performance. The system performance improvement is demonstrated by the reduction of the mini-Segway oscillation magnitude under idle conditions. The experimental results show that the low-cost microcontroller can be used for the dual-loop SHI control scheme, and the MS cart displacement oscillation magnitude is signiﬁcantly reduced by more than 65% over the baseline controller. The main contribution of this paper is implementing the proposed sample and hold input (SHI) scheme into an extremely low-cost micro-controller (Arduino) and demonstrating that low-cost microcontrollers can effectively utilize the proposed SHI.


Introduction
Non-minimum phase (NMP) systems refer to systems that have at least one unstable zero located in the open right half plane (in continuous-time domain) or outside of the unit circle (in discrete-time domain).Unstable zeros introduce additional phase lag [1] that limits stabilizing control gain and prevents further performance improvement.One way to avoid the NMP characteristics is to convert the continuous time NMP system to a discrete-time minimum phase (MP) system.Zero-order-hold (ZOH) was considered in [2] with a sufficiently large sampling period.The sampling period that results in a discrete-time MP system is called the feasible sampling period.However, the feasible sampling period of ZOH is often too large to capture the characteristics of a continuous-time system [3]; therefore, the technique using ZOH may not be feasible for control purposes.To find a feasible sampling period smaller than that of ZOH, other approaches were used, including impulse generator function [4], first order hold [5,6], and fraction order hold [7][8][9][10].However, these approaches also have their limitations.
Based on the discrete equivalent (DE) system theory in [11], three sample and hold inputs (SHIs) were proposed and studied in [12], and they are square pulse sample and hold input (SPSHI), forward triangle sample and hold input (FTSHI), and backward triangle sample and hold input (BTSHI).These SHIs have two design parameters: duty cycle (p) and sampling period (δ).These three SHIs are capable of significantly reducing the smallest feasible sampling period over ZOH.Note that the DE system is a continuous-time system with the same state and output variables at sampling time instants as those of the original system, but the zero locations of the DE system depend on the selection of SHI parameters.
Experimental validations were performed in [13], using a Quanser single-invertedpendulum (SIP) system with a prototype controller, to study the capability of the proposed SHIs.It was discovered that by selecting the sampling period and duty cycle within the feasible region, the discrete-time controller with selected SHI is able to improve the closed-loop system performance significantly.Since the controller was implemented into a very sophistic microcontroller, the feasibility of implementing the proposed SHIs into an extremely low-cost microprocessor remains an open question, which is the topic of this paper.To be specific, this paper studies the performance improvement of a mini-Segway (MS) robot with a low-cost microprocessor (Arduino) using a dual-loop control scheme, where the inner-loop continuous-time controller stabilizes the MS system, making it feasible to use the proposed SHI, and the outer-loop discrete-time controller further improves the MS system performance.The MS is a two-wheel self-balanced robot and is a multi-input-multi-output (MIMO) nonlinear system.It is NMP after linearizing about the upright equilibrium point.Due to its under-actuated nature, this platform is widely used for controller design and implementation studies, including PID controllers [14][15][16][17][18][19], fuzzy logic controllers [20][21][22], Fuzzy combined with PID [23], adaptive control [24], and linear quadratic regulation (LQR) control [19,[25][26][27].There are many articles that have investigated complex and strong control methodologies to NMP systems, such as [28].
In this study, the dual-loop control architecture, proposed in [13], was adopted.The continuous-time inner-loop LQR was implemented at a 100 Hz sample rate, and a discretetime outer-loop LQR with the selected SHI was implemented at 5 Hz.The idea is to utilize the inner-loop controller to stabilize the MS system and convert the resulting NMP MS system into a discrete-time MP system with the help of proposed SHIs.Consequently, a high gain outer-loop can be used to further improve closed-loop system performance.It is obvious that the overall system performance is affected by both inner and outer-loop controllers.To study the interaction between two controllers, multiple inner-loop LQR controllers were designed with gains from low to high, and the outer-loop controller was optimized for each designed inner-loop controller.It was found that the inner-loop control gain should be properly chosen to have a decent closed-loop system performance without the outer-loop controller.When the inner-loop control gain is relatively low, the nonlinear Coulomb friction dominates the closed-loop system dynamics, leading to unstable system response, and while the inner-loop control gain is relatively high, the system nonlinearity could result in unwanted high-frequency oscillations.
The main contribution of this paper is two-fold.The first is the feasibility study of implementing the proposed SHI with dual-loop control scheme into an extremely low-cost microcontroller (Arduino) and demonstrating the performance improvement on an NMP MS system; the second is the study of a dual-loop control tuning process to optimize overall closed-loop system performance.An MS robot platform was developed in the lab with a low-cost microcontroller (Arduino).Analytical study shows that the selected SHI is able to reduce the feasible sampling period from 0.75 s (ZOH) to 0.1162 s (a 84.5% reduction), and experimental results show that the average cart oscillation magnitude, mainly caused by the system Coulomb friction, was reduced from 10.94 mm to 3.85 mm (a 64.8% reduction).
The rest of the paper is organized as follows.The SHIs and DE system background are introduced in Section 2, and the MS system is modeled in Section 3. The dual-loop control architecture, along with analytical study, is discussed in Section 4, and Section 5 describes the hardware configuration of the MS system.Section 6 addresses the experimental implementation and dual-loop controller tuning processes, along with experimental results.Concluding remarks are provided in Section 7.

SHI and DE System
A zero-order hold (ZOH) input u z (t) is defined as where δ is the sampling period, and u(t k ) is the sampled value of u(t), which is a continuoustime input over the time interval (t k , t k + δ].Similar to ZOH, three additional SHIs were proposed in [12], and they are square pulse sample and hold input (SPSHI), forward triangle sample and hold input (FTSHI), and backward triangle sample and hold input (BTSHI).Note that the BTSHI feasible region (leading to an MP discrete-time system) as a function of sample period and duty-cycle is normally smaller than the other two, and the feasible regions of FTSHI and SPSHI often cover the BTSHI.As a result, the BTSHI provides less freedom in terms of selecting the sampling period and duty-cycle for the later experiment study; therefore, it is not adopted in this study.According to [3], the FTSHI requires a sampling frequency at least three times faster than SPSHI to generate the signal, and the low-cost microcontroller prevents the implementation of the FTSHI signal.As a result, the FTSHI was not used in this paper.
The SPSHI is defined in the following equation and can also be found in Figure 1, where p ∈ (0, 1] is the duty cycle of the switched input; p and δ are for SPSHI in this case and are referred to as SHI parameters later.
For the continuous time-invariant linear system with u(t) = u s (t) and the SPSHI defined in Equation (2), the system becomes Systems ( 3) and ( 4) are discrete-equivalent (DE) [12] if the state variables of both systems are equivalent at sampling time instants t k (k = 0, 1, 2, ...).For the rest of the paper, Equation ( 4) is called the DE system of (3).The DE system matrix with SPSHI has Ā = A and C = C, but the system input matrices B and B are Note that for the DE system, the system matrices Ā = A and C = C. Matrix B depends on the SHI parameter selections.When p = 1, matrix B in SPSHI becomes B, and the SPSHI becomes ZOH.Therefore, ZOH is a special case of SPSHI.In order to keep the input energy unchanged, the peak magnitude of SPSHI is scaled by (1/p); see Equation (2).When p < 1, the DE system input matrix B is different from the original input matrix B, so the zero locations of the DE system in (4) can be different from those of the original system in (3).

DE and DT Systems
The continuous-time DE system in (4) can be converted into a discrete-time (DT) system by sampling at time instants t k (k = 0, 1, 2, ...) below.
where A d = e δA , C d = C, and matrix B for SPSHI is

Mini-Segway System Model
The mini-Segway (MS) is a two-wheel self-balanced robot.It utilizes a low-cost microcontroller (Arduino), two motor-wheel sets, and a cart body.The free body diagram of the MS system is shown in Figure 2, where two motors provide the torques (τ L and τ R ) to prevent the cart body from falling and also to move the cart forward, backward, left, and right; x cart is the cart displacement in x cart direction; see Figure 2; and θ p and φ are the cart body pitch angle and cart yaw angle, respectively.

Mini-Segway Robot Dynamic Equation
The MS equations of motion are shown in (8) below.
where u L and u R are the left and right motor applied voltages, and they are considered as system control inputs.The MS system is balanced at its equilibrium point, the upright position (θ p = 0).Small angle approximations of nonlinear functions are used as below: The linearized MS state-space model is described in (10), and the state vector is where The MS system parameters are shown in Table 1.
The MS system is open-loop unstable due to a positive pole located at s = 9.5715.In order to further improve the system performance experimentally, the plant dynamics shall be stabilized before the SHI scheme can be applied since the proposed SHI requires a stable plant.

Dual-Loop Control Architecture 4.1. Inner-Loop Controller Design
A dual-loop control architecture proposed in [13] is used for the MS system, where the inner-loop controller stabilizes the MS system, and the outer-loop controller with SHI further improves MS system performance.For this study, as shown in the dashed region of Figure 3, the inner-loop utilizes a continuous-time LQR (referred as LQR c ) implemented at 100 Hz.For the inner-loop continuous-time stabilizing controller, the cost function for LQR c is

𝑥
where Q c ≥ 0 and R c > 0 are the weighting matrices.The inner-loop control output v in Figure 3 is in the form of v = −K c x, where K c = R −1 c B T P c , and P c is the stabilizing solution of the following Ricatti equation: For demonstration purpose, an initial set of LQR c weighting matrices Q ci and R ci was chosen as Q ci = diag[100 0.1 300 0.1 10 0.01] and R ci = diag[1 1] through an ad-hoc tuning process, and the corresponding control gain is With the initial LQR c , the MS system is stabilized, and the resulting closed-loop system remains NMP.

SHI Parameter Selection
For δ ∈ (0, 1] and p ∈ (0, 1], the zero locations of the K ci stabilized MS system can be calculated, and the SHI feasible region is shown with the shaded area in Figure 4, which is the common area formed by the sampling period and duty cycle resulting in an MP DT system for the closed-loop system with the inner-loop controller.Note that the feasible region was calculated by an exhaustive search of δ and p that resulted in an MP system.The black horizontal line on the top of Figure 4 represents the feasible sampling periods of ZOH, a special case of SPSHI with p = 1 (100% duty-cycle).The smallest feasible sampling period of ZOH is as large as 0.75 s.This sampling period can be reduced down to 0.1184 s using the SPSHI with an extremely small duty cycle.For example, if a sampling period of 0.2 s is selected, a wide range of duty cycles can be chosen between 0 and 0.6.Note that small sampling period is very important for improving closed-loop system performance using the outer-loop controller.
The normalized system bandwidths are calculated, and they are 1.3 Hz and 33.9 Hz for cart displacement and cart pitch angle, respectively.In order to ensure that the outer-loop controller sample frequency to is adequate to cover system dynamics for both outputs, the required sampling frequency is at least two times faster than the system dynamics [3], that is, 67.8 Hz for the outer-loop controller.In this case, it is impossible to have the outer-loop controller cover system dynamics for both outputs.Consequently, for the same reason, only the cart displacement output is considered since it requires a controller with the lowest sample frequency of 2.6 Hz [3].
Therefore, a small sampling period within the feasible region shown in Figure 4 is preferred.Due to the experimental validation result in [13], a small duty cycle leads to better performance.As a result, for the SPSHI, the outer-loop sampling period is chosen to be δ = 0.2 s, marked with the dashed line in Figure 4, and the implementation duty cycle is chosen as p = 0.2 (20% duty-cycle).

Outer-Loop Design
Since the open-loop MS system is NMP, high gain control could destabilize the system.With the SHI parameters selected in the previous section, it is able to convert the continuoustime NMP MS system to a discrete-time MP system.In order to improve the stabilized MS system performance, the outer-loop controller, a discrete-time LQR (referred as LQR d ) with the SPSHI, was used (see Figure 3), and LQR d provides additional control effort for further performance improvement.The LQR d cost function is defined below.
where ω SH I (k) is the outer-loop control output (see Figure 3).Note that the selection of LQR d weighting matrices (Q d and R d ) is critical for this study, where an adequate control effort should be guaranteed while maintaining both actuators within their saturated input voltage of ±12 V.

Experimental Hardware
The target MS system is built with three main component groups: sensors, microcontrollers, and actuators.

Sensors
In order to balance the MS system about its upright equilibrium point, the measurement signals of the cart body pitch angle, pitch angular velocity, individual wheel displacement, and velocity are required.
Cart body pitch angle and velocity: An MPU-6050 sensor from IvenSense Inc. is used for reading cart body angular information.It contains a MEMS (microelectromechanical system) gyroscope and a MEMS accelerometer in a single chip.The gyroscope is a sensor that measures the angular velocity in roll, pitch, and yaw directions, and the accelerometer measures gravitational and motion accelerations in X, Y, and Z directions.After disabling the sleep mode of the chip in Simulink, the gyroscope and accelerometer readings are sent to the microcontroller via the Arduino I 2 C bus.The cart body pitch angular velocity is obtained directly from the gyroscope raw data.Theoretically, integrating the angular velocity yields the pitch angle, but the sensor noise and bias cause the integrated angle signal drift.Note that the pitch angle can also be obtained from the arc-tangent value of the X and Z direction gravitational accelerations from the accelerometer signals; however, the sensor noise and external forces could also affect its accuracy easily.Hence, a complementary filter, developed in [29], is used to have an accurate pitch angle signal; see the complementary filter in Figure 5.To compensate the gyroscope drift with the accelerator reading, it applies a low-pass filter and a high-pass filter to accelerometer and gyroscope signals, respectively.For the MS used in this paper, β = 0.98 was used for the filter.

Wheel displacement and velocity:
The MS displacement is measured with two halleffect rotary encoders mounted on the two motors.The motor encoders output digital signals of both motor shaft positions with a resolution of 1320 samples per revolution.The encoder readings can be converted into cart displacement and velocity based on gear ratio and wheel radius.

Microcontroller
For the purpose of balancing the MS system, the microcontroller speed has to be adequate for sampling sensor signals, communicating with the host computer via Wi-Fi, and generating control commands for both motors.For this study, the control algorithm was developed in MATLAB/Simulink, which requires additional throughput from the microcontroller to handle the communication between the Arduino microcontroller and real-time Simullink via Wi-Fi; see Figure 6 below.An Arduino MKR 1000 Wi-Fi is selected for this study due to its WiFi capability.It uses the microcontroller with a clock speed of 48 MHz that is capable of handling the sampling frequency of 100 Hz.The communication between the host computer and MS system could have certain delay via Wi-Fi connection.However, with a private Wi-Fi router, the experimental data were sent to the host computer with barely no delay at a constant sampling period.

Actuators
Two 12 V DC motors with a 1:4 gear ratio are used, where the motor peak speed is 333 RPM and peak output power is 4.8 W. The motor torque parameter K τ is 0.23 Nm/A.The MKR motor carrier is used to drive both motors and process both encoder signals.It has an operating voltage of 5 to 12 V and uses a L298P motor driver.The maximum output current is 2 A/channel, which is lower than the motor maximum current of 6.5 A, meaning that the motors are protected from excess current.

Experimental Set Up
The MS robot (see Figure 7) and its detailed hardware configuration is shown in Figure 6.The rectangular box represents the MS cart.All the sensor signals are fed into the Arduino MKR 1000 and sent to the host computer via Wi-Fi.The host computer then generates control signals in MATLAB/Simulink and sends them back to the microcontroller to drive the motors using the MKR motor shield.

Experimental Implementation 6.1. Inner-Loop LQR Controller Tuning
After the MS system platform was developed, the inner-loop LQR c was implemented to stabilize the MS system.A baseline system performance was established based on Q ci and R ci , which are the initial LQR c weighting matrices.Starting from this baseline controller with the Q ci matrix fixed, the weighting matrix R c was tuned by introducing a gain G Rc such that R c = G Rc R ci .Experiments were conducted with G Rc from 0.6 to 1.2 with an increment of 0.1.The cart displacement and pitch angle are shown in Figure 8a,b.The corresponding control voltage is shown in Figure 8c.2, and the data are plotted in Figure 9. From Figure 8, when G Rc is 0.6, the resulting LQR control gain is high, and the MS system outputs (pitch angle and displacement) oscillate with very high frequencies.When G Rc = 0.7 with a reduced control gain, the cart oscillation magnitude is reduced but is still unstable.As a result, these two G Rc values are not feasible since they do not result in feasible LQR c controllers for stabilization purposes.For G Rc = 0.8, the closed-loop system takes about 5 s to stabilize; as a result, the closed-loop MS system transits from unstable with G Rc = 0.7 to stable with G Rc = 0.8 (as shown in Figure 9).The closed-loop system performance is further improved with G Rc = 0.9, and the cart is also stabilized with G Rc = 1.0 but with an increased oscillation magnitude.When G Rc reaches 1.1, the closedloop system has an unbounded oscillation magnitude for cart displacement, indicating an unstable system.The data in Table 2 are plotted in Figure 9.In spite of the undesired range and unstable range, the feasible (stabilizing) G Rc is between 0.8 and 1.0.

Outer-Loop Controller Tuning
For each stabilizing G Rc designed for the inner-loop LQR c , the outer-loop LQR d controller was tuned accordingly to achieve the optimal performance.A "baseline" LQR d was designed first using weighting matrices Q di = diag[100 0.1 80 0.1 10 0.01] and R di = diag[ 1 1].With the feasible LQR c controllers, the dual-loop feasible regions are shown in Figure 10.The smallest feasible sampling periods are 0.1136 s, 0.1162 s, and 0.1184 s for G Rc , equal to 0.8, 0.9, and 1.0, respectively.Since the feasible regions of the  For the purpose of tuning, G Rd was introduced so that R d = G Rd R di , and G Rd ranges from 0.3 to 1.1 with an increment of 0.2 while the Q di matrix is fixed.Smaller G Rd values, such as 0.1 and 0.2, were tested, but the corresponding LQR d gains were too large for the MS system, resulting in an unstable closed-loop MS system.From the system bandwidths of 1.3 Hz for the cart displacement and 33.9 Hz for the body pitch angle, the outer-loop controller sampled at 5 Hz can only cover the cart displacement performance.Therefore, control gain tuning is used to minimize cart oscillation magnitude, and the results for each G Rc are shown in Table 3 below.It is clear that when G Rc = 0.9, the best improvement was achieved, where the oscillation magnitude with inner-loop control only was 12.17 mm and dual-loop was 3.83 mm, a 68.4% improvement.It was 28.3% and 60.0% for G Rc = 0.8 and 1.0, respectively).The outer-loop tuning result for G Rc = 0.9 is shown in Figure 11.
The experimental results in Figure 11 are divided into six segments.Segment I corresponds to the responses with inner-loop controller only from the previous section and used as the baseline controller.Between segments II and VI, G Rd increases from 0.3 to 1.1 with a 0.2 increment.
The dual-loop experimental results with SPSHI in Figure 11a show that the outer-loop LQR d with G Rd = 0.3 reduces the cart displacement magnitude significantly.However, the cart body pitch angle (shown in Figure 11b) is barely affected due to the aforementioned inadequate control sample frequency.From segments II to VI, with increased G Rd , the cart displacement magnitude increases while the SHI control effort decreases.The best cart displacement is boxed in the table.From the trend shown in Figure 12a, when G Rd = 0.3, the cart oscillation magnitude reaches the local minimum; meanwhile, the cart pitch angle is slightly higher than the single loop case.The numerical results show that the inner-loop mean absolute cart displacement amplitude is reduced from 12.17 mm to 3.85 mm with G Rd = 0.3, which is a 68.3% reduction.Note that even though the SPSHI signal in Figure 11d ranges from −1 to 1 V, it does not increase the overall control voltage in Figure 11c.From Figure 12d, it can be observed that dual-loop control does not increase the overall control magnitude.

Conclusions
A mini-Segway (MS) platform was developed for implementing sample and hold input (SHI), converting a non-minimum phase (NMP) continuous-time system into a minimum-phase (MP) discrete-time system, to study the feasibility of using a low-cost microcontroller (Arduino).The inner-loop controller is a continuous-time linear quadratic regulator (LQR) implemented at a 100 Hz sample rate, and the outer-loop discrete-time LQR uses the square pulse sample and hold input (SPSHI) with a 5 Hz sampling rate.The SPSHI is used to convert the stabilized NMP system using the inner-loop LQR to a discrete-time MP system, meaning that the outer-loop high-gain LQR can further improve the performance.It is shown that both inner and outer-loop controllers affect the overall MS system performance.In order to optimize the dual-loop control scheme, a set of feasible inner-loop continuous-time LQRs (linear quadratic regulators) with guaranteed stability was obtained by varying the control weighting, and the best dual-loop controller was found by tuning the discrete outer-loop LQR controller to minimize the cart displacement magnitude.The exhaustive search found that selecting proper inner and outer-loop LQR control weightings is the key to optimizing overall MS system performance.Experiments were conducted to validate the analytical results for the controller tuning processes.With the dual-loop control scheme, the average cart displacement magnitude is reduced by more than 65% using the SPSHI.Note that even though the inner-loop LQR was optimized for the best performance prior to implementing the outer-loop controller, a significant performance improvement can still be achieved by using the outer-loop control with SHI.The main contribution of this paper is to demonstrate that the proposed sample and hold input scheme is capable of significantly improving system performance without utilizing expensive control hardware.Note that the main disadvantage of utilizing SPSHI is that it increases the required actuator size due to a magnified pulsive control signal.It is important to balance the SPSHI duty-cycle and resulting MP system property.There are many existing control approaches dealing with NMP systems using advanced control algorithms, which require relatively expensive control hardware; however, the proposed SHI scheme can be applied to NMP systems without expensive hardware.Future work in this area will be to compare its system performance improvement with other control schemes.

Figure 2 .
Figure 2. Free body diagram of the mini-Segway robot.

Figure 3 .
Figure 3. Dual-loop control architecture for the MS system.

Figure 4 .
Figure 4.The feasible sampling period (in s) of ZOH that results in an MP DT system and the p-δ feasible regions of SPSHI.

Figure 6 .
Figure 6.The MS system hardware configuration.

Figure 8 .
Figure 8.The experimental result for inner-loop LQR c optimization.
closed-loop systems with SPSHI in Figures 4 and 10 are barely changed, the SHI parameter selection remains unchanged at p = 0.2 and δ = 0.2 s.

Figure 10 .
Figure 10.The feasible region of the closed-loop MS system with SPSHI.

Figure 11 .Figure 12 .
Figure 11.Experimental results for Dual-loop Controller with SPSHI.The overall control, u, and SPSHI control ω are shown in Figure 11c,d, respectively.The SPSHI signal is 0 in segment I since only LQR Rc is active.The outer-loop is activated, starting from segment II.As G Rd increases, the SPSHI control decreases and cart displacement magnitude increases.The mean absolute values of the cart displacement, overall control input voltage, and SHI voltage in Figure 11 are summarized in Table4.The data in Table4are plotted in Figure12.

Table 1 .
Mini-Segway parameters.With these parameter values defined in Table1, the MS state-space model becomes

Table 2 .
Mean absolute values of cart displacement and control voltage with inner-loop LQR c only.
Figure 9. LQR c tuning data plot.

Table 3 .
Mean absolute values of outer-loop LQR d .

Table 4 .
The mean absolute values of outer-loop LQR d tuning data.