Learning gravity compensation in robots: Rigid arms, elastic joints, flexible links