This video demonstrates use of the DenavitHartenberg convention for defining the reference frames of a kinematic chain.
In short, the zaxis for each joint is placed along its axis of motion, and then the xaxes are placed along the common normals between these zaxes. Then four parameters are used to specify the transformation between each of these frames:
• d the "depth" along the previous joint's z axis
• θ (theta) the rotation about the previous z (the angle between the common normal and the previous x axis)
• r the radius of the new origin about the previous z (the length of the common normal)
• α (alpha) the rotation about the new x axis (the common normal) to align the old z to the new z.
See also the Tekkotsu kinematics page, with numerical examples, tools, and links to download HD. http://www.tekkotsu.org/Kinematics.html