Open diegoferigo opened 5 years ago
@diegoferigo what are the above equations needed for?
@DanielePucci I implemented a test that compares three toy environments:
Most of the pendulum analysis you can find online and in the literature do not consider the pendulum as a cylinder but as a point mass, and they derive its inertia accordingly. Though, simulators typically read a URDF file that, if done properly, has the inertial element of a given body matching its visual appearance. The pendulum URDF of this repository has a cilynder-shaped body, and in this issue I recapped the steps to derive the equations to integrate the pendulum system under this condition.
This is necessary to have a (almost) perfect match with the simulation running in the considered physics engines. The only difference is the integration method used. For this simple comparison, a relatively small integration step together with Euler integration was good enough to provide a fair comparison.
This test allows to avoid regressions in reproducibility. I kept this issue open because it would be nice to add also the friction in the picture. Moreover, I would exclude the development of an example with contacts because in this case physics engine behave quite differently and creating an analytical model would be rather involved.
Marking this issue as backlog since the variant with friction will be not implemented in the near future.
In order to render the equation you need to enable MathJAX on GitHub. It can be done using Chrome or Firefox extensions.
This information should be moved to the website as soon as we have one.
Pendulum System
Modeling with Newton Laws
1. Inertia of a cylinder rotating around its center of mass
\begin{equation} I_{com} = \frac{1}{12} m (3 r^2 + L^2) \end{equation}
2. Express inertia in the pivot point using the parallel axis theorem
\begin{aligned} I{pivot} &= I{com} + m \left( \frac{L}{2} \right)^2 \\ &= \dots = \frac{m}{12} (4L^2+3r^2) \end{aligned}
3. Apply the second Newton Law in its rotational form
\begin{aligned} \tau{net} = I{pivot} \ddot\theta = \left( \frac{L}{2} \right) m g sin(\theta) \end{aligned}
\begin{aligned} \ddot\theta = \dots = \frac{6g}{4L + 3 r^2 / L} sin(\theta) \end{aligned}
Modeling with Lagrange Equations
1. Calculate the lagrangian of the system
\begin{equation} K = \frac{1}{2} m v^2 + \frac{1}{2} I_{com} \dot\theta^2 \end{equation}
\begin{equation} U = \frac{1}{2} mg \left( \frac{L}{2} \right) cos(\theta) \end{equation}
\begin{aligned} L &= K - U \\ &= \frac{1}{2} m v^2 + \frac{1}{2} I{com} \dot\theta^2 - \frac{1}{2} mg \left( \frac{L}{2} \right) cos(\theta) \\ &= \frac{1}{2} m \left( \frac{L}{2} \right)^2 \dot\theta^2 + \frac{1}{2} I{com} \dot\theta^2 - \frac{1}{2} mg \left( \frac{L}{2} \right) cos(\theta) \end{aligned}
2. Apply the Euler-Lagrange equation
\begin{equation} \frac{d}{dt} \frac{\partial L}{\partial \dot\theta} - \frac{\partial L}{\partial \theta} = 0 \end{equation}
Calculate the partial derivatives:
\begin{equation} \frac{\partial L}{\partial \dot\theta} = \left( m \left( \frac{L}{2} \right)^2 + I_{com} \right) \dot\theta \end{equation}
\begin{equation} \frac{\partial L}{\partial \theta} = mg \left( \frac{L}{2} \right) sin(\theta) \end{equation}
Substituting the derivatives and $I_{com}$:
\begin{aligned} \ddot\theta = \dots = \frac{6g}{4L + 3 r^2 / L} sin(\theta) \end{aligned}
Calculate the system dynamics with Euler integration
\begin{aligned} \dot\thetak &= \dot\theta{k-1} + \ddot\theta_k \Delta t \\ \thetak &= \theta{k-1} + \dot\theta_k \Delta t \end{aligned}