4. Simulation
The dynamics of the system can be modeled using either Newtonian or Lagrangian mechanics, which are two different approaches to describe the motion of physical systems. In the Newtonian approach, the equations of motion are derived from the fundamental laws of mechanics, such as Newton’s laws of motion and the principle of conservation of energy. In the Lagrangian approach, the equations of motion are derived from the Lagrangian, which is a function that summarizes the energy of the system in terms of generalized coordinates and their time derivatives.
The two approaches are equivalent, meaning that they provide the same physical predictions for a given system. The Lagrangian approach, however, often provides a more elegant and concise way of deriving the equations of motion. In this chapter, both approaches will be applied in order to derive the equations of motion for the inverted pendulum on a cart system. First the Newtonian approach will be applied to derive the equations of motion, and then the Lagrangian approach to obtain the same set of equations.
After the equations of motion have been derived, the system will be simulated using numerical methods. Specifically, the Forward Euler and Fourth order Runge-Kutta methods will be explored. Both the Euler and Runge-Kutta methods have their advantages and disadvantages, and the choice of which method to use will depend on the specific requirements of the simulation. In general, the Euler method is simpler and faster, but may not be accurate enough for some applications. The Runge-Kutta method, on the other hand, is more accurate and stable, but may be slower and more computationally expensive.
By using these numerical methods to simulate the inverted pendulum on a cart system, the dynamics of the system can be explored and different control strategies can be tested.
4.1. Pole Cart Model
asdsadd hello hei
4.1.1. Newtonian Approach
Fig. 4.1 Cart Free body diagram (FBD) and kinetic diagram (KD)
From the FBD and KD displayed of the cart in the above figure, the following equation is derived applying Newton’s second law. Since the cart is constrained to only be able to move along the X-axis, the horizontal forces are ignored as it will not give any useful information. Further, the constraint applied means that the cart is not able to rotate. Specifically, \(\ddot{\theta}\) is zero and is constant.
Fig. 4.2 Pole Free body diagram (FBD) and kinetic diagram (KD)
From the FBD and KD displayed of the pole in figure above, multiple equations can be derived by applying Newton’s second law. First the horizontal forces are considered, where the blow equation derived.
It is beneficial to be able to describe the linear acceleration of the pendulum in the horizontal direction by the carts acceleration and the pendulum rotational acceleration. This is done by substituting the variable \(\ddot{x}_{px}\) in the below equation. Since the pendulum is attached to the cart with a revolute joint, the pendulums acceleration in the horizontal direction can be described.
Fig. 4.3 Kinematics assist figure
Utilizing the above figure, the kinematic relations to the pole are derived
Position
Velocity
Acceleration
Finally the pendulums acceleration along the X-axis can be described in relation to the moving cart
Substituting Equation. (4.2) into Equation. (4.1) Yields
Then by substituting the above equation with, the variable \(R_x\) is eliminated.
The equation is then simplified into Equation. (4.3)
Then, the vertical forces acting on the pole is considered.
Same as for the horizontal components, it is beneficial to substitute \(\ddot{x}_{py}\) with the states the carts linear acceleration and the pendulums angular acceleration. Since the cart is not able to move in the horizontal direction \(\ddot{x}_{cy}\) is zero.
Substituting Equation. (4.5) into Equation. (4.4) yields
Now, the final steps are to eliminate the reaction force \(R_y\) from the above equation. To achieve this, the sum of moment of the pole is collected about the center of mass.
Solving for \(R_y\) yields
Substituting Equation. (4.7) into Equation. (4.6)
Substituting \(R_x\) into Equation. (4.8)
Expanding the expression
Simplifying
The expression is then expanded with \(\sin(\theta)\)
The expression is then simplified further
From the above calculations the equations of motions are derived to be
4.1.2. Lagrangian Approach
4.2. Parameter Estimation
In order to make the simulation model as close to the real system as possible. The different parameters constants from the derived equations of motion has to be deduced.
4.2.1. Pendulum Damping
It is possible to determine the damping coefficient
asdasdasdsad
4.3. Forward Euler
The forward Euler can be considered the The simplest method for numerical integration. It involves using the current state of the system to estimate its next state. The Euler method can be prone to numerical instability and may require a very small time step to accurately simulate the system.
4.4. Runge-Kutta
The fourth-order Runge-Kutta method is a numerical integration scheme commonly used to solve ordinary differential equations. It is a higher-order method than the forward Euler method, meaning that it is more accurate and can use a larger time step while maintaining stability.
The method works by evaluating the state of the system at multiple intermediate time steps, using a weighted average of these evaluations to determine the next state of the system. The weights used in the averaging process are chosen to minimize the error in the approximation, resulting in a more accurate simulation.
Although the fourth-order Runge-Kutta method is more computationally expensive than the forward Euler method, it is a popular choice for simulating physical systems due to its accuracy and stability. It is also a versatile method that can be adapted to different types of differential equations, making it a valuable tool for many applications in science and engineering.