<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Preamble stuff (can ignore)
Step1:  Model the Cab as a Cube 
Step2:  Model the Links as Thin Rods
Step3:  Rotate the MOI matrix of $m_1$ into frame $\mathcal{A}$
Step4:  Apply parallel axis theorem to find MOI of $m_1$ about $O$
Step5:  $\left[\mathbb{I}{G_2}^{m_2}\right]\mathcal{C}=$
Step6:  Rotate the MOI matrix of $m_2$ into frame $\mathcal{A}$
Step7:  Simplify by defining $\theta_2 \triangleq \beta - \theta_1$
Step8:  Apply parallel axis theorem to find MOI of $m_2$ about $O$
Step9:  Total Moment of Inertia is the sum of the 3 Moment of Inertia matrices
$\left[\mathbb{I}{O}\right]\mathcal{A} =\left[\mathbb{I}{O}^{m_1}\right]\mathcal{A}+\left[\mathbb{I}{O}^{m_2}\right]\mathcal{A} + \left[\mathbb{I}{O}^{\textrm{cab}}\right]\mathcal{A}$
<ASSISTANT_TASK:>
Python Code:
from miscpy.utils.sympyhelpers import *
init_printing()
M,h,m1,m2,th1,th2,b,l1,l2 = \
symbols('M,h,m_1,m_2,theta_1,theta_2,beta,l_1,l_2')
Explanation: Preamble stuff (can ignore)
End of explanation
I_O_cab = M*2/3*h**2/4*eye(3); I_O_cab
Explanation: Model the Cab as a Cube : $\left[\mathbb{I}O^\textrm{cab}\right]\mathcal{A}=$
End of explanation
I_G1_m1_B = m1*l1**2/12*(eye(3) - diag(1,0,0)); I_G1_m1_B
Explanation: Model the Links as Thin Rods:
$\left[\mathbb{I}{G_1}^{m_1}\right]\mathcal{B}=$
End of explanation
aCb = Matrix(([cos(th1),-sin(th1),0],[sin(th1),cos(th1),0],[0,0,1])); aCb
I_G1_m1_A = aCb*I_G1_m1_B*aCb.transpose(); I_G1_m1_A
Explanation: Rotate the MOI matrix of $m_1$ into frame $\mathcal{A}$:
$\left[\mathbb{I}{G_1}^{m_1}\right]\mathcal{A}= {}^{\mathcal A}{C}^\mathcal B\left[\mathbb{I}{G_1}^{m_1}\right]\mathcal{B}{}^{\mathcal B}{C}^\mathcal A$
End of explanation
r_O_G1 = aCb*Matrix([-l1/2,0,0]) + Matrix([-h/2,0,0]); r_O_G1
I_O_m1_A = simplify(I_G1_m1_A + m1*((r_O_G1.transpose()*r_O_G1)[0]*eye(3) - r_O_G1*r_O_G1.transpose())); I_O_m1_A
Explanation: Apply parallel axis theorem to find MOI of $m_1$ about $O$:
$\left[\mathbb{I}{O}^{m_1}\right]\mathcal{A} =\left[\mathbb{I}{G_1}^{m_1}\right]\mathcal{A} + m_1(\Vert \mathbf{r}{O/G_1}\Vert^2 I - \left[\mathbf{r}{O/G_1}\right]\mathcal{A}\left[\mathbf{r}{O/G_1}\right]_\mathcal{A}^T)$
$\mathbf{r}_{O/G_1} = -\frac{l_1}{2}\mathbf{b_1}  -\frac{h}{2}\mathbf{a_1} $
End of explanation
I_G2_m2_C = m2*l2**2/12*(eye(3) - diag(1,0,0)); I_G2_m2_C
Explanation: $\left[\mathbb{I}{G_2}^{m_2}\right]\mathcal{C}=$
End of explanation
bCc = Matrix(([cos(b),sin(b),0],[-sin(b),cos(b),0],[0,0,1])); bCc
aCc = simplify(aCb*bCc); aCc
Explanation: Rotate the MOI matrix of $m_2$ into frame $\mathcal{A}$:
${}^{\mathcal A}{C}^\mathcal C = {}^{\mathcal A}{C}^\mathcal B {}^{\mathcal B}{C}^\mathcal c$
$\left[\mathbb{I}{G_2}^{m_2}\right]\mathcal{A}= {}^{\mathcal A}{C}^\mathcal C\left[\mathbb{I}{G_2}^{m_2}\right]\mathcal{C}{}^{\mathcal C}{C}^\mathcal A$
End of explanation
aCc = aCc.subs(b-th1,th2); aCc
I_G2_m2_A = aCc*I_G2_m2_C*aCc.transpose(); I_G2_m2_A
Explanation: Simplify by defining $\theta_2 \triangleq \beta - \theta_1$
End of explanation
r_O_G2 = aCc*Matrix([-l2/2,0,0]) + aCb*Matrix([-l1,0,0]) + Matrix([-h/2,0,0]); r_O_G2
I_O_m2_A = simplify(I_G2_m2_A + m2*((r_O_G2.transpose()*r_O_G2)[0]*eye(3) - r_O_G2*r_O_G2.transpose())); I_O_m2_A
Explanation: Apply parallel axis theorem to find MOI of $m_2$ about $O$:
$\left[\mathbb{I}{O}^{m_2}\right]\mathcal{A} =\left[\mathbb{I}{G_2}^{m_2}\right]\mathcal{A}+ m_2(\Vert \mathbf{r}{O/G_2}\Vert^2 I - \left[\mathbf{r}{O/G_2}\right]\mathcal{A}\left[\mathbf{r}{O/G_2}\right]_\mathcal{A}^T)$
$\mathbf{r}_{O/G_2} = -\frac{l_2}{2}\mathbf{c_1} - l_1 \mathbf{b_1} -\frac{h}{2}\mathbf{a_1} $
End of explanation
I_O_A = simplify(I_O_cab + I_O_m1_A + I_O_m2_A); I_O_A
Explanation: Total Moment of Inertia is the sum of the 3 Moment of Inertia matrices
$\left[\mathbb{I}{O}\right]\mathcal{A} =\left[\mathbb{I}{O}^{m_1}\right]\mathcal{A}+\left[\mathbb{I}{O}^{m_2}\right]\mathcal{A} + \left[\mathbb{I}{O}^{\textrm{cab}}\right]\mathcal{A}$
End of explanation
<END_TASK>