A Science Robotics article explains that robots get this knowledge from sensors placed at the joints and at the center of mass.