Rigid body dynamics with moving internal masses on a rough surface