# Robotic Mechanics and Modeling/Dynamics

## Dynamics

The study of dynamics requires that we extend kinematic equations for a system to account for balances of loads or energy to model motion dependent on inertia, loading, energy-storage elements, and energy-dissipating elements.

## Simple Swinging Rod (Pendulum) Under Gravity

For the figure shown, we can write the kinematic equations as:

${\displaystyle x_{P}=L\cos \theta }$

${\displaystyle y_{P}=L\sin \theta }$

The equation of motion for this 2nd-order ordinary differential equation (ODE) is:

${\displaystyle {\ddot {\theta }}+{\frac {3g}{2L}}\sin \theta =0}$

For small angles of displacement, we have:${\displaystyle {\ddot {\theta }}+{\frac {3g}{2L}}\theta =0}$

Using the standard form ${\displaystyle {\ddot {\theta }}+2\zeta \omega _{n}{\dot {\theta }}+\omega _{n}^{2}\theta =0}$  for 2nd-order ODEs, we can determine the natural frequency (rad/s) for small angles to be the following:

${\displaystyle \omega _{n}={\sqrt {\frac {3g}{2L}}}}$

For small angles, we can also write and verify a hypothetical solution of the form:

${\displaystyle \theta =A\sin(\omega t+\phi )}$

where ${\displaystyle A}$  is an amplitude, ${\displaystyle t}$  is time, and ${\displaystyle \phi }$  is a phase angle. Substituting this hypothetical solution into the equation of motion for small angles, we can also determine the natural frequency ${\displaystyle \omega _{n}}$  while also determining responses to initial conditions for initial conditions.

For example, for an initial small angle ${\displaystyle \theta _{0}}$  with zero initial velocity at ${\displaystyle t=0}$ , we have the following:

${\displaystyle \theta =\theta _{0}\sin(\omega _{n}t+\pi /2)}$

If we want to know the angular velocity or angular acceleration, we have only to differentiate:

${\displaystyle {\dot {\theta }}=\theta _{0}\omega _{n}\cos(\omega _{n}t+\pi /2)}$

${\displaystyle {\ddot {\theta }}=-\theta _{0}\omega _{n}^{2}\sin(\omega _{n}t+\pi /2)}$

Code
%reset -f
import numpy as np
import matplotlib
import matplotlib.pyplot as plt

theta0=0.1;
g=9.8 # m/s^2
L=3*g/(8*np.pi**2)
omega_n=np.sqrt(3*g/(2*L))
phi=np.pi/2;
num_periods=3
t=np.linspace(0,num_periods*2*np.pi/omega_n,num=100)
theta=theta0*np.sin(omega_n*t+phi)

fig=plt.figure()
plt.plot(t,theta,'bo-')
ax.set_xlim([0, num_periods*2*np.pi/omega_n])
ax.set_ylim([-theta0, theta0])
ax.set_ylabel('Theta',size=12)
ax.set_autoscale_on(False)
ax.set_title('Omega_n= '+str(np.round(2*np.pi/omega_n,1))+
' s; Theta_0='+str(np.round(theta0,1)))
ax.set_xlim([0, num_periods*2*np.pi/omega_n])
ax.set_ylim([-theta0*omega_n, theta0*omega_n])
ax.set_xlabel('Time (s)',size=12)
ax.set_autoscale_on(False)
ax.set_xlabel('Time (s)',size=12)
ax.set_xlim([0, num_periods*2*np.pi/omega_n])
ax.set_ylim([-theta0*omega_n**2, theta0*omega_n**2])
ax.set_xlabel('Time (s)',size=12)
ax.set_autoscale_on(False)
ax.set_xlabel('Time (s)',size=12)

plt.savefig('Theta_for_rod_pendulum_200303.png',dpi=300, bbox_inches='tight')

## Use of Denavit and Hartenberg matrices (Copied from Link)

The Denavit and Hartenberg notation gives a standard methodology to write the kinematic equations of a manipulator. This is especially useful for serial manipulators where a matrix is used to represent the pose (position and orientation) of one body with respect to another. See paper1 and paper2.

The position of body ${\displaystyle n}$  with respect to ${\displaystyle n-1}$  may be represented by a position matrix indicated with the symbol ${\displaystyle T}$  or ${\displaystyle M}$

${\displaystyle \operatorname {} _{n-1}^{n}T=M_{n-1,n}}$

This matrix is also used to transform a point from frame ${\displaystyle n}$  to ${\displaystyle n-1}$

${\displaystyle M_{n-1,n}=\left[{\begin{array}{ccc|c}R_{xx}&R_{xy}&R_{xz}&T_{x}\\R_{yx}&R_{yy}&R_{yz}&T_{y}\\R_{zx}&R_{zy}&R_{zz}&T_{z}\\\hline 0&0&0&1\end{array}}\right]}$

Where the upper left ${\displaystyle 3\times 3}$  submatrix of ${\displaystyle M}$  represents the relative orientation of the two bodies, and the upper right ${\displaystyle 3\times 1}$  represents their relative position or more specifically the body position in frame n − 1 represented with element of frame n.

The position of body ${\displaystyle k}$  with respect to body ${\displaystyle i}$  can be obtained as the product of the matrices representing the pose of ${\displaystyle j}$  with respect of ${\displaystyle i}$  and that of ${\displaystyle k}$  with respect of ${\displaystyle j}$

${\displaystyle M_{i,k}=M_{i,j}M_{j,k}}$

An important property of Denavit and Hartenberg matrices is that the inverse is

${\displaystyle M^{-1}=\left[{\begin{array}{ccc|c}&&&\\&R^{T}&&-R^{T}T\\&&&\\\hline 0&0&0&1\end{array}}\right]}$

where ${\displaystyle R^{T}}$  is both the transpose and the inverse of the orthogonal matrix ${\displaystyle R}$ , i.e. ${\displaystyle R_{ij}^{-1}=R_{ij}^{T}=R_{ji}}$ .

Further matrices can be defined to represent velocity and acceleration of bodies.[1][2] The velocity of body ${\displaystyle i}$  with respect to body ${\displaystyle j}$  can be represented in frame ${\displaystyle k}$  by the matrix

${\displaystyle W_{i,j(k)}=\left[{\begin{array}{ccc|c}0&-\omega _{z}&\omega _{y}&v_{x}\\\omega _{z}&0&-\omega _{x}&v_{y}\\-\omega _{y}&\omega _{x}&0&v_{z}\\\hline 0&0&0&0\end{array}}\right]}$

where ${\displaystyle \omega }$  is the angular velocity of body ${\displaystyle j}$  with respect to body ${\displaystyle i}$  and all the components are expressed in frame ${\displaystyle k}$ ; ${\displaystyle v}$  is the velocity of one point of body ${\displaystyle j}$  with respect to body ${\displaystyle i}$  (the pole). The pole is the point of ${\displaystyle j}$  passing through the origin of frame ${\displaystyle i}$ .

The acceleration matrix can be defined as the sum of the time derivative of the velocity plus the velocity squared

${\displaystyle H_{i,j(k)}={\dot {W}}_{i,j(k)}+W_{i,j(k)}^{2}}$

The velocity and the acceleration in frame ${\displaystyle i}$  of a point of body ${\displaystyle j}$  can be evaluated as

${\displaystyle {\dot {P}}=W_{i,j}P}$
${\displaystyle {\ddot {P}}=H_{i,j}P}$

It is also possible to prove that

${\displaystyle {\dot {M}}_{i,j}=W_{i,j(i)}M_{i,j}}$
${\displaystyle {\ddot {M}}_{i,j}=H_{i,j(i)}M_{i,j}}$

Velocity and acceleration matrices add up according to the following rules

${\displaystyle W_{i,k}=W_{i,j}+W_{j,k}}$
${\displaystyle H_{i,k}=H_{i,j}+H_{j,k}+2W_{i,j}W_{j,k}}$

in other words the absolute velocity is the sum of the parent velocity plus the relative velocity; for the acceleration the Coriolis' term is also present.

The components of velocity and acceleration matrices are expressed in an arbitrary frame ${\displaystyle k}$  and transform from one frame to another by the following rule

${\displaystyle W_{(h)}=M_{h,k}W_{(k)}M_{k,h}}$
${\displaystyle H_{(h)}=M_{h,k}H_{(k)}M_{k,h}}$

For the dynamics three further matrices are necessary to describe the inertia ${\displaystyle J}$ , the linear and angular momentum ${\displaystyle \Gamma }$ , and the forces and torques ${\displaystyle \Phi }$  applied to a body.

Inertia ${\displaystyle J}$ :

${\displaystyle J=\left[{\begin{array}{ccc|c}I_{xx}&I_{xy}&I_{xz}&x_{g}m\\I_{yx}&I_{yy}&I_{yz}&y_{g}m\\I_{zx}&I_{zy}&I_{zz}&z_{g}m\\\hline x_{g}m&y_{g}m&z_{g}m&m\end{array}}\right]}$

where ${\displaystyle m}$  is the mass, ${\displaystyle x_{g},\,y_{g},\,z_{g}}$  represent the position of the center of mass, and the terms ${\displaystyle I_{xx},\,I_{xy},\ldots }$  represent inertia and are defined as

${\displaystyle I_{xx}=\iint x^{2}\,dm}$
{\displaystyle {\begin{aligned}I_{xy}&=\iint xy\,dm\\I_{xz}&=\cdots \\&\,\,\,\vdots \end{aligned}}}

Action matrix ${\displaystyle \Phi }$ , containing force ${\displaystyle f}$  and torque ${\displaystyle t}$ :

${\displaystyle \Phi =\left[{\begin{array}{ccc|c}0&-t_{z}&t_{y}&f_{x}\\t_{z}&0&-t_{x}&f_{y}\\-t_{y}&t_{x}&0&f_{z}\\\hline -f_{x}&-f_{y}&-f_{z}&0\end{array}}\right]}$

Momentum matrix ${\displaystyle \Gamma }$ , containing linear ${\displaystyle \rho }$  and angular ${\displaystyle \gamma }$  momentum

${\displaystyle \Gamma =\left[{\begin{array}{ccc|c}0&-\gamma _{z}&\gamma _{y}&\rho _{x}\\\gamma _{z}&0&-\gamma _{x}&\rho _{y}\\-\gamma _{y}&\gamma _{x}&0&\rho _{z}\\\hline -\rho _{x}&-\rho _{y}&-\rho _{z}&0\end{array}}\right]}$

All the matrices are represented with the vector components in a certain frame ${\displaystyle k}$ . Transformation of the components from frame ${\displaystyle k}$  to frame ${\displaystyle h}$  follows the rule

{\displaystyle {\begin{aligned}J_{(h)}&=M_{h,k}J_{(k)}M_{h,k}^{T}\\\Gamma _{(h)}&=M_{h,k}\Gamma _{(k)}M_{h,k}^{T}\\\Phi _{(h)}&=M_{h,k}\Phi _{(k)}M_{h,k}^{T}\end{aligned}}}

The matrices described allow the writing of the dynamic equations in a concise way.

Newton's law:

${\displaystyle \Phi _{k(0)}=H_{0,k}J_{k(0)}-J_{k(0)}H_{0,k}^{T}\,}$

Momentum:

${\displaystyle \Gamma _{k}=W_{k}J_{k}-J_{k}W_{k}^{T}\,}$

The first of these equations express the Newton's law and is the equivalent of the vector equation ${\displaystyle f=ma}$  (force equal mass times acceleration) plus ${\displaystyle t=J{\dot {\omega }}+\omega \times J\omega }$  (angular acceleration in function of inertia and angular velocity); the second equation permits the evaluation of the linear and angular momentum when velocity and inertia are known.

## Denavit and Hartenberg Matrices Applied to a Single Pendulum

For a single pendulum, we can write out the D-H transformation matrix is as follows:${\displaystyle _{0}^{1}T=M_{0,1}\left[{\begin{array}{ccc|c}\cos \theta _{1}&-\sin \theta _{1}&0&a_{1}\cos \theta _{1}\\\sin \theta _{1}&\cos \theta _{1}&0&a_{1}\sin \theta _{1}\\0&0&1&0\\\hline 0&0&0&1\end{array}}\right]}$

where "body" 0 is the ground reference frame and body 1 is link 1.

The velocity matrix of body 1 with respect to the ground reference frame is:

${\displaystyle W_{0,1(0)}=\left[{\begin{array}{ccc|c}0&-{\dot {\theta }}_{1}&0&-{\dot {\theta }}_{1}a_{1}\sin \theta _{1}\\{\dot {\theta }}_{1}&0&0&{\dot {\theta }}_{1}a_{1}\cos \theta _{1}\\0&0&0&0\\\hline 0&0&0&0\end{array}}\right]}$

The acceleration matrix of body 1 with respect to the ground reference frame becomes:

${\displaystyle H_{0,1(0)}={\dot {W}}_{0,1(0)}+W_{0,1(0)}^{2}=\left[{\begin{array}{ccc|c}0&-{\ddot {\theta }}_{1}&0&0\\{\ddot {\theta }}_{1}&0&0&0\\0&0&0&0\\\hline 0&0&0&0\end{array}}\right]+\left[{\begin{array}{ccc|c}-{\dot {\theta }}_{1}^{2}&0&0&0\\0&-{\dot {\theta }}_{1}^{2}&0&0\\0&0&0&0\\\hline 0&0&0&0\end{array}}\right]}$

We can describe the inertia ${\displaystyle J_{1}}$  with the following matrix:

${\displaystyle J_{1(1)}=\left[{\begin{array}{ccc|c}0&0&0&-{\frac {1}{2}}mL\ \\0&0&0&0\\0&0&{\frac {1}{12}}mL^{2}&0\\\hline -{\frac {1}{2}}mL\ &0&0&m\end{array}}\right]}$

We can express an action matrix ${\displaystyle \Phi _{1}}$ :

${\displaystyle \Phi _{1(1)}=\left[{\begin{array}{ccc|c}0&0&0&-F_{base}\ \\0&0&0&-mg\sin \theta _{1}\\0&0&0&0\\\hline F_{base}&mg\sin \theta _{1}&0&0\end{array}}\right]}$

where ${\displaystyle F_{base}={\frac {1}{2}}mL{\dot {\theta }}_{1}^{2}-mg\cos \theta _{1}}$  to account for both the centripetal acceleration of the rod and the weight of the bar.

Using Newton's Law in the form ${\displaystyle \Phi _{k(0)}=H_{0,k}J_{k(0)}-J_{k(0)}H_{0,k}^{T}\,}$ , we should arrive at the following:

## Double Pendulum as a Model System (Pasted Material[3])

In physics and mathematics, in the area of dynamical systems, a double pendulum is a pendulum with another pendulum attached to its end, and is a simple physical system that exhibits rich dynamic behavior with a strong sensitivity to initial conditions.[4] The motion of a double pendulum is governed by a set of coupled ordinary differential equations and is chaotic.

## Analysis and interpretation

Several variants of the double pendulum may be considered; the two limbs may be of equal or unequal lengths and masses, they may be simple pendulums or compound pendulums (also called complex pendulums) and the motion may be in three dimensions or restricted to the vertical plane. In the following analysis, the limbs are taken to be identical compound pendulums of length l and mass m, and the motion is restricted to two dimensions.

In a compound pendulum, the mass is distributed along its length. If the mass is evenly distributed, then the center of mass of each limb is at its midpoint, and the limb has a moment of inertia of I = 1/12ml2 about that point.

It is convenient to use the angles between each limb and the vertical as the generalized coordinates defining the configuration of the system. These angles are denoted θ1 and θ2. The position of the center of mass of each rod may be written in terms of these two coordinates. If the origin of the Cartesian coordinate system is taken to be at the point of suspension of the first pendulum, then the center of mass of this pendulum is at:

{\displaystyle {\begin{aligned}x_{1}&={\frac {l}{2}}\sin \theta _{1}\\y_{1}&=-{\frac {l}{2}}\cos \theta _{1}\end{aligned}}}

and the center of mass of the second pendulum is at

{\displaystyle {\begin{aligned}x_{2}&=l\left(\sin \theta _{1}+{\tfrac {1}{2}}\sin \theta _{2}\right)\\y_{2}&=-l\left(\cos \theta _{1}+{\tfrac {1}{2}}\cos \theta _{2}\right)\end{aligned}}}

This is enough information to write out the Lagrangian.

### Lagrangian

The Lagrangian is

{\displaystyle {\begin{aligned}L&={\text{kinetic energy}}-{\text{potential energy}}\\&={\tfrac {1}{2}}m\left(v_{1}^{2}+v_{2}^{2}\right)+{\tfrac {1}{2}}I\left({{\dot {\theta }}_{1}}^{2}+{{\dot {\theta }}_{2}}^{2}\right)-mg\left(y_{1}+y_{2}\right)\\&={\tfrac {1}{2}}m\left({{\dot {x}}_{1}}^{2}+{{\dot {y}}_{1}}^{2}+{{\dot {x}}_{2}}^{2}+{{\dot {y}}_{2}}^{2}\right)+{\tfrac {1}{2}}I\left({{\dot {\theta }}_{1}}^{2}+{{\dot {\theta }}_{2}}^{2}\right)-mg\left(y_{1}+y_{2}\right)\end{aligned}}}

The first term is the linear kinetic energy of the center of mass of the bodies and the second term is the rotational kinetic energy around the center of mass of each rod. The last term is the potential energy of the bodies in a uniform gravitational field. The dot-notation indicates the time derivative of the variable in question.

Substituting the coordinates above and rearranging the equation gives

${\displaystyle L={\tfrac {1}{6}}ml^{2}\left({{\dot {\theta }}_{2}}^{2}+4{{\dot {\theta }}_{1}}^{2}+3{{\dot {\theta }}_{1}}{{\dot {\theta }}_{2}}\cos(\theta _{1}-\theta _{2})\right)+{\tfrac {1}{2}}mgl\left(3\cos \theta _{1}+\cos \theta _{2}\right).}$

There is only one conserved quantity (the energy), and no conserved momenta. The two momenta may be written as

{\displaystyle {\begin{aligned}p_{\theta _{1}}&={\frac {\partial L}{\partial {{\dot {\theta }}_{1}}}}={\tfrac {1}{6}}ml^{2}\left(8{{\dot {\theta }}_{1}}+3{{\dot {\theta }}_{2}}\cos(\theta _{1}-\theta _{2})\right)\\p_{\theta _{2}}&={\frac {\partial L}{\partial {{\dot {\theta }}_{2}}}}={\tfrac {1}{6}}ml^{2}\left(2{{\dot {\theta }}_{2}}+3{{\dot {\theta }}_{1}}\cos(\theta _{1}-\theta _{2})\right).\end{aligned}}}

These expressions may be inverted to get

{\displaystyle {\begin{aligned}{{\dot {\theta }}_{1}}&={\frac {6}{ml^{2}}}{\frac {2p_{\theta _{1}}-3\cos(\theta _{1}-\theta _{2})p_{\theta _{2}}}{16-9\cos ^{2}(\theta _{1}-\theta _{2})}}\\{{\dot {\theta }}_{2}}&={\frac {6}{ml^{2}}}{\frac {8p_{\theta _{2}}-3\cos(\theta _{1}-\theta _{2})p_{\theta _{1}}}{16-9\cos ^{2}(\theta _{1}-\theta _{2})}}.\end{aligned}}}

The remaining equations of motion are written as

{\displaystyle {\begin{aligned}{{\dot {p}}_{\theta _{1}}}&={\frac {\partial L}{\partial \theta _{1}}}=-{\tfrac {1}{2}}ml^{2}\left({{\dot {\theta }}_{1}}{{\dot {\theta }}_{2}}\sin(\theta _{1}-\theta _{2})+3{\frac {g}{l}}\sin \theta _{1}\right)\\{{\dot {p}}_{\theta _{2}}}&={\frac {\partial L}{\partial \theta _{2}}}=-{\tfrac {1}{2}}ml^{2}\left(-{{\dot {\theta }}_{1}}{{\dot {\theta }}_{2}}\sin(\theta _{1}-\theta _{2})+{\frac {g}{l}}\sin \theta _{2}\right).\end{aligned}}}

These last four equations are explicit formulas for the time evolution of the system given its current state. It is not possible to go further and integrate these equations analytically, to get formulas for θ1 and θ2 as functions of time. It is, however, possible to perform this integration numerically using the Runge Kutta method or similar techniques.

## Chaotic motion

The double pendulum undergoes chaotic motion, and shows a sensitive dependence on initial conditions. The image to the right shows the amount of elapsed time before the pendulum flips over, as a function of initial position when released at rest. Here, the initial value of θ1 ranges along the x-direction from −3 to 3. The initial value θ2 ranges along the y-direction, from −3 to 3. The colour of each pixel indicates whether either pendulum flips within:

• 10lg (green)
• 100lg (red)
• 1000lg (purple) or
• 10000lg (blue).

Initial conditions that do not lead to a flip within 10000lg are plotted white.

The boundary of the central white region is defined in part by energy conservation with the following curve:

${\displaystyle 3\cos \theta _{1}+\cos \theta _{2}=2.}$

Within the region defined by this curve, that is if

${\displaystyle 3\cos \theta _{1}+\cos \theta _{2}>2,}$

then it is energetically impossible for either pendulum to flip. Outside this region, the pendulum can flip, but it is a complex question to determine when it will flip. Similar behavior is observed for a double pendulum composed of two point masses rather than two rods with distributed mass.[5]

The lack of a natural excitation frequency has led to the use of double pendulum systems in seismic resistance designs in buildings, where the building itself is the primary inverted pendulum, and a secondary mass is connected to complete the double pendulum.