Algorithm allows robot to fall gracefully