Purpose The purpose of this paper is to develop a novel formation controller with fixed and switching topologies, using pigeon-inspired optimization (PIO) with Cauchy disturbance for unmanned aerial vehicle (UAV) parameter tuning. Design/methodology/approach Aiming at the problem of UAV formation control with fixed/switching communication topologies, the UAV formation control strategy is established based on leader-following strategy and second-order consensus control. To overcome the difficulties of manually adjusting the controller parameters, the PIO with Cauchy disturbance algorithm is used to optimize the control parameters. Findings Drawing upon graph theory and the consensus control protocol, it can be concluded that the consensus of the formation with both fixed and switching topologies is assured, given the existence of a directed spanning tree in the communication topologies and the switching frequency not exceeding a certain value. The heavy-tailed property of Cauchy distribution effectively prevents the algorithm from being trapped in local optima during the optimization process. The integration of Cauchy disturbance into PIO can effectively address the problem that the PIO algorithm is prone to falling into local optima and effectively solve the parameter tuning problem for UAV controllers. Practical implications The PIO with Cauchy disturbance algorithm can cope with various sudden communication failures in practical applications, improve the control accuracy of UAVs and ensure the effectiveness of the formation controller by adapting to changing communication topologies. Originality/value A formation controller based on consensus control with fixed and switching topologies is proposed, and the PIO with Cauchy disturbance algorithm is proposed and applied to parameter tuning.