LQR/PID Controller Design of PLC-based Inverted Pendulum Kaset Sirisantisamrid, Napasool Wongvanich * , Suphan Gulpanich, and Narin Tammarugwattana Abstract—This paper presents an LQR based PID controller to control the inverted pendulum system. The control design employs a control zoning approach whereby the entire pendu- lum system is divided into two regions: a normal pendulum region and the inverted pendulum region where the system is approximately linear close to the upright position. The LQR architecture is used to obtain optimal gains for the PID controller. An algebraic approach is also presented for selection of Q and R matrices. Experimental implementations with a PLC based system show that the computed gains yield the most stable controlled responses compared to the gains chosen through trial and errors. Index Terms—LQR control, PID control, PLC, Inverted Pendulum I. I NTRODUCTION T HE classical Proportional Integral Derivative (PID) controller has remained the most popular industrial controller over the last six decades, despite the enormous hosts of development over the same period [1]. Various PID tuning methods have been developed by a number of re- searchers in the last 40 years. Developments in evolutionary algorithms and particle swarm optimization have led to the application of these methods for PID tuning [2], [3]. Other PID tuning approaches include the direct search algorithms and online optimization based approaches [4], [5]. Although these methods have resulted in the automatic tuning of the PID controllers, they require significant computational loading, and are not suitable for real time applications. The Inverted Pendulum system is an inherently unstable system which is coupled with highly nonlinear dynamics. This feature alone makes the inverted pendulum system a challenging one, and also making it a primitive benchmark for comparing the various control approaches. Several ad- vanced control designs have been presented, including fuzzy logics [6], [7]. These approaches however, require large training sets, and for the case of fuzzy based designs, a large set of rules which further complicates the control for higher order systems. The Linear Quadratic Regulator (LQR) is well known in modern control, and besides the PID has been widely used. The LQR is used to obtain maximal performance of the system by minimizing the cost function relating the states and the control input. Through the use of optimal control theory, LQR is reduced to the solving of Algebraic Riccati Equation (ARE) to obtain the transformation matrix P. The Manuscript received December 05, 2017; revised January 23, 2018 Kaset Sirisantisamrid, Napasool Wongvanich, Suphan Gulpanich and Narin Tammarugwattana are with the Department of Instrumentation and Control Engineering, Faculty of Engineering, King Mongkut’s Institute of Technology Ladkrabang, Bangkok, Thailand. E-mail: (kaset.si@kmitl.ac.th,napasool.wo@kmitl.ac.th,suphan.gu@kmitl.ac.th, narin.ta@kmitl.ac.th). ∗ Corresponding author weight matrices Q and R are usually obtained through trial- and-error and thus sub-optimal. Bryson [8] developed the iterative tuning algorithm for selecting Q and R. Kumar [9] developed an algebraic method of selecting the Q and R matrices for a 3 ×3 system. This work extends this method to a 5 ×5 system for the application of controlling the nonlinear inverted pendulum system. Furthermore, to ensure simplicity of the controller designs, a control-zoning approach is also employed. II. METHODOLOGY A. The LQR controller outline Consider the following linear-time invariant system de- scribed in the state-space form defined: ˙ x = Ax + bu (1a) y = Cx (1b) x ≡ [x 1 ,x 2 ,...,x n ] T , x 0 ≡ x 10 ,...,x n0 T (1c) where x i = x i (t), i=1,...,n is a quantity of state i at time t (s), x is the n × 1 state vector, x 0 is the initial state vector, y is the measurement state vector, u is the input. The main assumption here is that the input u is time- dependent only, and does not depend on x 0 . The conventional Linear Quadratic Regulator (LQR) control seeks an optimal controller u opt that minimizes the cost function: J = ∞ 0 x T Qx + u T Ru dt (2) where Q = Q T is a positive semidefinite matrix, and R is a positive definite matrix. Matrix Q is the matrix penalizing the deviation of the states from the equilibrium, while matrix R is the matrix penalizing the control input size. Through the use of optimal control theory, the optimal gain vector K is given by: K = R −1 B T P (3) where matrix P(n×n) is the solution of the algebraic Riccati Equation defined: A T P + PA + Q - PBR −1 B T P =0 (4) The selection of matrices Q and R have great bearings on the resulting controller being designed. If these matrices are simply chosen as simple diagonal matrices, the quadratic performance index of Equation (2) is thus the weighted integrals of the squared errors of the states and inputs. In practice these matrices are usually chosen arbitrarily first, then undergo manual tuning by trial and errors to achieve the required response. To save time and thus avoid this scenario, the following section gives an algebraic procedure for solving for these matrices explicitly for a fifth order system. Proceedings of the International MultiConference of Engineers and Computer Scientists 2018 Vol I IMECS 2018, March 14-16, 2018, Hong Kong ISBN: 978-988-14047-8-7 ISSN: 2078-0958 (Print); ISSN: 2078-0966 (Online) IMECS 2018