Dynamic Modeling and Simulation of a Rotational Inverted Pendulum

This paper presents an alternative way to the dynamic modeling of a rotational inverted pendulum using the classic mechanics known as Euler-Lagrange allows to find motion equations that describe our model. It also has a design of the basic model of the system in SolidWorks software, which based on the material and dimensions of the model provides some physical variables necessary for modeling. In order to verify the theoretical results, It was made a contrast between the solutions obtained by simulation SimMechanics-Matlab and the system of equations Euler-Lagrange, solved through ODE23tb method included in Matlab bookstores for solving equations systems of the type and order obtained. This article comprises a pendulum trajectory analysis by a phase space diagram that allows the identification of stable and unstable regions of the system.


Introduction
Nowadays, the underactuated mechanical systems [1] are generating interest among researchers of modern control theories. This interest is that these systems have similar problems to those found in industrial applications, such as external shocks and/or non-linear behavior in some conditions of operation. The rotational inverted pendulum [2] is a clear example of a mechanical underactuated system; this is a mechanism of two degrees of freedom (DOF) and two rotational joints. It consists of three main elements: a motor, a rotational arm and a pendulum [3]. The motor shaft is connected to one end of the rotational arm making this fully rotate on a horizontal plane; the other end of the arm has connected the pendulum that freely rotates 360 degrees in a vertical plane. Despite being a purely academic level, this system is helpful to study, apply and analyze different modeling strategies. Some industrial applications [4] that present the previously mentioned drawbacks and behavior, are in fields such as robotics, robots balance, biped robots [5], robotic arms; aerospace, positioning rocket; telecommunications, satellite positioning; transportation, Segway [6,7], stability of ships and submarines, iBot, Self-balancing unicycle; construction, bridge cranes; and field monitoring, drones.
To carry out this work, initially a literature review of similar projects [8,9,10] was conducted in order to determine the appropriate dimensions for the prototype design in SolidWorks CAD software. Then it was performed continuously dynamic modeling of the system and using the Lagrangian mechanics as a method, two equations of motion were obtained, due to each one of the two links comprising, the inverted pendulum has a degree of freedom (DOF). To validate the equations obtained, multiple simulations were made in the Matlab software in order to observe their behavior. Thus it was possible to verify in a graphic mode, the waveform of the position and angular velocity of the arm and the pendulum. A fundamental part in the simulation stage, was to bring the CAD model made in SolidWorks to SimMechanics [11] Matlab environment. At the same time, the equations obtained using the Lagrangian mechanics were resolved with the ODE23tb method (Ordinary Differential Equations) belonging to the Matlab software. The use of block diagrams in Simulink allowed a representation of the system. This was intended in order to develop an overlap of results of both simulations and establish similarities and/or differences in the waveform of the variables of interest.
Finally, the graph of the effective potential of the system allowed tracing paths and obtain the phase space diagram [12] in which they can study the critical points that correspond to the maximum and minimum of the potential.
In section II the design of the basic model is presented with their respective physical variables. In section III It provides a brief definition of systems underactuated. Section IV presents the advantage of making use of Euler-Lagrange formalism. In Section V it shows the dynamic modeling of proposed rotational inverted pendulum. In section VI activities are defined for perform proposed simulations as a method of validating results. In section VII the results obtained are shown with a respective analysis of them. Finally, section VIII contains the relevant conclusions of the article.

Prototype Proposed
This section presents the basic design created in SolidWorks CAD software with the following features:

Underactuated Systems
Direct and indirect actions are two concepts that are acquired in the study of mechanisms. The first consists of movement of elements by action of an actuator, while the second consists of the action of motion transmitted by another interconnected element. Such movements are known as degrees of freedom, so that mechanical systems or mechanisms can be classified depending on the number of degrees of freedom and the number of actuators. The fully actuated mechanical systems are those having the same number of degrees of freedom and actuators. Underactuated mechanical systems are those with fewer actuators than degrees of freedom [13]. It is important to highlight the advantages of underactuated systems, since if they do not have advantages over fully actuated mechanical systems, it will not make sense its development. The main advantages present in underactuated systems are: energy saving and control efforts. However, these systems are intended to perform the same functions of fully actuated systems without their disadvantages.

Euler-Lagrange
The dynamic equations of any mechanical system can be obtained from the known classical mechanics (Newton), the drawback of this formalism is the use of the variables in vector form, complicating considerably the analysis when increasing the joints or there are rotations present in the system. In these cases, it is favorable to employ the Lagrange equations, which have formalism of scale, facilitating the analysis for any mechanical system.
In order to use Lagrange equations, it is necessary to follow four steps: 1) Calculation of kinetic energy.
2) Calculation of the potential energy.
3) Calculation of the Lagrangian.

4) Solve the equations.
Where the kinetic energy can be both rotationally and translational, this form of energy may be a function of both the position and the speed . The potential energy is due to conservative forces as the forces exerted by springs and gravity, this energy is in terms of the position .
The Lagrangian is defined as: (1) So the Lagrangian in general terms is defined as follows: (2) Finally the Euler-Lagrange equations for a degrees of freedom system of is defined as follows: Where , are forces or externally exercised pairs (actuators) at each joint, besides nonconservative forces such as friction, resistance to movement of an object within a fluid and generally those that depend on time or speed. It will be obtained an equal number of dynamic equations and degrees of freedom.

Modeling of Rotational Inverted Pendulum
Lagrangian system modeling was performed as shown in Figure 1. It is necessary to make an energy analysis. Therefore, initially the kinetic energy of each link is analyzed, so it can be identified which kinetic energies (rotational and translational) were present in each link.

Kinetic Energy
The kinetic energy of the system consist of a translational and rotational component for the pendulum and rotational component for the arm, Where m is the mass of the body, the linear velocity, the moment of inertia, the angular velocity and the kinetic energy. In this case there are two bodies, the arm and the pendulum. The kinetic energy of the arm is: The kinetic energy of the pendulum is: The total energy of the system is:

Potential Energy
This system only store gravitational potential energy in the pendulum.
The arm has in its nature a rotational movement in a horizontal plane, therefore it does not have height change in its center of mass, providing equal 0 component in equation (8) resulting in a potential energy zero .
The potential energy of the pendulum is, Where represents the value of gravity. The total potential energy of the system is (9),

Position of the pendulum
Because the pendulum is a rigid body, the required position is the its center of mass, The position of the center of mass,

Linear Speed of the center of mass
The speed is defined as the derivative of the position with respect to time.
The velocity components are obtained by differentiating each component position (11), (12) and (13) respectively, The linear velocity of the center of mass can be expressed as follows vector form, They are calculated separately each of the components to the square of the velocity of the center of mass. (21) Finally the following expression is obtained for the linear velocity. (24)

Energy System
The total energy of the system is, Substituting (5) and (6) in (25) is obtained, Total kinetic energy is obtained by substituting equation (24) in (26) The potential energy of the system is shown in equation (10)

Euler-Lagrange Equations
The Lagrangian of the system is, Substituting (10) and (27) (28) the Lagrangian of the system is obtained, As there are two degrees of freedom (DOF) the Euler-Lagrange equations have the following form, Where is the torque of the motor. Solving (30) and (31) we obtain the equations of motion which are given by, Where (32) is the equation of motion of the arm (33) of the pendulum.

Simulation
Although the Euler-Lagrange formalism ensures a high degree of approximation of the mathematical models, is essential do comparisons to validate these results. For verification of modeling the following steps are followed: 1) Represent the system equations in the state space.
2) Define an experiment with initial conditions, natural interactions and external forces.
3) Import the CAD model of SolidWorks in SimMechanics-Matlab. 4) Add the necessary blocks to obtain the desired graphic model and applying external forces. 5) Simulating experiment. 6) Export the results of SimMechanics to Workspace Matlab. 7) Implement a block diagram Simulink-Matlab to solve the equations. 8) Export the solutions to the equations to Workspace Matlab. 9) Graphing and overlay solutions.
As can be seen in the steps above, the simulation of the model was divided into two stages: first, simulate the CAD model initially designed and the second, implement the equations obtained.

Results
Then, it presents each of the steps mentioned in the previous section.

So the equation (34) is the dynamic equation for mechanical systems of n degrees of freedom (DOF).
Where is the matrix of inertia of the system, is the centrifugal and Coriolis matrix, the vector of gravity and external forces.
Taking the equations of motion (32) and (33) and replacing in (34) is obtained representation in state space system, The matrix is important for the dynamic modeling and for the design of controllers. This matrix has a great relationship with the kinetic energy, also the inertia matrix is a symmetric, positive and square matrix of , whose elements depend only on the generalized coordinates.
Centrifugal and Coriolis matrix it is important in the study of stability in control systems, mechanical systems, among others. This matrix is square of and has dependence in its elements of the generalized coordinates and velocities.
The gravity vector it is present in mechanical systems without counterweights or springs, in turn is in systems with displacement off the horizontal plane. This vector is of and has only reliance on joint positions.
2) It defined that the system would have the initial conditions shown in Figure 5, in addition to being subject to effects of gravity and to a torque step 0.2 seconds in the end of the arm that connects to the motor shaft. Finally, a simulation interval 5 seconds was established.

3)
Was imported the CAD model in SimMechanics with the following code line: The initial position of the system is Figure 5 a).

4)
It was necessary add a few block the diagram SimMechanics, since the CAD model is only under the effect of gravity and not have some kind of movement, it blocks provide the step of torque arm included to start rotating, besides adding blocks to the sensing of angular displacement and velocities in an interval of 5 second of test.

6)
To export system solutions to Workspace, is need to add the blocks with the name To Workspace located in Simulink library, which will create a cell for each solution, with the respective data and time in which such data is obtained.

7)
The implementation of the block diagram was performed to numerically solve the equations of the system, thus obtaining values along the defined time interval. The diagram is implemented as follows: Wherein the first block has the input applied to the system, which in this case is a torque step 0.2 second, which has the value 0.5 Nm which is the maximum torque provided by the engine, the block is called System contains the model equations in the state space, with 5 inputs ( ) and 2 outputs ( ). Internally, the block uses the ODE23tb method for solving equations.
Numerical data necessary to solve the equations of motion Euler-Lagrange are as follows: Where equation (36) is the moment of inertia of the arm measured from the end connected to the motor shaft to the opposite end. While equation (37) is the pendulum moment of inertia measured pendulum from the center of mass.

8)
The way to export the data to Workspace of block diagram above is performed with the same aggregate block in step 6).

9)
Taking the exported data in points 6) and 8) the following graphs were made.

Figure 7.
Step torque    It is important to note that the graphs do not have a zero error due to the approximations that were made to the calculation of the moments of inertia of each link, the difference is that the SolidWorks software performs a more accurate calculation of the moments of inertia, because the software considers the geometry of each link.
Then, the pendulum trajectory analysis shown, which part of the potential energy in the center of mass as shown in equation (9), When all paths of the pendulum are collected the phase diagram, which also shows which are the critical points of the system, in this case we know that the pendulum has two critical points, a stable point at which the pendulum is in its obtained hanging position and unstable point in this case refers to a metastable point is satisfied when the pendulum is reversed. Graphically you can get the critical points in the system, we can first obtain which is the equation for calculating the minimum by Figure   VIII  20, it can be seen that the minimum occurs when the wave goes from a negative slope to a positive slope, therefore, we are obtained minimum where must be odd. Similarly one can find the maximum, these occur when moving from a positive slope to a negative, therefore the maximum are present in where must be equal to 0 or couple.

Figure 21. Pendulum phase space
Physically each point on the graph above represents a possible system status, explicitly state in which the pendulum would.
As mentioned above the pendulum has two equilibrium points, however, in the phase space endless these points are. This is because there is shown the position like a straight or space when the real space is a circle that is not topologically equals . Therefore, if space representing geometric positioning system is not topologically equivalent to , for subsequent phase space will not be in , since this is the Cartesian product between the geometric space and space representing the speed is generally . Topologically speaking the pendulum has a geometric space which is equivalent to a circle and a space velocity , therefore, the phase space equivalent to a cylinder and not to . The correct graphic process should be done on a cylinder where its circumference is the geometric representation of the pendulum, this is equivalent to the set of possible positions of the center of mass, while the position along its axis represents the velocity of the center mass, this cylinder is topologically correct space phase. Touring the circumference of the cylinder we can see that there is only one minimum and one maximum diametrically opposed. In Figure 20 you could take energy levels were the result of drawing lines parallel to the axis of the , straight position, well, now those levels may be taken with circles surrounding the cylinder.

Conclusions
The Euler-Lagrange formalism allows dynamic modeling of rotational inverted pendulum in a simple way, thanks to the classical mechanics allows us to work on a climb. This paper has presented step by step dynamic modeling of the proposed system, in addition to the respective simulation of the solution of the equations and further validation of the results using a simulation CAD model designed in SolidWorks exported in SimMechanics Matlab.
This work differs from others through the use of SimMechanics extension for simulation CAD model, this tool is easy to use and reliable enough, this is an advantage for simulations of 3D models since it is not necessary to create platforms for simulation. It also allows working in different ways on the same software, which in this case was Matlab, which allowed us to work with the CAD model and the equations of motion in the same environment (Simulink).