Hybrid Fuzzy Logic and Adaptive LQR Controller for Swing-up , Positioning and Stabilization of Inverted Pendulum

This paper presents the design and practical implementation of a hybrid fuzzy logic and adaptive linear–quadratic controller (LQR) for a real inverted short pendulum system. We present an extended swing-up approach using fuzzy controller and then discuss an adaptive LQR realization which takes into account nonlinearities while passing the transient process to the upward position of the short pendulum which is mounted on a cart. So long as the cart’s configuration space is restricted by boundary conditions the controller also solves the positioning task, during which the cart returns to the centre of cart’s configuration space. We also discuss the practical realization of such controller logic, embedded into 32-bit microcontroller with the algorithm reaction of 1 ms. DOI: http://dx.doi.org/10.5755/j01.eee.20.3.6675


I. INTRODUCTION
The inverted pendulum system presents possibilities for investigation of the nonlinear system.Recently, various approaches show that such system is a good platform for testing the behaviour of optimal and fuzzy control algorithms, but recent experiments deal with relatively long pendulums, i.e. 35 cm in [1], 50 cm in [2], and of similar size in [3].In this work we pick a short pendulum of the length 11 cm, explore a swing up and stabilization strategy and present a specific design for the high performance microcontroller system.So long as the length of pendulum is inversely proportional to the required sensitivity and reaction of the control system, we assumed it is appropriate to pick a relatively short pendulum and test how the control strategies we developed would behave.
Our swing up strategy incorporates an additional constraint on the cart's position and pendulum's angular speed as compared with work in [1].We adopt a similar multi-swing fuzzy logic approach as in [2], but with inequalities which are more suitable for our microprocessor workload.And finally, we present a novel approach for an extended angle stabilization of a short pendulum using LQR.We present a linear system of inequalities for the control law of adaptive LQR to be implemented into the embedded architecture.We present this system of inequalities as control regions graphically in the diagram.
Our pendulum system (Fig. 1) has the control algorithm reaction of 1 ms.It is able to swing up the pendulum to its upright position using fuzzy logic and is able to position the cart to the centre and stabilize the pendulum if external disturbances are present [4] using adaptive LQR regulator.

II. THE PARTS OF INVERTED PENDULUM SYSTEM
Figure 1 shows the inverted pendulum system picture.Its structural layout is described in Fig. 2. The cart's O (Fig. 2) configuration space covers the area between left and right side borders (guarded by safety contacts I).The incremental rotary encoder G (Fig. 2) (Autonics E40S6-2500-3-T-24) senses pendulum's angle, and the other encoder E (Yumo E6A2-CW3C) helps to localize the cart's position.Accelerometer H (Fig. 2) ADXL 322 detects any external disturbances and enables monitoring of how they affect the stabilization and position algorithm.H-bridge driver B (Fig. 2) controls DC motor's F Д-5ТР (nominal voltage UN = 26 V; torque MN = 0.0009 kg•m; electrical power P = 3.8 W; speed ΩN = 4100 rpm) control voltage using pulse width modulation (PWM) of 20 kHz control signal.We collected and soldered H-bridge specifically for this project.Phoenix Contact power supply unit A (Fig. 2) MINI-PS-100-240AC/24DC/4 provides 24 V DC voltage for H-bridge and DC motor.Microcontroller D (Fig. 2) mbed NXP LPC1769 uses the current sensor C ACS712 05B to monitor the energy consumption of the mechanical cart system.A control switch K (Fig. 2) sets whether system should go into automatic control mode, or we should have a manual control option.When set to manual control, we are able to control the voltage of the DC motor by potentiometer J (Fig. 2).The calibration switch starts the auto-calibration of the cart to detect the left-most and right-most possible positions of the cart, we have the desired centre position of the cart.Figure 3 describes the physical layout distances, present in our system.Here the length of the pendulum (11 cm) is relatively small so higher reaction of the cart is required (performance of 1 ms has been achieved), but this allows smaller overshooting of the cart in the respect of the centre of the configuration space.
The left side of the H-bridge is present in Fig. 4.  The right side of the H-Bridge has similar wiring diagram except that microprocessor's wires are connected so that Table I relationships are fulfilled.
As we can see, there is no short circuit condition and the only condition to care of was an abrupt stop condition, which induced currents less than 10 A during the experiments.

III. CONTROL STRATEGY
There are two main parts for the whole automatic control workflow: swing-up and stabilization.We get positioning effect as an artefact by using additional state space variables and the fuzzy rules.
The fuzzy logic has several independent regions in the configuration space of the pendulum as seen in Fig. 5 and its rules are dependent on the specific dynamical state of the pendulum, specifically on its angular velocity.
The swing-up procedure uses regions A1→D and A2←D and follows the bang-bang principle (DC motor voltage is set to either +24 V or -24 V) as in Fig. 5.If pendulum's angular velocity -12.5 rad/s < ω < 12.5 rad/s and the pendulum is moving from A1 to D, then 24 V is applied, else, if from A2 to D, then -24 V is applied.There is one more constraint in the swing-up fuzzy logic.If the cart's is located more than 1.1 cm from the centre of its configuration space, then the control command to the right is forbidden.Similar rule applies for the cart's motion direction to the left.
After the swing-up, the next active operation region is from B1 to B2 (Fig. 5), where we have hybrid fuzzy logic and LQR control.The differential equations for a rotary pendulum on cart were: where M is the cart's mass  The values of constants and coefficients of the system were evaluated from empirical tests, and we assumed that both friction coefficients related linearly to the velocity variables, which was a rough approximation when small velocity values were present.So long as inductance of DC motor was small compared to other weights in (3), we eliminated it from further calculations.
Then we show the state space matrix equations, after approximating sine of  with  and cosine of  with 1, as: , where x  is velocity of the cart, x  is its acceleration,   is angular velocity of the pendulum, respectively,   its angular acceleration, denominator of state space matrices elements, and C is measurement matrix represented by an identity matrix of the size 4.The state space matrix D is represented by zero elements so we do not show it here.We selected control law matrices of LQR regulator as: where R is a matrix controlling the performance of the regulator, xweight = 5000, vweight = 50, θweight = 5000 and ωweight = 60 are, respectively, the relative-weight coefficients for state space variables of the cart's position and its velocity, the pendulum's angle and its angular velocity.We tuned the value of R considering that the module of the control voltage cannot exceed Umax = 24 V during the experiments.After solving state space system using infinitehorizon Riccati equation where , we get the coefficients of the control law U KX   as
We have to mention that the state space system (4)-(7) has nonlinearities removed by local linearization of trigonometric functions approximations, but empirically we found that θ > 9°angles result into overshooting control effects of LQR controller.So we had to adopt hybrid practice and split the LQR activity regions into two main parts, making it adaptive.
In the second region the LQR control inequality is different because the displacement of the cart is restricted by the side borders, so we can allow only the cases, when the pendulum is moving upwards.Then the following inequality must hold (9 24 )and( 1.51 9.4 1.99))or ( 24 9 )and( 1.99 9.4 1.51)).
Equations ( 12) and ( 13) represent a novel approach for adaptive LQR control region and it is shown in Fig. 6.The main benefit of it is that we found a linear relationship between state variables for the control law suitable for embedded development.The constant values of ( 12) and (13) were determined after simulation tests (Table II) when applying the control law matrix coefficients from (10).Δx was the cart's displacement from its configuration space centre, θmin and θmax were the minimum and maximum pendulum angle's displacement from its vertical orientation, and u was control voltage, required after 20 milliseconds passed.There is one more caveat regarding these two LQR control regions.The second region has a different control law 0.86 U KX   applied to it.We needed it to avoid control overshooting in this region, because nonlinearities noticeably affected the state space equations and the controller's behaviour.

IV. EXPERIMENTAL RESULTS
After performing practical experiments the acceptable control law matrix was found as   162.2 111.7 254.6 17.5 .
The difference between (10) and ( 14) occurs because of two main reasons: a) static friction was not a constant during the experiments and it was not taken into account when modeling the friction force; b) the control voltage is limited by Umax while LQR regulator's control law might require higher voltage levels as a result of the solution of (12).
Figure 7 shows the transient curves of pendulum angle and the current consumption in DC motor at the swing-up.
Time period of approximately 4 s was enough for a full swing-up from the pendulum angle 180° to 0° (Fig. 7).Other bang-bang principles might have been applied for timeoptimal control, but those were out of scope of this paper.
The time period, which occurs right after the swing-up and before adaptive LQR stabilization finalizes, is shown in Fig. 8.
We can see that the controller stabilizes the pendulum right after the swing-up in about 0.5 second.Stabilization after external disturbance is shown in Fig. 9.We see that the transition time period after the disturbance, which caused 4°, is approximately 1.9 seconds.
Additionally, the position displacement of the cart was minimized, i.e. the positioning is another result of the adaptive LQR control.
We also demonstrated that similar swing-up, positioning and stabilization occurs when bigger external force is applied to the pendulum.Its result is that it drops the pendulum from its upright position.Then this approach rotates the pendulum downwards and stabilizes it to the upright position from the other side [4].

V. CONCLUSIONS
This research work aimed on the swing-up, positioning and stabilization of inverted short pendulum on a cart.We have developed control strategies to swing-up the pendulum, position the cart and stabilize the pendulum after the swingup finish or disturbances.We successfully demonstrated that the approach produces acceptable automatic control in both small and big disturbances by using hybrid fuzzy logic and adaptive LQR approach.And this approach has high performance with controller's reaction of 1 millisecond.

Fig. 1 .
Fig. 1.The picture of the inverted pendulum system.

Fig. 2 .
Fig.2.The structural layout of inverted pendulum system, where A is power supply, B -H-bridge driver, C -DC current sensor, Dmicrocontroller, E -the encoder of DC motor, F -DC Motor, G -the encoder of the pendulum, H -accelerometer, mounted on a cart, I -cart's safety contacts, J -potentiometer, K -automatic or manual control, Lon/off switch, M -calibration switch.

Fig. 3 .
Fig. 3.The physical distances between different parts of the system.

Fig. 4 .
Fig. 4. The wiring diagram of the left side (output A) of the H-bridge used to control DC motor.Optocouplers A (Fig. 4) assure that overvoltage disturbances of 24V side do not interfere microprocessor signals in wires FWD, REV and ENA.The transistor, of NPN type, B inverts the signal from the optocoupler for MOSFET transistor, of P-ch, C and another MOSFET N-Ch transistor D is used when reverse voltage on the DC motor's (1.5 kg), m is the pendulum's mass (0.059 kg), l is the length of pendulum (0.11 m), in k is the cart's inertia coefficient (0.00082 kg·m 2 /rad), θ is the pendulum's angle, x is the position of the cart, g is free fall acceleration (9.812 m/s 2 ), fr k is the friction coefficient of the cart (22.67 N·s/m), b is the friction coefficient of the pendulum (0.00028 kg·m 2 /(s·rad)), i k is the current coefficient (6 N·s/A), i is DC motor current, i R is DC motor armature resistance (3.7 Ω), i L is DC motor armature inductance (0.003351 H),  c is DC motor constant (-0.06 N·m/A) and u is control voltage supplied to DC motor by Hbridge.

Fig. 5 .
Fig. 5.The fuzzy logic validity regions in the configuration space of the pendulum.

Fig. 7 .
Fig. 7.The swing-up transient processes of DC current i (continuous curve) and the pendulum (dashed curve).

TABLE I .
THE DC MOTOR'S BEHAVIOR AT VARIOUS H-BRIDGE SIGNALS.

TABLE II .
THE SIMULATION RESULTS WITH DIFFERENT INITIAL CONDITIONS.ω