Connectivity Maintenance: Global and Optimized approach through Control Barrier Functions