Dynamics of cooperative excavation in ant and robot collectives