Skip to content

Homework 1 Problem 1

abbreviations

  • c1=cos(θ1)c1 = \cos(\theta_1) | c2=cos(θ2)c2 = \cos(\theta_2) | c3=cos(θ3)c3 = \cos(\theta_3)
  • s12=sin(θ1+θ2)s_{12} = \sin(\theta_1 + \theta_2)
  • c123=cos(θ1+θ2+θ3)c_{123} = \cos(\theta_1 + \theta_2 + \theta_3)
  • c23=cos(θ2+θ3)c_{23} = \cos(\theta_2 + \theta_3)

link 1:

xc1=l12c1, yc1=l12s1vc12=(l12)2θ˙12\begin{align*} &x_{c1} = \frac{l_1}{2}c_1 ,\space y_{c1} = \frac{l_1}{2}s_1 \\ &v_{c1}^2 = (\frac{l_1}{2})^2\dot{\theta}_1^2 \end{align*}

kinetic energy

12m1vc12=18m1l1θ˙12\frac{1}{2}m_1v_{c1}^2 = \frac{1}{8} m_1 l_1\dot{\theta}_1^2

link 2:

xc2=l1c1+l22c12, yc2=l1s1+l22s12vc22=l12θ˙12+(l22)2(θ˙1+θ˙2)2+l1l2θ˙1(θ˙1+θ˙2)c2\begin{align*} &x_{c2} = l_1c_1 + \frac{l_2}{2}c_{12} ,\space y_{c2} = l_1s_1 + \frac{l_2}{2}s_{12} \\ &v_{c2}^2 = l_1^2\dot{\theta}_1^2 + (\frac{l_2}{2})^2(\dot{\theta}_1+\dot{\theta}_2)^2 + l_1l_2\dot{\theta}_1(\dot{\theta}_1+\dot{\theta}_2)c2 \end{align*}

kinetic energy

12m2vc22=12m2l12θ˙12+18m2l22(θ˙1+θ˙2)2+12m2l1l2θ˙1(θ˙1+θ˙2)c2\frac{1}{2}m_2v_{c2}^2 = \frac{1}{2}m_2l_1^2\dot{\theta}_1^2 + \frac{1}{8}m_2l_2^2(\dot{\theta}_1+\dot{\theta}_2)^2 + \frac{1}{2}m_2l_1l_2\dot{\theta}_1(\dot{\theta}_1+\dot{\theta}_2)c2

link 3:

xc3=l1c1+l2c12+l32c123yc3=l1s1+l2s12+l32s123vc32=x˙c32+y˙c32\begin{align*} x_{c3} &= l_1c_1 + l_2c_{12} + \frac{l_3}{2}c_{123} \\ y_{c3} &= l_1s_1 + l_2s_{12} + \frac{l_3}{2}s_{123} \\ v_{c3}^2 &= \dot{x}_{c3}^2 + \dot{y}_{c3}^2 \end{align*} vc32=l12q˙12+l22q˙122+(l32)2q˙1232+2l1l2q˙1q˙12c2+l2l3q˙12q˙123c3+l1l3q˙1q˙123c23v_{c3}^2 = l_1^2 \dot{q}_1^2 + l_2^2 \dot{q}_{12}^2 + (\frac{l_3}{2})^2 \dot{q}_{123}^2 + 2 l_1 l_2 \dot{q}_1 \dot{q}_{12} c_2 + l_2 l_3 \dot{q}_{12} \dot{q}_{123} c_3 + l_1 l_3 \dot{q}_1 \dot{q}_{123} c_{23}

kinetic energy

12m3vc32=12m3l12q˙12+12m3l22q˙122+18m3l32q˙1232+m3l1l2q˙1q˙12c2+12m3l2l3q˙12q˙123c3+12m3l1l3q˙1q˙123c23\frac{1}{2}m_3v_{c3}^2 = \frac{1}{2}m_3l_1^2 \dot{q}_1^2 + \frac{1}{2}m_3l_2^2 \dot{q}_{12}^2 + \frac{1}{8}m_3l_3^2 \dot{q}_{123}^2 \\ + m_3 l_1 l_2 \dot{q}_1 \dot{q}_{12} c_2 + \frac{1}{2}m_3 l_2 l_3 \dot{q}_{12} \dot{q}_{123} c_3 + \frac{1}{2}m_3 l_1 l_3 \dot{q}_1 \dot{q}_{123} c_{23}

Angular velocity: ω1=θ˙1,ω2=θ˙1+θ˙2,ω3=θ˙1+θ˙2+θ˙3\omega_1 = \dot{\theta}_1, \quad \omega_2 = \dot{\theta}_1 + \dot{\theta}_2, \quad \omega_3 = \dot{\theta}_1 + \dot{\theta}_2 + \dot{\theta}_3

I=112ml2I = \frac{1}{12}ml^2

link 1:

12I1θ˙12=124m1l12θ˙12\frac{1}{2} I_1 \dot{\theta}_1^2 = \frac{1}{24} m_1 l_1^2 \dot{\theta}_1^2

link 2:

12I2(θ˙12+θ˙22+2θ˙1θ˙2)\frac{1}{2} I_2 (\dot{\theta}_1^2 + \dot{\theta}_2^2 + 2\dot{\theta}_1\dot{\theta}_2)

link 3:

12I3(θ˙12+θ˙22+θ˙32+2θ˙1θ˙2+2θ˙2θ˙3+2θ˙1θ˙3)\frac{1}{2} I_3 (\dot{\theta}_1^2 + \dot{\theta}_2^2 + \dot{\theta}_3^2 + 2\dot{\theta}_1\dot{\theta}_2 + 2\dot{\theta}_2\dot{\theta}_3 + 2\dot{\theta}_1\dot{\theta}_3) K1=(18m1l12+124m1l12)θ˙12=16m1l12θ˙12K_1 = \left( \frac{1}{8} m_1 l_1^2 + \frac{1}{24} m_1 l_1^2 \right) \dot{\theta}_1^2 = \mathbf{\frac{1}{6} m_1 l_1^2 \dot{\theta}_1^2} K2=12m2l12θ˙12+16m2l22(θ˙1+θ˙2)2+12m2l1l2θ˙1(θ˙1+θ˙2)cosθ2K_2 = \frac{1}{2} m_2 l_1^2 \dot{\theta}_1^2 + \mathbf{\frac{1}{6} m_2 l_2^2 (\dot{\theta}_1 + \dot{\theta}_2)^2} + \frac{1}{2} m_2 l_1 l_2 \dot{\theta}_1 (\dot{\theta}_1 + \dot{\theta}_2) \cos\theta_2 K3=12m3l12θ˙12+12m3l22(θ˙1+θ˙2)2+16m3l32(θ˙1+θ˙2+θ˙3)2+m3l1l2θ˙1(θ˙1+θ˙2)cosθ2+12m3l2l3(θ˙1+θ˙2)(θ˙1+θ˙2+θ˙3)cosθ3+12m3l1l3θ˙1(θ˙1+θ˙2+θ˙3)cos(θ2+θ3)\begin{aligned} K_3 = & \frac{1}{2} m_3 l_1^2 \dot{\theta}_1^2 + \frac{1}{2} m_3 l_2^2 (\dot{\theta}_1 + \dot{\theta}_2)^2 + \mathbf{\frac{1}{6} m_3 l_3^2 (\dot{\theta}_1 + \dot{\theta}_2 + \dot{\theta}_3)^2} \\ & + m_3 l_1 l_2 \dot{\theta}_1 (\dot{\theta}_1 + \dot{\theta}_2) \cos\theta_2 \\ & + \frac{1}{2} m_3 l_2 l_3 (\dot{\theta}_1 + \dot{\theta}_2) (\dot{\theta}_1 + \dot{\theta}_2 + \dot{\theta}_3) \cos\theta_3 \\ & + \frac{1}{2} m_3 l_1 l_3 \dot{\theta}_1 (\dot{\theta}_1 + \dot{\theta}_2 + \dot{\theta}_3) \cos(\theta_2 + \theta_3) \end{aligned}

total kinetic energy K

K=D1q˙12+D2q˙122+D3q˙1232+D12c2q˙1q˙12+D23c3q˙12q˙123+D13c23q˙1q˙123K = D_1 \dot{q}_1^2 + D_2 \dot{q}_{12}^2 + D_3 \dot{q}_{123}^2 + D_{12} c_2 \dot{q}_1 \dot{q}_{12} + D_{23} c_3 \dot{q}_{12} \dot{q}_{123} + D_{13} c_{23} \dot{q}_1 \dot{q}_{123}

where,

D1=(16m1+12m2+12m3)l12D2=(16m2+12m3)l22D3=16m3l32D12=(12m2+m3)l1l2D23=12m3l2l3D13=12m3l1l3\begin{align*} D_1 &= (\frac{1}{6}m_1 + \frac{1}{2}m_2 + \frac{1}{2}m_3)l_1^2 \\ D_2 &= (\frac{1}{6}m_2 + \frac{1}{2}m_3)l_2^2 \\ D_3 &= \frac{1}{6}m_3 l_3^2 \\ D_{12} &= (\frac{1}{2}m_2 + m_3)l_1 l_2 \\ D_{23} &= \frac{1}{2}m_3 l_2 l_3 \\ D_{13} &= \frac{1}{2}m_3 l_1 l_3 \end{align*} P=12m1gl1s1P1+m2g(l1s1+12l2s12)P2+m3g(l1s1+l2s12+12l3s123)P3P = \underbrace{\frac{1}{2} m_1 g l_1 s_1}_{P_1} + \underbrace{m_2 g (l_1 s_1 + \frac{1}{2} l_2 s_{12})}_{P_2} + \underbrace{m_3 g (l_1 s_1 + l_2 s_{12} + \frac{1}{2} l_3 s_{123})}_{P_3}

L=KPL = K - P By using the partial differential equations:

τk=ddt(Lθ˙k)Lθk(k=1,2,3)\tau_k = \frac{d}{dt}\left(\frac{\partial L}{\partial \dot{\theta}_k}\right) - \frac{\partial L}{\partial \theta_k} \quad (k = 1, 2, 3)

τ3\tau_3:

Kθ˙3=Kq˙123=2D3q˙123+D23c3q˙12+D13c23q˙1\frac{\partial K}{\partial \dot{\theta}_3} = \frac{\partial K}{\partial \dot{q}_{123}} = 2 D_3 \dot{q}_{123} + D_{23} c_3 \dot{q}_{12} + D_{13} c_{23} \dot{q}_1 ddt(Kθ˙3)=2D3q¨123+D23c3q¨12+D13c23q¨1angular velocityD23s3θ˙3q˙12D13s23(θ˙2+θ˙3)q˙1v squared\frac{d}{dt}\left(\frac{\partial K}{\partial \dot{\theta}_3}\right) = \underbrace{2 D_3 \ddot{q}_{123} + D_{23} c_3 \ddot{q}_{12} + D_{13} c_{23} \ddot{q}_1}_{\text{angular velocity}} \underbrace{- D_{23} s_3 \dot{\theta}_3 \dot{q}_{12} - D_{13} s_{23} (\dot{\theta}_2 + \dot{\theta}_3) \dot{q}_1}_{\text{v squared}} Kθ3=(D23s3q˙12q˙123D13s23q˙1q˙123)=+D23s3q˙12q˙123+D13s23q˙1q˙123-\frac{\partial K}{\partial \theta_3} = -(- D_{23} s_3 \dot{q}_{12} \dot{q}_{123} - D_{13} s_{23} \dot{q}_1 \dot{q}_{123}) = + D_{23} s_3 \dot{q}_{12} \dot{q}_{123} + D_{13} s_{23} \dot{q}_1 \dot{q}_{123} τ3=2D3q¨123+D23c3q¨12+D13c23q¨1+D23s3q˙122+D13s23q˙12+G3\tau_3 = 2 D_3 \ddot{q}_{123} + D_{23} c_3 \ddot{q}_{12} + D_{13} c_{23} \ddot{q}_1 + D_{23} s_3 \dot{q}_{12}^2 + D_{13} s_{23} \dot{q}_1^2 + G_3

where,

G3=12m3gl3c123G_3 = \frac{1}{2}m_3 g l_3 c_{123}

τ2\tau_2:

Kθ˙2=Kq˙12+Kq˙123\frac{\partial K}{\partial \dot{\theta}_2} = \frac{\partial K}{\partial \dot{q}_{12}} + \frac{\partial K}{\partial \dot{q}_{123}} Kθ˙2=(2D2+D23c3)q˙12+(2D3+D23c3)q˙123+(D12c2+D13c23)q˙1\frac{\partial K}{\partial \dot{\theta}_2} = (2 D_2 + D_{23} c_3) \dot{q}_{12} + (2 D_3 + D_{23} c_3) \dot{q}_{123} + (D_{12} c_2 + D_{13} c_{23}) \dot{q}_1 ddt(Kθ˙2)=(2D2+D23c3)q¨12+(2D3+D23c3)q¨123+(D12c2+D13c23)q¨1D23s3θ˙3q˙12D23s3θ˙3q˙123D12s2θ˙2q˙1D13s23(θ˙2+θ˙3)q˙1\frac{d}{dt}\left(\frac{\partial K}{\partial \dot{\theta}_2}\right) = (2 D_2 + D_{23} c_3) \ddot{q}_{12} + (2 D_3 + D_{23} c_3) \ddot{q}_{123} + (D_{12} c_2 + D_{13} c_{23}) \ddot{q}_1 \\ - D_{23} s_3 \dot{\theta}_3 \dot{q}_{12} - D_{23} s_3 \dot{\theta}_3 \dot{q}_{123} - D_{12} s_2 \dot{\theta}_2 \dot{q}_1 - D_{13} s_{23} (\dot{\theta}_2 + \dot{\theta}_3) \dot{q}_1 Kθ2=(D12s2q˙1q˙12D13s23q˙1q˙123)=+D12s2q˙1q˙12+D13s23q˙1q˙123-\frac{\partial K}{\partial \theta_2} = -(- D_{12} s_2 \dot{q}_1 \dot{q}_{12} - D_{13} s_{23} \dot{q}_1 \dot{q}_{123}) = + D_{12} s_2 \dot{q}_1 \dot{q}_{12} + D_{13} s_{23} \dot{q}_1 \dot{q}_{123} τ2=(2D2+D23c3)q¨12+(2D3+D23c3)q¨123+(D12c2+D13c23)q¨1+D12s2q˙12+D13s23q˙12D23s3(2q˙12θ˙3+θ˙32)+G2\tau_2 = (2 D_2 + D_{23} c_3) \ddot{q}_{12} + (2 D_3 + D_{23} c_3) \ddot{q}_{123} + (D_{12} c_2 + D_{13} c_{23}) \ddot{q}_1 \\ + D_{12} s_2 \dot{q}_1^2 + D_{13} s_{23} \dot{q}_1^2 - D_{23} s_3 (2 \dot{q}_{12} \dot{\theta}_3 + \dot{\theta}_3^2) + G_2

where,

G2=(m2l22+m3l2)gc12+12m3gl3c123G_2 = (m_2 \frac{l_2}{2} + m_3 l_2)g c_{12} + \frac{1}{2}m_3 g l_3 c_{123}

τ1\tau_1:

Kθ˙1=Kq˙1+Kq˙12+Kq˙123\frac{\partial K}{\partial \dot{\theta}_1} = \frac{\partial K}{\partial \dot{q}_1} + \frac{\partial K}{\partial \dot{q}_{12}} + \frac{\partial K}{\partial \dot{q}_{123}} τ1=[(2D1+2D2+2D3)+2D12c2+2D23c3+2D13c23]θ¨1+[(2D2+2D3)+D12c2+2D23c3+D13c23]θ¨2+[2D3+D23c3+D13c23]θ¨3D12s2(2q˙1θ˙2+θ˙22)D23s3(2q˙12θ˙3+θ˙32)D13s23[2q˙1(θ˙2+θ˙3)+(θ˙2+θ˙3)2]+G1\begin{aligned} \tau_1 = & \left[ (2D_1 + 2D_2 + 2D_3) + 2D_{12}c_2 + 2D_{23}c_3 + 2D_{13}c_{23} \right] \ddot{\theta}_1 \\ & + \left[ (2D_2 + 2D_3) + D_{12}c_2 + 2D_{23}c_3 + D_{13}c_{23} \right] \ddot{\theta}_2 \\ & + \left[ 2D_3 + D_{23}c_3 + D_{13}c_{23} \right] \ddot{\theta}_3 \\ & - D_{12} s_2 (2\dot{q}_1 \dot{\theta}_2 + \dot{\theta}_2^2) - D_{23} s_3 (2\dot{q}_{12} \dot{\theta}_3 + \dot{\theta}_3^2) - D_{13} s_{23} \left[ 2\dot{q}_1 (\dot{\theta}_2+\dot{\theta}_3) + (\dot{\theta}_2+\dot{\theta}_3)^2 \right] \\ & + G_1 \end{aligned}

The inertia matrix is symmetric:

M(θ)=[M11M12M13M21M22M23M31M32M33]M(\theta) = \begin{bmatrix} M_{11} & M_{12} & M_{13} \\ M_{21} & M_{22} & M_{23} \\ M_{31} & M_{32} & M_{33} \end{bmatrix} M11=2D1+2D2+2D3+2D12cosθ2+2D23cosθ3+2D13cos(θ2+θ3)M_{11} = 2D_1 + 2D_2 + 2D_3 + 2D_{12} \cos\theta_2 + 2D_{23} \cos\theta_3 + 2D_{13} \cos(\theta_2+\theta_3) M12=2D2+2D3+D12cosθ2+2D23cosθ3+D13cos(θ2+θ3)M_{12} = 2D_2 + 2D_3 + D_{12} \cos\theta_2 + 2D_{23} \cos\theta_3 + D_{13} \cos(\theta_2+\theta_3) M13=2D3+D23cosθ3+D13cos(θ2+θ3)M_{13} = 2D_3 + D_{23} \cos\theta_3 + D_{13} \cos(\theta_2+\theta_3) M22=2D2+2D3+2D23cosθ3M_{22} = 2D_2 + 2D_3 + 2D_{23} \cos\theta_3 M23=2D3+D23cosθ3M_{23} = 2D_3 + D_{23} \cos\theta_3 M33=2D3M_{33} = 2D_3

Centrifugal force and Coriolis force vectors

Section titled “Centrifugal force and Coriolis force vectors”
V(θ,θ˙)=[V1V2V3]V(\theta, \dot{\theta}) = \begin{bmatrix} V_1 \\ V_2 \\ V_3 \end{bmatrix} V1=D12sinθ2(2q˙1θ˙2+θ˙22)D23sinθ3(2q˙12θ˙3+θ˙32)D13sin(θ2+θ3)[2q˙1(θ˙2+θ˙3)+(θ˙2+θ˙3)2]V_1 = - D_{12} \sin\theta_2 (2\dot{q}_1 \dot{\theta}_2 + \dot{\theta}_2^2) - D_{23} \sin\theta_3 (2\dot{q}_{12} \dot{\theta}_3 + \dot{\theta}_3^2) \\ - D_{13} \sin(\theta_2+\theta_3) \left[ 2\dot{q}_1 (\dot{\theta}_2+\dot{\theta}_3) + (\dot{\theta}_2+\dot{\theta}_3)^2 \right] V2=D12sinθ2q˙12+D13sin(θ2+θ3)q˙12D23sinθ3(2q˙12θ˙3+θ˙32)V_2 = D_{12} \sin\theta_2 \dot{q}_1^2 + D_{13} \sin(\theta_2+\theta_3) \dot{q}_1^2 - D_{23} \sin\theta_3 (2 \dot{q}_{12} \dot{\theta}_3 + \dot{\theta}_3^2) V3=D23sinθ3q˙122+D13sin(θ2+θ3)q˙12V_3 = D_{23} \sin\theta_3 \dot{q}_{12}^2 + D_{13} \sin(\theta_2+\theta_3) \dot{q}_1^2 G(θ)=[G1G2G3]G(\theta) = \begin{bmatrix} G_1 \\ G_2 \\ G_3 \end{bmatrix} G1=(12m1+m2+m3)gl1c1+(12m2+m3)gl2c12+12m3gl3c123G_1 = (\frac{1}{2}m_1 + m_2 + m_3)g l_1 c_{1} + (\frac{1}{2}m_2 + m_3)g l_2 c_{12} + \frac{1}{2}m_3 g l_3 c_{123} G2=(12m2+m3)gl2c12+12m3gl3c123G_2 = (\frac{1}{2}m_2 + m_3)g l_2 c_{12} + \frac{1}{2}m_3 g l_3 c_{123} G3=12m3gl3c123G_3 = \frac{1}{2}m_3 g l_3 c_{123}

2. Task-Space PD Control with Gravity Compensation

Section titled “2. Task-Space PD Control with Gravity Compensation”

m1=m2=m3=1kgm_1=m_2=m_3=1 kg and l1=l2=l3=0.3ml_1=l_2=l_3=0.3 m so that:

x=l1c1+l2c12+l3c123 x = l_1c_{1} + l_2c_{12} + l_3c_{123} y=l1s1+l2s12+l3s123 y = l_1s_{1} + l_2s_{12} + l_3s_{123}
J=[l1s1l2s12l3s123l2s12l3s123l3s123l1c1+l2c12+l3c123l2c12+l3c123l3c123]J = \begin{bmatrix} -l_1s_{1} - l_2s_{12} - l_3s_{123} & -l_2s_{12} - l_3s_{123} & -l_3s_{123} \\ l_1c_{1} + l_2c_{12} + l_3c_{123} & l_2c_{12} + l_3c_{123} & l_3c_{123} \end{bmatrix}
x˙=Jq˙\dot{\mathbf{x}} = J\dot{\mathbf{q}}

Position error:

e=[xdyd][xy]\mathbf{e} = \begin{bmatrix} x_d \\ y_d \end{bmatrix} - \begin{bmatrix} x \\ y \end{bmatrix}

Velocity error:

e˙=[x˙dy˙d]x˙\dot{\mathbf{e}} = \begin{bmatrix} \dot{x}_d \\ \dot{y}_d \end{bmatrix} - \dot{\mathbf{x}}

Control force:

F=Kpe+Kde˙\mathbf{F} = K_p \mathbf{e} + K_d \dot{\mathbf{e}} M(q)q¨+C(q,q˙)q˙+Fq˙+g(q)=τM(q)\ddot{q} + C(q,\dot{q})\dot{q} + F\dot{q} + g(q) = \tau τ=JTF+Fq˙+g(q)\tau = J^{T}\mathbf{F} + F\dot{q} + g(q) q¨=M1(JTFV)\ddot{\mathbf{q}} = M^{-1} \left( J^{T}\mathbf{F} - \mathbf{V} \right)

where:

  • MM : manipulator inertia matrix
  • JJ : manipulator Jacobian
  • F\mathbf{F} : task-space control force
  • V\mathbf{V} : gravity / nonlinear dynamics term
  • q¨\ddot{\mathbf{q}} : joint acceleration vector
function [ddq,x,y] = pd_gravity(q, dq, tosim, t)
% parameters
m1 = tosim(1);
m2 = tosim(2);
m3 = tosim(3);
l1 = tosim(4);
l2 = tosim(5);
l3 = tosim(6);
xc = tosim(7);
yc = tosim(8);
r = tosim(9);
w = tosim(10);
kp = tosim(11);
% task-space gains, 2x2
Kp = kp*eye(2);
Kd = 2*sqrt(kp)*eye(2);
th1 = q(1);
th2 = q(2);
th3 = q(3);
dth1 = dq(1);
dth2 = dq(2);
dth3 = dq(3);
dq1 = dth1;
dq12 = dth1 + dth2;
% desired end-effector trajectory
xd = xc + r*cos(w*t);
yd = yc + r*sin(w*t);
dxd = -r*w*sin(w*t);
dyd = r*w*cos(w*t);
% current end-effector position
x = l1*cos(th1) + l2*cos(th1+th2) + l3*cos(th1+th2+th3);
y = l1*sin(th1) + l2*sin(th1+th2) + l3*sin(th1+th2+th3);
% manipulator Jacobian
J = [-l1*sin(th1)-l2*sin(th1+th2)-l3*sin(th1+th2+th3), ...
-l2*sin(th1+th2)-l3*sin(th1+th2+th3), ...
-l3*sin(th1+th2+th3);
l1*cos(th1)+l2*cos(th1+th2)+l3*cos(th1+th2+th3), ...
l2*cos(th1+th2)+l3*cos(th1+th2+th3), ...
l3*cos(th1+th2+th3)];
% current task-space velocity
dxy = J*dq;
% task-space PD
e = [xd; yd] - [x; y];
de = [dxd; dyd] - dxy;
F = Kp*e + Kd*de;
% Dynamics parameters
D1 = m1*l1^2/6 + (m2 + m3)*l1^2/2;
D2 = m2*l2^2/6 + m3*l2^2/2;
D3 = m3*l3^2/6;
D12 = (m2/2 + m3)*l1*l2;
D23 = m3*l2*l3/2;
D13 = m3*l1*l3/2;
c2 = cos(th2);
c3 = cos(th3);
c23 = cos(th2 + th3);
s2 = sin(th2);
s3 = sin(th3);
s23 = sin(th2 + th3);
M11 = 2*D1 + 2*D2 + 2*D3 ...
+ 2*D12*c2 + 2*D23*c3 + 2*D13*c23;
M12 = 2*D2 + 2*D3 ...
+ D12*c2 + 2*D23*c3 + D13*c23;
M13 = 2*D3 + D23*c3 + D13*c23;
M22 = 2*D2 + 2*D3 + 2*D23*c3;
M23 = 2*D3 + D23*c3;
M33 = 2*D3;
M = [M11 M12 M13;
M12 M22 M23;
M13 M23 M33];
V1 = -D12*s2*(2*dq1*dth2 + dth2^2) ...
-D23*s3*(2*dq12*dth3 + dth3^2) ...
-D13*s23*(2*dq1*(dth2 + dth3) + (dth2 + dth3)^2);
V2 = D12*s2*dq1^2 ...
+ D13*s23*dq1^2 ...
- D23*s3*(2*dq12*dth3 + dth3^2);
V3 = D23*s3*dq12^2 ...
+ D13*s23*dq1^2;
V = [V1; V2; V3];
% task-space PD with gravity compensation
ddq = M \ (J' * F - V);
end

End-effector position: "Position of end-effector" Start position: "3 link movement." Stable trajectory:

"Position of end-effector" "Position of end-effector" GIF: "Position of end-effector"

"Simulink"

Define the task space trajectory, end-effector is in Cartesian plane over time:

  • Desired Position: Xd(t)=[xd(t),yd(t),ϕd(t)]TX_d(t) = [x_d(t), y_d(t), \phi_d(t)]^T
  • Desired Velocity: X˙d(t)=[x˙d(t),y˙d(t),ϕ˙d(t)]T\dot{X}_d(t) = [\dot{x}_d(t), \dot{y}_d(t), \dot{\phi}_d(t)]^T

At every time step of the control loop, feed the desired Cartesian position Xd(t)X_d(t) into the analytical geometric Inverse Kinematics equations. For a 3-Dof planar arm, this maps (x,y)(x,y) coordinate and orientation angle θ\theta back to the specific joint angles:

qd(t)=IK(Xd(t))q_d(t) = \text{IK}(X_d(t))

Use Jacobian matrix J(q)J(q) to get teh target joint velocities(q˙d\dot{q}_d) without introducing numerical lag from finite-differencing qdq_d.

X˙=J(q)q˙\dot{X} = J(q)\dot{q} q˙d(t)=J1(qd)X˙d(t)\dot{q}_d(t) = J^{-1}(q_d) \dot{X}_d(t)

Then feed into the existing joint space controller.

τ=Kp(qd(t)q)+Kd(q˙d(t)q˙)+G(q)\tau = K_p (q_d(t) - q) + K_d (\dot{q}_d(t) - \dot{q}) + G(q)