Algorithm helps drone avoid crashes