SP

Lagrangian

dawdw

Variables

  • θ\theta = pendulum angle
  • ϕ\phi = wheel angle with respect to pendulum
  • IpI_p = moment of inertia of pendulum
  • IwI_w = moment of inertia of wheel
  • bwb_{w} = friction torque of wheel
  • bpb_{p} = friction torque of pendulum
  • mm = mass of system
  • gg = gravity
  • ll = length to center of mass

To use the Lagrange-Euler Equation we have to define the Lagrangian. The kinetic energy of the system is:

T=12Iw(θ˙+ϕ˙)2+12Ip(θ˙)T = \frac{1}{2}I_{w}(\dot{\theta}+ \dot{\phi})^2+ \frac{1}{2}I_{p}(\dot{\theta})

This is the relative velocity of the wheel attached to the pendulum θ˙+ϕ˙\dot{\theta}+ \dot{\phi}. Then we define the potential function:

V=mglcos(θ)V = mgl\cos(\theta)

Where mm is the mass of the system, and ll is the distance from the pivot to the center of mass. The Lagrangian equation is:

L=TV\mathcal{L} = T - V L=12Iw(θ˙+ϕ˙)2+12Ip(θ˙)mglcos(θ)\mathcal{L} = \frac{1}{2}I_{w}(\dot{\theta}+ \dot{\phi})^2+ \frac{1}{2}I_{p}(\dot{\theta}) - mgl\cos(\theta)

Lagrange-Euler Equation

ddtLq˙Lq=QiNC\frac{d}{dt}\frac{\partial \mathcal{L}}{\partial \dot{q}} - \frac{\partial \mathcal{L}}{\partial q} = Q_{i}^{NC} We define q=[θϕ]q = \begin{bmatrix} \theta \\ \phi \\ \end{bmatrix} Expanding the QiNCQ_{i}^{NC} term, we have two contributions, the torque of the brushless motor and the friction on the wheel and the body pendulum.

So expanding the Lagrange-Euler Equation becomes:

ddtLq˙Lq=τi+Qidiss\frac{d}{dt}\frac{\partial \mathcal{L}}{\partial \dot{q}} - \frac{\partial \mathcal{L}}{\partial q} = \tau_{i} + Q_{i}^{diss} Using the Rayleigh Dissipation Function:

R=12bpθ˙2+12bwϕ˙2\mathcal{R} =\frac{1}{2}b_{p}\dot{\theta}^2 + \frac{1}{2}b_w \dot{\phi}^2

Where bpb_{p} and bwb_{w} are coefficients of friction respectively of pendulum on the pole and wheel. Then

Qidiss=Rq˙Q_{i}^{diss} = - \frac{\partial \mathcal{R}}{\partial{\dot{q}}}

Brushless motor

![[Screenshot 2026-05-07 at 14.56.55.png]] We can model our brushless motor as a normal DC motor with a good approximation, drawing a typical circuit we can easily identify the torque function of the input voltage.

τ=KtVaRaKtKeϕ˙Ra\tau = \frac{ K_t V_{a}}{R_{a}} - \frac{ K_t K_e \dot{\phi}}{R_{a}}

Derivation

component θ\theta:

Lθ˙=Iw(θ˙+ϕ˙)+Ip(θ˙)=θ˙(Ip+Iw)+Iwϕ˙\frac{\partial \mathcal{L}}{\partial \dot{\theta}} = I_{w}(\dot{\theta}+\dot{\phi})+I_{p}(\dot{\theta})=\dot{\theta}(I_{p}+I_{w})+I_{w}\dot{\phi} tLθ˙=θ¨(Ip+Iw)+Iwϕ¨\frac{\partial}{\partial t} \frac{\partial \mathcal{L}}{\partial \dot{\theta}} = \ddot{\theta}(I_{p}+I_{w})+ I_{w}\ddot{\phi} Lθ=mglsin(θ)\frac{\partial \mathcal{L}}{\partial \theta} = mgl\sin(\theta)

The result for the θ\theta component is:

θ¨(Ip+Iw)+Iwϕ¨mglsin(θ)=τθ+Qθdiss\ddot{\theta}(I_{p}+I_{w})+ I_{w}\ddot{\phi} - mgl\sin(\theta) = \tau_{\theta} + Q_{\theta}^{diss}

Where:

Qθdiss=Rθ˙=bpθ˙Q_{\theta}^{diss} = - \frac{\partial \mathcal{R}}{\partial{\dot{\theta}}}=-b_{p}\dot{\theta}

The motor applies +τ+\tau to the wheel and an opposite τ-\tau to the pendulum. Since the angle ϕ\phi is relative to the position of the pendulum, the work depends on relative displacement. This is the reason why the internal motor does not net work on global rotation. For this reason:

τθ=0\tau_{\theta} = 0

The final kinematic equation for the θ\theta component is:

θ¨(Ip+Iw)+Iwϕ¨mglsin(θ)=bpθ˙\ddot{\theta}(I_{p}+I_{w})+ I_{w}\ddot{\phi} - mgl\sin(\theta) = -b_{p}\dot{\theta}

Component ϕ\phi:

Lϕ˙=Iwϕ˙+Iwθ˙\frac{\partial \mathcal{L}}{\partial \dot{\phi}} = I_{w} \dot{\phi}+I_{w}\dot{\theta} ddtLϕ˙=Iwϕ¨+Iwθ¨\frac{d}{dt}\frac{\partial \mathcal{L}}{\partial \dot{\phi}} = I_{w} \ddot{\phi}+I_{w}\ddot{\theta}

Inserting the torque τϕ\tau_{\phi} and the friction from the Reiligh dissipation function:

Iwϕ¨+Iwθ¨=KtVaRaKtKeϕ˙Rabwϕ˙I_{w} \ddot{\phi}+I_{w}\ddot{\theta} = \frac{ K_t V_{a}}{R_{a}} - \frac{ K_t K_e \dot{\phi}}{R_{a}} - b_{w}\dot{\phi}

Now that we have our system of kinematics equation:

{θ¨(Ip+Iw)+Iwϕ¨mglsin(θ)=bpθ˙Iwϕ¨+Iwθ¨=KtVaRaKtKeϕ˙Rabwϕ˙\begin{cases} \ddot{\theta}(I_{p}+I_{w})+ I_{w}\ddot{\phi} - mgl\sin(\theta) = -b_{p}\dot{\theta} \\ I_{w} \ddot{\phi}+I_{w}\ddot{\theta} = \frac{ K_t V_{a}}{R_{a}} - \frac{ K_t K_e \dot{\phi}}{R_{a}} - b_{w}\dot{\phi} \end{cases}

This dynamic system is not linear, we can linearise it near an equilibrium point, that is when the pendulum is straight up (θ=0\theta = 0), so that when the angle is small enough we can solve an optimal control problem like LQR. For small angles sinθθ\sin\theta \approx \theta so our linearised system when the pendulum is straight up becomes:

{θ¨(Ip+Iw)+Iwϕ¨mglθ=bpθ˙Iwϕ¨+Iwθ¨=KtVaRaKtKeRaϕ˙bwϕ˙ \begin{cases} \ddot{\theta}(I_{p}+I_{w})+ I_{w}\ddot{\phi} - mgl\theta = -b_{p}\dot{\theta} \\ I_{w} \ddot{\phi}+I_{w}\ddot{\theta} = \frac{ K_t V_{a}}{R_{a}} - \frac{ K_t K_e }{R_{a}}\dot{\phi} - b_{w}\dot{\phi} \end{cases}

The equation of motions must be represented in matrix form:

x˙(t)=Ax(t)+Bu(t)\dot x(t) = Ax(t)+Bu(t)

Defining the state vector with our angles and angular velocities and input, that is the voltage of the motor:

x=[θθ˙ϕϕ˙]Tx = \begin{bmatrix} \theta & \dot{\theta} & \phi & \dot{\phi}\end{bmatrix}^T

where x1=θ,x2=θ˙,x3=ϕ,x4=ϕ˙x_1 = \theta, \quad x_2 = \dot{\theta}, \quad x_3 = \phi, \quad x_4 = \dot{\phi} and:

Va=uV_{a} = u

Defining the scalars:

E=KtRaE = \frac{K_{t}}{R_{a}} D=KtKeRa+bwD = \frac{K_{t}K_{e}}{R_{a}}+ b_{w}

Substituting into the system:

{x2˙(Ip+Iw)+Iwx4˙mglx1=bpx2Iwx4˙+Iwx2˙=EuDx4bwx4x1˙=x2x3˙=x4\begin{cases} \dot{\,\,x_{2}}(I_{p}+I_{w})+ I_{w}\dot{\,\,x_{4}} - mgl \, x_{1} = -b_{p}\,x_{2} \\ \,\,I_{w} \dot{\,\,x_{4}}+I_{w}\dot{\,\,x_{2}} = E\,u - D \, x_{4} - b_{w}x_{4} \\ \dot{\,\,x_{1}} = x_{2} \\ \dot{\,\,x_{3}} = x_{4} \end{cases}

Solving for x2˙\dot{\,\,x_{2}} in the second equation we get:

x2˙=EIwuDIwx4x4˙\dot{\,\,x_{2}} = \frac{E}{I_{w}}u-\frac{D}{I_{w}}x_{4}-\dot{\,\,x_{4}}

And substituting this in the first one we get:

x4˙=mglIpx1+bpIpx2D(Iw+Ip)IwIpx4+E(Iw+Ip)IwIpu\dot{\,\,x_{4}} = -\frac{mgl}{I_{p}}x_{1} + \frac{b_{p}}{I^p}\,x_{2} - \frac{D(I_{w} + I_{p})}{I_{w}\,I_{p}}\, x_{4}+\frac{E\,(I_{w}+I_{p})}{I_{w}\,I_{p}} u

And substituting back this into the x2˙\dot{\,\,x_{2}} after some algebra we get:

x2˙=mglIpx1bpIpx2+DIpx4EIpu\dot{\,\,x_{2}} = \frac{mgl}{I_{p}}x_{1} - \frac{b_{p}}{I^p}\,x_{2} + \frac{D}{\,I_{p}}\, x_{4}-\frac{E\,}{\,I_{p}} u

Now we can write the dynamic matrix A around the equilibrium point:

A=[0100mglIpbpIp0DIp0001mglIpbpIp0D(Iw+Ip)IwIp] A = \begin{bmatrix} 0 & 1 & 0 & 0 \\ \frac{mgl}{I_{p}} & -\frac{b_{p}}{I^p} & 0 & \frac{D}{\,I_{p}} \\ 0 & 0 & 0 & 1 \\ -\frac{mgl}{I_{p}} & \frac{b_{p}}{I^p} & 0 & - \frac{D(I_{w} + I_{p})}{I_{w}\,I_{p}} \end{bmatrix}

And the B matrix:

B=[0EIp0E(Iw+Ip)IwIp]B = \begin{bmatrix} 0 \\ -\frac{E\,}{\,I_{p}} \\ 0 \\ \frac{E\,(I_{w}+I_{p})}{I_{w}\,I_{p}} \end{bmatrix}