Detecting track has finished

Just use the same sensors you're already using for obstacle avoidance to also detect the end of the track. If they can detect a block and a gap then they can detect the lack of a wall and a gap on 3 sides of the track.