I paste this algorithm from textbook
Modern Robotics P294 in chapter 8:
This is coordinate invariance of Newton-Euler equations. In the textbook, they use the frame is
centers of mass so the inertial matrix is simple and beautiful, but the result
torque $\tau$ is applied in the
centers of mass and NOT in the joint frame. so, when we use this frame,
\tau maybe need some transformation from centers of mass to the joint frame?