Derive the equations for an inverted pendulum on a cart in one dimension.
- User
Derive the equations for an inverted pendulum on a cart in one dimension.
- Assistant
Derive the equations for an inverted pendulum on a cart in one dimension.
Certainly! The inverted pendulum on a cart is a fundamental problem in dynamics and control theory, illustrating the principles of balancing an unstable equilibrium. Below is a comprehensive derivation of its equations of motion using both Newtonian mechanics and Lagrangian mechanics. We'll focus primarily on the one-dimensional case.
Consider the following setup:
[image: Inverted Pendulum on a Cart] open
Figure: Inverted pendulum on a cart. ( x ) is the horizontal position of the cart, ( \theta ) the angle of the pendulum from the vertical.
Derive the equations of motion for the system, relating the cart's acceleration ( \ddot{x} ) and the pendulum's angular acceleration ( \ddot{\theta} ) to the forces acting on the system.
We'll use Lagrangian mechanics for the derivation, as it provides a systematic way to handle the dynamics of constrained systems.
We'll use ( x ) and ( \theta ) as generalized coordinates:
The kinetic energy has contributions from both the cart and the pendulum.
Cart's Kinetic Energy: [ T_{\text{cart}} = \frac{1}{2} M \dot{x}^2 ]
Pendulum's Kinetic Energy:
The pendulum has both translational and rotational kinetic energy. However, since it's rigidly attached and swings without slipping, its kinetic energy can be expressed in terms of ( x ) and ( \theta ).
The position of the pendulum's center of mass: [ x_p = x + \ell \sin\theta ] [ y_p = y + \ell \cos\theta ] Since the motion is in one dimension horizontally, and we can set the vertical position ( y ) to be zero (as the cart moves horizontally), so: [ y_p = \ell \cos\theta ]
The velocities: [ \dot{x}_p = \dot{x} + \ell \cos\theta , \dot{\theta} ] [ \dot{y}_p = -\ell \sin\theta , \dot{\theta} ]
Thus, the pendulum's kinetic energy: [ T_{\text{pendulum}} = \frac{1}{2} m (\dot{x}_p^2 + \dot{y}_p^2) = \frac{1}{2} m \left[ (\dot{x} + \ell \cos\theta , \dot{\theta})^2 + (\ell \sin\theta , \dot{\theta})^2 \right] ]
Expanding: [ T_{\text{pendulum}} = \frac{1}{2} m \left( \dot{x}^2 + 2 \ell \cos\theta , \dot{x} \dot{\theta} + \ell^2 \cos^2\theta , \dot{\theta}^2 + \ell^2 \sin^2\theta , \dot{\theta}^2 \right) ] [ T_{\text{pendulum}} = \frac{1}{2} m \left( \dot{x}^2 + 2 \ell \cos\theta , \dot{x} \dot{\theta} + \ell^2 (\cos^2\theta + \sin^2\theta) \dot{\theta}^2 \right) ] [ T_{\text{pendulum}} = \frac{1}{2} m \left( \dot{x}^2 + 2 \ell \cos\theta , \dot{x} \dot{\theta} + \ell^2 \dot{\theta}^2 \right) ]
Total Kinetic Energy: [ T = T_{\text{cart}} + T_{\text{pendulum}} = \frac{1}{2} M \dot{x}^2 + \frac{1}{2} m \left( \dot{x}^2 + 2 \ell \cos\theta , \dot{x} \dot{\theta} + \ell^2 \dot{\theta}^2 \right) ] [ T = \frac{1}{2} (M + m) \dot{x}^2 + m \ell \cos\theta , \dot{x} \dot{\theta} + \frac{1}{2} m \ell^2 \dot{\theta}^2 ]
The potential energy arises from the pendulum's height in the gravitational field.
[ V = -m g y_p = -m g \ell \cos\theta ]
(Note: The negative sign ensures that ( V ) is minimized when ( \theta = 0 ), which is consistent with the pendulum being upright.)
The Lagrangian ( L ) is the difference between kinetic and potential energies:
[ L = T - V = \frac{1}{2} (M + m) \dot{x}^2 + m \ell \cos\theta , \dot{x} \dot{\theta} + \frac{1}{2} m \ell^2 \dot{\theta}^2 + m g \ell \cos\theta ]
The Euler-Lagrange equations are given by:
[ \frac{d}{dt} \left( \frac{\partial L}{\partial \dot{q}_i} \right ) - \frac{\partial L}{\partial q_i} = Q_i ]
where ( q_i ) are the generalized coordinates and ( Q_i ) the generalized forces. In this setup, we'll assume that the only external force is a horizontal force ( F ) applied to the cart:
[ \frac{\partial L}{\partial \dot{x}} = (M + m) \dot{x} + m \ell \cos\theta , \dot{\theta} ]
[ \frac{d}{dt} \left( \frac{\partial L}{\partial \dot{x}} \right ) = (M + m) \ddot{x} + m \ell \left( -\sin\theta , \dot{\theta} , \dot{\theta} + \cos\theta , \ddot{\theta} \right) ] [ = (M + m) \ddot{x} - m \ell \sin\theta , \dot{\theta}^2 + m \ell \cos\theta , \ddot{\theta} ]
[ \frac{\partial L}{\partial x} = 0 ]
[ (M + m) \ddot{x} - m \ell \sin\theta , \dot{\theta}^2 + m \ell \cos\theta , \ddot{\theta} = F ]
[ \frac{\partial L}{\partial \dot{\theta}} = m \ell \cos\theta , \dot{x} + m \ell^2 \dot{\theta} ]
[ \frac{d}{dt} \left( \frac{\partial L}{\partial \dot{\theta}} \right ) = m \ell \left( -\sin\theta , \dot{\theta} , \dot{x} + \cos\theta , \ddot{x} \right ) + m \ell^2 \ddot{\theta} ] [ = -m \ell \sin\theta , \dot{\theta} , \dot{x} + m \ell \cos\theta , \ddot{x} + m \ell^2 \ddot{\theta} ]
[ \frac{\partial L}{\partial \theta} = -m \ell \sin\theta , \dot{x} \dot{\theta} - m g \ell \sin\theta ]
[ -m \ell \sin\theta , \dot{\theta} \dot{x} + m \ell \cos\theta , \ddot{x} + m \ell^2 \ddot{\theta} + m \ell \sin\theta , \dot{x} \dot{\theta} + m g \ell \sin\theta = 0 ]
Simplifying:
[ m \ell \cos\theta , \ddot{x} + m \ell^2 \ddot{\theta} + m g \ell \sin\theta = 0 ]
We now have two coupled equations:
From the ( x )-equation: [ (M + m) \ddot{x} - m \ell \sin\theta , \dot{\theta}^2 + m \ell \cos\theta , \ddot{\theta} = F ]
From the ( \theta )-equation: [ m \ell \cos\theta , \ddot{x} + m \ell^2 \ddot{\theta} + m g \ell \sin\theta = 0 ]
These are the nonlinear equations of motion for the inverted pendulum on a cart.
For practical control design, it's common to linearize the equations around the upright equilibrium (( \theta = 0 )) assuming small angles (( \sin\theta \approx \theta ), ( \cos\theta \approx 1 )) and neglecting higher-order terms.
Applying the small angle approximation:
First Equation: [ (M + m) \ddot{x} - m \ell \theta , \dot{\theta}^2 + m \ell \ddot{\theta} = F ] For small angles and assuming ( \theta ) and ( \dot{\theta} ) are small, the term ( m \ell \theta , \dot{\theta}^2 ) is negligible: [ (M + m) \ddot{x} + m \ell \ddot{\theta} = F ]
Second Equation: [ m \ell \ddot{x} + m \ell^2 \ddot{\theta} + m g \ell \theta = 0 ]
We have:
[ \begin{cases} (M + m) \ddot{x} + m \ell \ddot{\theta} = F \quad (1) \ m \ell \ddot{x} + m \ell^2 \ddot{\theta} + m g \ell \theta = 0 \quad (2) \end{cases} ]
Let's express these equations in matrix form:
\begin{bmatrix} F \
To solve for ( \ddot{x} ) and ( \ddot{\theta} ), we can invert the coefficient matrix.
Let the matrix be ( \mathbf{A}} ):
[ \mathbf{A} = \begin{bmatrix} M + m & m \ell \ m \ell & m \ell^2 \end{bmatrix} ]
The determinant of ( \mathbf{A} ) is:
[ \det(\mathbf{A}) = (M + m)(m \ell^2) - (m \ell)^2 = M m \ell^2 + m^2 \ell^2 - m^2 \ell^2 = M m \ell^2 ]
The inverse of ( \mathbf{A} ), ( \mathbf{A}^{-1} ), is:
[ \mathbf{A}^{-1} = \frac{1}{\det(\mathbf{A})} \begin{bmatrix} m \ell^2 & -m \ell \
Multiplying ( \mathbf{A}^{-1} ) with the RHS vector:
\mathbf{A}^{-1} \begin{bmatrix} F \
Simplifying:
For ( \ddot{x} ): [ \ddot{x} = \frac{F}{M} + \frac{m g \theta}{M} ]
For ( \ddot{\theta} ): [ \ddot{\theta} = - \frac{F}{M \ell} - \frac{(M + m) g \theta}{M \ell} ] [ \ddot{\theta} = - \frac{F}{M \ell} - \frac{(M + m) g}{M \ell} \theta ]
The linearized equations governing the inverted pendulum on a cart are:
[ \begin{cases} \ddot{x} = \frac{F}{M} + \frac{m g}{M} \theta \ \ddot{\theta} = -\frac{F}{M \ell} - \frac{(M + m) g}{M \ell} \theta \end{cases} ]
These equations can also be expressed in state-space form or further manipulated for control design purposes.
For completeness, let's briefly outline the derivation using Newtonian mechanics.
Cart:
Pendulum:
However, this approach can become cumbersome due to the coupling between ( x ) and ( \theta ). The Lagrangian method is generally more straightforward for handling such systems.
We derived the equations of motion for an inverted pendulum on a cart in one dimension using the Lagrangian formulation. The resulting nonlinear equations describe the coupled dynamics of the cart's horizontal motion and the pendulum's angular motion. For practical applications, especially in control systems, these equations are often linearized around the upright equilibrium to facilitate analysis and controller design.
Nonlinear Equations: [ \begin{cases} (M + m) \ddot{x} - m \ell \sin\theta , \dot{\theta}^2 + m \ell \cos\theta , \ddot{\theta} = F \ m \ell \cos\theta , \ddot{x} + m \ell^2 \ddot{\theta} + m g \ell \sin\theta = 0 \end{cases} ]
Linearized Equations: [ \begin{cases} \ddot{x} = \frac{F}{M} + \frac{m g}{M} \theta \ \ddot{\theta} = -\frac{F}{M \ell} - \frac{(M + m) g}{M \ell} \theta \end{cases} ]
These equations form the foundation for further analysis, such as stability assessment and controller design, to maintain the pendulum in the inverted position.
Not yet included in a published release.