  For aerial swarms, navigation in a prescribed formation is widely practiced
in various scenarios. However, the associated planning strategies typically
lack the capability of avoiding obstacles in cluttered environments. To address
this deficiency, we present an optimization-based method that ensures
collision-free trajectory generation for formation flight. In this paper, a
novel differentiable metric is proposed to quantify the overall similarity
distance between formations. We then formulate this metric into an optimization
framework, which achieves spatial-temporal planning using polynomial
trajectories. Minimization over collision penalty is also incorporated into the
framework, so that formation preservation and obstacle avoidance can be handled
simultaneously. To validate the efficiency of our method, we conduct benchmark
comparisons with other cutting-edge works. Integrated with an autonomous
distributed aerial swarm system, the proposed method demonstrates its
efficiency and robustness in real-world experiments with obstacle-rich
surroundings. We will release the source code for the reference of the
community.
