A Complex Overview of Modeling and Control of the Rotary Single Inverted Pendulum System

The purpose of this paper is to present an in-depth survey of the rotary single inverted pendulum system from a control engineer’s point of view. The scope of the survey includes modeling and open-loop analysis of the system as well as design and verification of balancing and swing up controllers which ensure successful stabilization of the pendulum in the unstable upright equilibrium. All relevant tasks and simulation experiments are conducted using the appropriate function blocks, GUI applications and demonstration schemes from a Simulink block library developed by the authors of the paper. The library is called Inverted Pendula Modeling and Control (IPMaC) and offers comprehensive program support for modeling, simulation and control of classical (linear) and rotary inverted pendulum systems.


Introduction
Inverted pendulum systems (IPS) represent a significant class of nonlinear underactuated mechanical systems, well-suited for verification and practice of ideas emerging in control theory and robotics [1]. Stabilization of a pendulum rod in the unstable upright position is considered a benchmark control problem which has been solved by attaching the pendulum to a base that moves in a controlled linear manner (classical or linear IPS) or in a rotary manner in a horizontal plane (rotary IPS).
The Inverted Pendula Modeling and Control (IP-MaC) is a structured Simulink block library which was developed by the authors of this paper and provides complex software support for the analysis and control of both classical and rotary IPS [2]. Strong emphasis is placed on the generalized approach to system modeling [3], [4], allowing the library to handle systems which differ by the number of pendulum links attached to the base, such as single [2], [4], [5] and double [2], [4], [6] IPS.
As an underactuated, unstable and yet controllable system, the rotary single inverted pendulum has been regarded as an attractive testbed system for linear and nonlinear control law verification since Katsuhisa Furuta, Professor at the Tokyo Institute of Technology, introduced it to feedback control community in 1992 [7]. The aim of this paper is to present a thorough overview of this system that covers all topics significant for control engineering. The paper is organized as follows: • In Section 2, a mathematical model of the system is obtained by automatic model generation, and open-loop responses of the system are evaluated.
• Design and verification of control algorithms that stabilize the pendulum in the unstable upright equilibrium is presented in Section 3 for a pair of model situations which deal with stabilizing the pendulum from around the upright and downward position respectively. The latter situation also involves the design of a swing-up controller.
• Finally, Section 4 concludes the paper with an evaluation of achieved results and some final remarks.
Suitable function blocks and GUI applications from the IPMaC are employed in every described step of the process of modeling and control design. All simulation experiments mentioned in the paper can be run from the Demo Simulations section of the IPMaC which contains links to corresponding simulation schemes.

Mathematical Modeling and Simulation of the Rotary Single Inverted Pendulum System
The considered rotary single inverted pendulum system ( Fig. 1) is composed of a rigid, homogenous pendulum rod attached to an rigid arm which is free to rotate in a horizontal plane. Since the number of actuators is lower than the number of system links, the system is underactuated: The only input (the torque M (t) applied on the arm) is used to control the two degrees of freedom of the system: arm angle θ 0 (t) [rad] and pendulum angle θ 1 (t) [rad].

Automatic Derivation and Evaluation of the Mathematical Model
Manual, step-by-step derivation of differential equations of motion is the traditional approach to modeling of mechanical systems which appears prevalently in accessible works such as [8], [9], [10] despite the fact that it often turns out as laborious and error-prone. As opposed to the traditional approach, the mathematical model of the system analyzed in this paper was generated automatically by the Inverted Pendula Model Equation Derivator (Fig. 2) a MATLAB GUI application which simplified the process of inverted pendula modeling to such a level that the user is only required to select the desired type of system (classical/) and the number of pendulum links. The application was designed as a central component of the IPMaC block library and uses an original procedure of mathematical model derivation based on the mutual analogy of IPS with a varying number of pendulum links. Via Symbolic Math Toolbox [11], the procedure implements the derivation of Euler-Lagrange equations of motion for a generalized system of n classical or rotary inverted pendula [3], [4], [5]. As it is shown in the preview of the Derivator window, the generated model of the rotary single inverted pendulum system is composed of two second-order nonlinear differential equations of motion which respectively describe the dynamic behavior of the rotary arm and the pendulum. For the purposes of further model analysis as well as control design, it is convenient to rearrange the obtained nonlinear equations into the so-called standard minimal ODE (Ordinary Differential Equation) matrix form [12]: where θ(t) is the vector of generalized coordinates defined as θ(t) = (θ 0 (t)θ 1 (t)) T , M I ( θ(t)) is the inertia matrix, N( θ(t), θ (t)) describes the influence of centrifugal and Coriolis forces, R( θ(t)) accounts for gravity forces and V (t) is the system's input vector. After the described rearrangement of the generated equations of motion, the mathematical model of the system assumed the form (2), see [5], where m 0 and m 1 stand for the masses of the arm and the pendulum, l 0 and l 1 are their respective lengths, δ 0 and δ 1 are the damping constants in the joints of the arm and pendulum, J 0 and J 1 are the moments of inertia of the arm and pendulum with respect to their pivot points, defined in each case as (3), see [13], and M(t) is the input torque applied upon the rotary arm. The generated model will hereafter be referred to as a torque model of a rotary single inverted pendulum system, to distinguish it from a voltage model of the system, which will be presented in section 2.3.
A number of differences were observed between the generated mathematical model and models in referenced works. Most of these can be attributed to the initial choice of the coordinate system orientation (rightor left-handed) and the orientation of the angles (clockwise/anticlockwise). In the general procedure implemented by the Derivator, it is assumed that all motion of the system is bound to a standard right-handed three-dimensional coordinate system, and that the rotary motion of the pendulum takes place in a vertical plane that is always perpendicular to both the horizontal arm plane and the arm itself. As a result, the actual plane the pendulum rotates in is different in every instant, which brings additional complexity as well as high accuracy to the generated mathematical model. In referenced works, the pendulum was often assumed to be rotating in a constant plane [8], [9] or the rotary motion of the arm was neglected altogether [10].

Open-Loop Dynamical Analysis of the Torque Simulation Model
The IPMaC is designed as an open library structured into sublibraries. One of the default components of the Inverted Pendula Models sublibrary of the IPMaC is the Rotary Single Inverted Pendulum (RSIP) block, which implements the mathematical model (2) derived above. The block is equipped with a dynamic block mask [2] which enables the user to edit the numeric values of parameters and initial conditions, to enable or disable the torque input port and to adjust the number of the block's output ports, all with great flexibility (Fig. 3).
The open-loop dynamical behavior of the rotary single inverted pendulum system was verified in a simulation experiment [5] in which the RSIP block was actuated from an initial upright position of the pendulum by a torque impulse of 0,4 Nm lasting 1 s. The numeric parameters of the simulated system were selected to be m 0 = 0, 5 kg, m 1 = 0, 275 kg, l 0 = 0, 6 m, l 1 = 0, 5 m, δ 0 = 0, 3 kgs −1 , δ 1 = 0, 011458 kgm 2 s −1 . The time behavior of the rotary arm and the freefall and stabiliza-

Open-Loop Dynamical Analysis of the Voltage Simulation Model
As is the case of all IPS, the practical use of the generated rotary single inverted pendulum torque model is limited purely to the simulational environment: we are unable to manually produce a torque which would stabilize the pendulum in a chosen position. Therefore, an electric motor needs to be coupled with the system to act as a controllable source of the torque which actuates both the rotary arm and the attached pendulum [2].
To provide the simulation models of IPS with a model of the most frequently used actuating mechanism, library block DC Motor for Inverted Pendula Systems was included into the Inverted Pendula Motors sublibrary of the IPMaC. The block implements the mathematical model of a brushed direct-current (DC) motor in two alternative forms depending on the type of system (classical/rotary). For rotary IPS, the DC motor is modeled as the following voltage-to-torque conversion relationship, derived in [3]: where V a (t) is the input voltage applied to the motor, k m is the motor torque constant, equal in value to the back EMF constant, k g is the gear ratio, and R a is the armature resistance. If the DC motor model is appended to the model of the rotary inverted pendulum system (i.e. (4) is substituted into (2)), a voltage model of the system is obtained (Fig. 5). In Fig. 6, the response of the rotary inverted pendulum voltage model to an impulse signal of 1 V lasting 1 s is depicted. The numeric parameters of the DC motor simulation model were borrowed from the motor featured in the series of popular laboratory models of inverted pendulum systems issued by Quanser Academic (SRV02-Series) and are specified in [14].

Stabilization of the Rotary Single Inverted Pendulum System in the Unstable Equilibrium
The principal control objective for the considered nonlinear system was defined as stabilization in the unstable equilibrium, i.e. in the vertical upright (inverted) position of the pendulum [5]. Two possible model situations were considered, in which a varying initial position of the pendulum calls for a corresponding control setup. It is sufficient to design a stabilizing feedback controller if the pendulum is kept in the proximity of the upright position (section 3.1). On the other hand, the pendulum in the natural hanging position requires an additional mechanism which swings it up to the upright position before it can be stabilized (section 3.2), as well as a mechanism to switch between the two controllers. The rotary single inverted pendulum can therefore be considered as a suitable testbed system for illustrating hybrid control approaches [15].

Design of a Stabilizing Controller via State-Feedback Techniques
Let us now suppose that at the beginning of the experiment, the pendulum is held close to the unstable upright equilibrium. The designed stabilizing controller should ensure that the following particular problems will be solved [3], [5], [6]: • balancing the pendulum around the upright position after an initial deflection (i.e. from nonzero initial conditions), • compensation of a time-constrained (impulse) or permanent (step) disturbance input signal, • the arm must be able to track a predefined reference trajectory at any time.
State-feedback control was selected as a principal control technique because simultaneous control of several degrees of freedom can only be ensured if they are all taken into consideration at once (Fig. 7). When close to a chosen equilibrium point, detailed methods and control techniques designed for linear systems can be used to compute a linear state-feedback control law which is subsequently applied to the original nonlinear system in the form of a stabilizing input signal u ST (t).

1) Automatic Linear Approximation of the Rotary Inverted Pendulum System
To obtain the linear approximation of the original system, which is a necessary prerequisite for linear statefeedback control design, the rotary single inverted pendulum model first had to be expressed by the standard state-space description of a nonlinear SIMO system [4]: With the state vector defined as x(t) = ( θ(t), θ (t)), the differential vector state equation f (.) was constructed by isolating the 2 nd derivative of the vector of generalized coordinates from the standard minimal ODE form (1) of the mathematical model of the system [12]. The algebraic output equation g(.) denotes the m state variables which are assumed to be available through measurement.
The general procedure implemented by the Derivator is based on the assumption that the upright position of the pendulum corresponds to the equilibrium point of x(t) = x ST = 0 T . If the system input is set to u(t) = u ST = 0, [2], then the continuous-time statespace description of the linear, time-invariant system which serves as an approximation defined as (5) in the upright equilibrium becomes: where A ∈ 4×4 is the state (Jacobian) matrix of the linearized system, b ∈ 4×1 is the input matrix, C ∈ m×4 is the output matrix and d ∈ m×1 is the direct feedthrough matrix [16]. The linearized statespace model (6) was obtained from the Inverted Pendula Model Linearizator & Discretizer (Fig. 8), a MAT-LAB GUI application which generates the continuoustime state-space matrices by expanding (5) into the Taylor series around a given equilibrium point with the higher-order terms neglected (Fig. 8). In case the sampling period constant T S is provided, the application also returns the matrices of the corresponding discretetime state-space representation: where F ∈ 4×4 is the discrete state matrix, g ∈ 4×1 is the discrete input matrix; C and d are the same as in the continuous system.
The system eigenvalues were computed to be (0 6, 404 − 9, 096 − 1, 79), which implies that the linear approximation of rotary single inverted pendulum in the upper equilibrium is an unstable system with first-degree astatism. The system was next discretized with the sampling period of T S = 0,01 s and the following discrete-time state equation matrices were obtained: In both cases, the matrices of the output equation are problem-dependent and are specified in later sections.

2)
State-Feedback Control with a State Estimator The Inverted Pendula Control sublibrary of the IPMaC provides complex software support for state-feedback methods of controller design for inverted pendulum systems. It contains several dynamic-masked blocks which were thoroughly described in [2] in terms of their structure, functionality and user interface.
The State-Feedback Controller with Feed-forward Gain (SFCFG) library block evaluates a state-feedback control law which is calculated either from the continuous-time state-space description: or from the discrete-time state-space description: assuming that controller output is equivalent to the system output: u ST (t) = u(t). The state-feedback control law is in both cases composed of several functional components [2], [3], [4], [5], [6]. The feedback component u R (t)/u R (i) brings the system's state vector x(t)/ x(i) into the origin of the state space, i.e. stabilizes the pendulum in the upright equilibrium and returns the arm to the reference position. The method to determine the feedback gain k/ k D applied on the full and measurable state vector can be selected from between the pole placement algorithm and the linear quadratic (LQ) optimal control method [5], [16]. The feedforward component u f f (t)/u f f (i) makes the system output y(t)/ y(i) track the reference command w(t)/w(i) by applying feedforward gain k f f / k f f D , which is computed in the form: POWER ENGINEERING AND ELECTRICAL ENGINEERING VOLUME: 11 | NUMBER: 2 | 2013 | SPECIAL ISSUE for the continuous-time control law (8), or in the form: for the discrete-time control law (9), given that I = diag (1 1 1 1). The artificial output matrix c 1 = (1 0 0 0) denotes the arm angle as the only state variable for which it makes sense to consider a nonzero reference command. Finally, the unmeasured disturbance input d u (t)/d u (i). is considered in both the continuous-time and the discrete-time form of the control law. The dynamic block mask of the SFCFG block allows the user to select a preferred control law, method to compute the feedback gain, and optional constraints. To match a particular control requirement (initial pendulum deflection, compensation of disturbance signal, tracking a reference position of the arm or a combination of the three), the block's appearance may be adjusted by optional enabling or disabling of the reference command input w(t)/w(i) and/or the disturbance input d u (t)/d u (i).
Because of measurement limitations, it is often impossible to retrieve the full state-space vector at every time instant [17]. The Luenberger Estimator (LE) block implements a discrete-time linear state observer that provides the controller block with a complete, reconstructed state vector by evaluating a model of the original discrete-time system in the structure: which ensures that the time behavior of estimation error x(i) = x(i) − x(i) is independent of input/output signals: and the estimator gain matrix L has to be selected in such a way that the approximated state vector x(i) quickly converges to the actual system state x(i). Figure 10 illustrates the results of applying the statefeedback control law based on both the continuous-time and discrete-time LQR algorithms on the rotary single inverted pendulum voltage model. RSIP, SFCFG and LE blocks were employed in the corresponding simulation scheme (Fig. 9). With the initial conditions set to θ 0 (0) = θ 1 (0) = 0, the control objective was to keep the pendulum upright all the time while making the arm rotate for a total of half a circle and stop every quarter-turn to stabilize before returning to its initial position. The weight matrices which occur in both the standard continuous-time LQ functional: (14) and the discrete-time LQ functional: were set to Q = diag(100 20 20 0) and r = 1. It was next assumed that the arm and pendulum angles would be directly measurable while the velocities would need to be estimated. The state-space matrices of the output equation therefore became while the vector of estimator poles was set to (0, 1 0, 2 + 0, 1i 0, 2 − 0, 1i 0, 3). It is obvious that the response of the discrete-time LQR algorithm closely follows that of the continuoustime algorithm, and there is no steady-state error in either case. The simulation results were also compared with those of the continuous-time pole-placement controller: for this case, the vector of desired closed-loop poles was set to (−2 − 3 + i − 3 − i − 10).
To enhance the performance of the designed LQR controller, optimal weight matrices were sought. After setting r = 1, the positive real diagonal elements of the Q weight matrix were modified and the influence of each candidate matrix on the overall performance of the system was verified in the discrete-time LQR simulation setup for the rotary inverted pendulum voltage model. The results of two extreme cases of selecting Q : Q 1 = diag(500 0 20 0) and Q 2 = diag(10 120 20 0), are depicted in Fig. 11. For Q 1 , the arm quickly reaches the reference position but the pendulum overshoot is quite far from desired. If Q 2 is selected, the pendulum swings are well within the limits, however the rise time of the arm is unacceptably slow. It has therefore been concluded that the optimal time behavior of the arm and the pendulum are two conflicting requirements which cannot be satisfied simultaneously. Any successful tuning of weight matrices must therefore result in a reasonable compromise between the quick rise time of the base and the low overshoot of the pendulum.

3) State-Feedback Control with Permanent Disturbance Compensation
Applying state-feedback control with feedforward gain on a system is insufficient if the steady-state effect of a permanent disturbance input needs to be compensated. The structure of the State-Feedback Controller with Summator (SFCS) block implements a summator term v(i) which sums up all past error values. This ensures that the system output will track all changes in the reference command and the influence of permanent disturbances will be eliminated. The evaluated control law, presented and derived by Modrlak in [17], is specified as: where w(i) is the reference command and k 1 , k 2 are gain matrices which are computed from the matrix structure: assuming that k (alternatively k D )is a standard feedback gain vector equivalent to the one in Section 3.1.2. The layout of the block mask once again allows the user to adjust the number of block input ports to match a specified control requirement and to compute k/ k D using a preferred method and state-space description [2]. The control law (16) was verified for the rotary single inverted pendulum voltage model and the weight matrices of the standard discrete-time LQ functional (15) were set to Q = diag(500 0 20 0), r = 1. The obtained results were compared to those of a conventional discrete-time LQR controller using the same values of weight matrices as in Section 3.1.2. A constant disturbance input (5 V for the first controller, 1 V for the second) was present in both simulations. To compensate for measurement limitations, the LE block was included in both schemes, with the estimator poles set to the same values as before. As it can be seen in Fig.  12, the conventional LQR controller fails to track the reference trajectory without producing steady-state error, but the permanent disturbances are successfully compensated by a LQR algorithm with a summator included in the control structure.

Design of a Control Strategy for Swing-up and Stabilization of the System
If the initial position of the pendulum is equivalent to the natural hanging position, then the additional control problem of swinging it upwards leads to a hybrid control setup which consists of three basic components, schematically depicted in the block diagram in Fig. 13: • a swing-up controller, which actuates the arm with an input signal u SW (t) of appropriate direction and magnitude, making the pendulum swing with an increasing amplitude and angular speed until it enters the stabilization zone (balancing region) around the upright position [7], • a stabilizing (balancing) controller, which maintains the pendulum in the upright position with a stabilizing control signal u ST (t) designed by available feedback control techniques, such as the statefeedback control law based on Jacobian linearization described in section 3.1, or a variety of nonlinear control design approaches [18], • a transition (switching) mechanism, which intercepts the pendulum when it nears the upright position (i.e. crosses the borderline of the balancing region) and switches to stabilizing control.

1) Energy-based Methods for Swing-up Control
One of the earliest and most effective approaches to pendulum swing-up is the method based on energy considerations, proposed and explained by Aström, Furuta and Iwase in [19], [20]. The goal is to bring the total mechanical energy W of the pendulum to zero, which corresponds to the upright position. The first derivative of W for the uncontrolled pendulum (2) in the simplified form is given as: Whether the expression in (18) is greater or lower than zero depends directly on the sign oḟ θ 1 (t)(cosθ 1 (t)). The basic energy-based control law (cosine value controller) therefore becomes: u SW (t) = −u m sgn(θ 1 (t)(cosθ 1 (t))).
This control law can be simplified into a law which will be referred to as a zero speed controller [21]: u SW (t) = u m sgn(θ 1 (t)), (20) or modified into an absolute value control law: The control laws (19), (20), (21), were encapsulated into the structure of Swing-up Controller block which is part of the Inverted Pendula Swing-up sublibrary and allows the user to select a swing-up method, the constraints of the balancing region, and the input magnitude u m .
The following swing-up / stabilizing control strategy was proposed and verified for the both the torque model and voltage model of the system. As the control objective, the freely hanging pendulum had to be brought into the upright equilibrium and the arm needed to be stabilized at the origin. Initial conditions of the system were therefore set to θ 0 (0) = −1 rad (−57, 3 degrees) and θ 1 (0) = −π rad (−180 degrees). All three swing-up control laws were tried out and for each control law, the input magnitude was tuned to the highest value which still allows successful swingup with no oscillations or destabilization. Once the pendulum was approaching the the upright position, control was switched to a balancing controller. Statefeedback controller based on discrete-time state-space description was selected and the weight matrices of the discrete-time LQ functional (15), were specified as Q = diag(100 20 20 0), r = 1 for each simulation experiment. Switching between the controllers took place when the pendulum was 0,6 rad (34,4 degrees) away from the upright position. Figure 14 depicts the comparison of the swing-up control laws (19), (20), (21) applied on the torque model of the system. It turned out that although all control laws met the control objective, the rotary inverted pendulum performed at its best for the cosinevalue controller -the system's performance was diminished for other controllers, which is caused by long intervals during which energy is taken from the pendulum.
When tuning the input magnitude u m , the time needed to swing the pendulum to the upright position was discovered to be indirectly proportional to u m . However, feasible input values could only be selected from a bounded interval. An unlimited increase in magnitude leads to the increase of the pendulum angular velocity, and a too low magnitude may either be entirely unable to bring the pendulum upright, or it needs numerous swings to do so, which results in a displacement of the rotary arm away from the equilibrium point. In both cases, the control mechanism would fail  to stabilize the system, proving that the balancing controller is only effective if the full state of the system is close to the equilibrium point in the moment of inter-ception. An illustrative experiment which compares the effect of a varying u m on the rotary single inverted pendulum voltage model, is depicted in Fig. 15.

Conclusion
The purpose of this paper was to present a comprehensive approach to the problem of modeling and control of the rotary single inverted pendulum system. A custom-designed Simulink block library developed by the authors of the paper, Inverted Pendula Modeling and Control (IPMaC), was used as a software framework for all covered issues which included mathematical model derivation, open-loop analysis and linear approximation of the system, as well as followed by design and verification of stabilizing state-feedback control algorithms as well as energy-based swing-up control laws.
The IPMaC block library provided suitable function blocks to support every step of the process of analysis and control design (such as a pre-prepared simulation model of the rotary single inverted pendulum system or a detailed state-feedback controller block), together with several original applications with graphical user interface. One such application was used to derive the mathematical model for the selected inverted pendulum system in the form of symbolic equations of motion; the other performed the automatic linear approximation of the system in a chosen equilibrium point. In these applications, great practical potential of symbolic mathematical software was demonstrated.
With the aid of developed program tools, the paper has presented a set of coherent results together with thorough evaluations. The validity of the nonlinear model generated by the above application was verified by comparing the obtained results to those listed in the resources, and by evaluating the open-loop responses of the simulation model. The outcome of both approaches was highly acceptable: all deviations were justified by the laws of mechanics and it was shown that the dynamic behavior of both the torque and the voltage model is in agreement with the empirically observed facts on pendulum movement. The ability to control the rotary inverted pendulum system with respect to the principal control objective (stabilization in the inverted position) and a variety of secondary issues was demonstrated for all implemented state-feedback control techniques which included pole-placement and the LQR optimal control method; the simulation results also justified the use of the techniques based on a linearized model to control nonlinear systems. To deal with the problem of swinging the pendulum upwards from the natural hanging position, several heuristic swing-up methods based on energy considerations were proposed and compared from multiple viewpoints.
The IPMaC block library enhances the capabilities of the MATLAB/Simulink program environment by providing effective means for analysis and control of an important class of nonlinear mechanical systems. Moreover, the readily available collection of mathematical and simulation models of inverted pendulum systems can be viewed as a testbed model basis for exploring the properties of underactuated nonlinear systems, mechatronic systems, hybrid systems and other concepts. As a meaningful contribution to modeling and control education, the library has been included into the research and teaching activities of the Center of Modern Control Techniques and Industrial Informatics (http://kyb.fei.tuke.sk/laben/) at the Faculty of Electrical Engineering and Informatics, Technical University of Kosice.