Skip to content

Latest commit

 

History

History
303 lines (213 loc) · 12 KB

File metadata and controls

303 lines (213 loc) · 12 KB

🇨🇳 中文文档 | 🇺🇸 English

2D无人机编队控制

Status Language MATLAB Version

本文档详细介绍了2D无人机正方形编队控制算法的实现、参数配置和使用方法。

版本差异

  • V1版本:基础实现,使用深色背景
  • V2版本:增强了避碰能力,优化了视觉效果
  • V3版本:使用白色背景,适合论文和报告使用,增强了图像质量设置

仿真过程

仿真过程主要包括以下步骤:

  1. 初始化:随机生成无人机初始位置,确保初始位置不会太近
  2. 目标位置计算:计算正方形编队的目标位置
  3. 迭代更新
    • 计算每架无人机受到的吸引力和斥力
    • 更新无人机位置和速度
    • 记录轨迹
    • 检查收敛情况
  4. 可视化:实时显示无人机位置、轨迹和目标正方形

示例效果

2D编队动画 2D编队多子图面板

算法原理

本项目实现了基于人工势场法的二维平面无人机正方形编队控制算法。主要特点包括:

  • 领导者-跟随者结构:第一架无人机作为领导者,其余无人机作为跟随者
  • 人工势场法:结合吸引力和斥力实现编队控制和碰撞避免
  • 自适应速度控制:根据距离目标位置的远近动态调整速度

势场力计算

  1. 吸引力:无人机受到目标位置的吸引力

    • 领导者吸引力:LEADER_ATTRACT * 方向向量
    • 跟随者吸引力:FOLLOWER_ATTRACT * 方向向量
  2. 斥力:无人机之间的避碰斥力

    • 当两架无人机距离小于安全距离时产生斥力
    • 斥力大小:K_REPULSE * (1/距离 - 1/SAFE_DISTANCE) * (1/距离²)
  3. 碰撞避免优先级:通过COLLISION_AVOIDANCE_PRIORITY参数调整避碰优先级

文件说明

  • quadrangular_formation_control_2D.m:基础版本实现
  • quadrangular_formation_control_2D_V2.m:改进版本,增强了避碰能力
  • quadrangular_formation_control_2D_V3_white_bg.m:白色背景版本,适合论文和报告使用
  • create_subfigure_2D.py:Python脚本,用于生成多子图面板展示

参数配置

主要参数及其含义:

NUM_UAV = 20                 % 无人机数量
MAP_SIZE = 100               % 地图大小(正方形区域边长)
CENTER_POSITION = [50, 50]   % 正方形编队的中心坐标
SQUARE_SIZE = 45             % 正方形编队的边长

% 势场参数
SAFE_DISTANCE = 6            % 无人机之间的安全距离
LEADER_ATTRACT = 4           % 领导者吸引力增益
FOLLOWER_ATTRACT = 2.5       % 跟随者吸引力增益
K_REPULSE = 3                % 避碰斥力增益
MAX_VELOCITY_LEADER = 3      % 领导者最大速度
MAX_VELOCITY_FOLLOWER = 2    % 跟随者最大速度

视觉效果参数

为了提供更好的可视化效果,代码中包含了丰富的视觉参数设置:

% 视觉效果参数
BACKGROUND_COLOR = [0.05, 0.05, 0.15]  % 深蓝色背景
GRID_COLOR = [0.2, 0.2, 0.3]           % 网格颜色
SQUARE_COLOR = [0.9, 0.7, 0.2]         % 目标正方形颜色(金色)
LEADER_COLOR = [0.95, 0.2, 0.2]        % 领导者颜色(红色)
FOLLOWER_COLOR = [0.2, 0.6, 0.9]       % 跟随者颜色(蓝色)

% 轨迹样式参数
LEADER_TRAIL_WIDTH = 3.0               % 领导者轨迹线宽
FOLLOWER_TRAIL_WIDTH = 2.2             % 跟随者轨迹线宽
TRAIL_ALPHA = 0.8                      % 轨迹透明度
TRAIL_GRADIENT = true                  % 是否启用渐变效果

运行方法

  1. 在MATLAB中打开quadrangular_formation_control_2D_V3_white_bg.m文件
  2. 根据需要调整参数
  3. 运行脚本开始仿真
  4. 仿真结果将保存在uav_square_formation2D/frames_时间戳/目录下

结果处理

运行create_subfigure_2D.py脚本可以将仿真生成的图像合成为多子图面板:

python create_subfigure_2D.py

该脚本会自动查找最新的仿真结果,并生成4×2的子图面板,适合用于论文或报告展示。

常见问题

  1. 如何调整编队形状?

    • 修改SQUARE_SIZE参数可以改变正方形的大小
    • 修改CENTER_POSITION可以改变编队中心位置
  2. 如何提高避碰效果?

    • 增大K_REPULSECOLLISION_AVOIDANCE_PRIORITY参数
    • 增大SAFE_DISTANCE参数
  3. 如何加快收敛速度?

    • 增大LEADER_ATTRACTFOLLOWER_ATTRACT参数
    • 增大MAX_VELOCITY_LEADERMAX_VELOCITY_FOLLOWER参数
  4. 如何优化视觉效果?

    • 调整TRAIL_GRADIENTTRAIL_GRADIENT_COLORS参数
    • 修改颜色参数如LEADER_COLORFOLLOWER_COLOR

性能优化

代码中包含多项性能优化措施:

% 性能优化参数
ENABLE_DRAWNOW = true        % 使用drawnow而不是pause来更新图形
SAVE_FRAME_INTERVAL = 5      % 每隔多少帧保存一次图像(减少I/O操作)
TRAIL_SIMPLIFY = true        % 是否简化轨迹绘制
OPTIMIZE_SCATTER = true      % 优化散点图绘制

这些优化可以显著提高仿真速度,特别是在处理大量无人机时。


🇨🇳 中文文档 | 🇺🇸 English

2D UAV Square Formation Control

Status Language MATLAB Version

This document provides detailed information about the implementation, parameter configuration, and usage of the 2D UAV square formation control algorithm.

Version Differences

  • V1 Version: Basic implementation with dark background
  • V2 Version: Enhanced collision avoidance and improved visual effects
  • V3 Version: White background version suitable for papers and reports with enhanced image quality settings

Simulation Process

The simulation process consists of the following steps:

  1. Initialization: Randomly generate initial UAV positions, ensuring they are not too close
  2. Target Position Calculation: Calculate the target positions for the square formation
  3. Iterative Updates:
    • Calculate attractive and repulsive forces for each UAV
    • Update UAV positions and velocities
    • Record trajectories
    • Check convergence status
  4. Visualization: Real-time display of UAV positions, trajectories, and target square

Example Results

2D Formation Animation 2D Formation Multi-panel

Algorithm Principles

This project implements a 2D UAV square formation control algorithm based on artificial potential field method. Key features include:

  • Leader-Follower Structure: The first UAV acts as the leader, while the rest are followers
  • Artificial Potential Field Method: Combines attractive and repulsive forces for formation control and collision avoidance
  • Adaptive Velocity Control: Dynamically adjusts velocity based on distance to target position

Potential Field Force Calculation

  1. Attractive Force: UAVs are attracted to target positions

    • Leader attraction: LEADER_ATTRACT * direction vector
    • Follower attraction: FOLLOWER_ATTRACT * direction vector
  2. Repulsive Force: Collision avoidance force between UAVs

    • Repulsive force is generated when the distance between two UAVs is less than the safe distance
    • Force magnitude: K_REPULSE * (1/distance - 1/SAFE_DISTANCE) * (1/distance²)
  3. Collision Avoidance Priority: Adjusted through the COLLISION_AVOIDANCE_PRIORITY parameter

File Description

  • quadrangular_formation_control_2D.m: Basic implementation
  • quadrangular_formation_control_2D_V2.m: Improved version with enhanced collision avoidance
  • quadrangular_formation_control_2D_V3_white_bg.m: White background version suitable for papers and reports
  • create_subfigure_2D.py: Python script for generating multi-panel displays

Parameter Configuration

Main parameters and their meanings:

NUM_UAV = 20                 % Number of UAVs
MAP_SIZE = 100               % Map size (square area side length)
CENTER_POSITION = [50, 50]   % Center coordinates of the square formation
SQUARE_SIZE = 45             % Side length of the square formation

% Potential field parameters
SAFE_DISTANCE = 6            % Safe distance between UAVs
LEADER_ATTRACT = 4           % Leader attraction gain
FOLLOWER_ATTRACT = 2.5       % Follower attraction gain
K_REPULSE = 3                % Repulsive force gain for collision avoidance
MAX_VELOCITY_LEADER = 3      % Maximum velocity of the leader
MAX_VELOCITY_FOLLOWER = 2    % Maximum velocity of followers

Visual Effect Parameters

To provide better visualization, the code includes rich visual parameter settings:

% Visual effect parameters
BACKGROUND_COLOR = [0.05, 0.05, 0.15]  % Deep blue background
GRID_COLOR = [0.2, 0.2, 0.3]           % Grid color
SQUARE_COLOR = [0.9, 0.7, 0.2]         % Target square color (gold)
LEADER_COLOR = [0.95, 0.2, 0.2]        % Leader color (red)
FOLLOWER_COLOR = [0.2, 0.6, 0.9]       % Follower color (blue)

% Trail style parameters
LEADER_TRAIL_WIDTH = 3.0               % Leader trail line width
FOLLOWER_TRAIL_WIDTH = 2.2             % Follower trail line width
TRAIL_ALPHA = 0.8                      % Trail transparency
TRAIL_GRADIENT = true                  % Whether to enable gradient effect

How to Run

  1. Open the quadrangular_formation_control_2D_V3_white_bg.m file in MATLAB
  2. Adjust parameters as needed
  3. Run the script to start the simulation
  4. Simulation results will be saved in the uav_square_formation2D/frames_timestamp/ directory

Result Processing

Run the create_subfigure_2D.py script to combine simulation-generated images into a multi-panel display:

python create_subfigure_2D.py

This script will automatically find the latest simulation results and generate a 4×2 panel suitable for papers or reports.

Frequently Asked Questions

  1. How to adjust the formation shape?

    • Modify the SQUARE_SIZE parameter to change the size of the square
    • Modify CENTER_POSITION to change the center position of the formation
  2. How to improve collision avoidance?

    • Increase the K_REPULSE and COLLISION_AVOIDANCE_PRIORITY parameters
    • Increase the SAFE_DISTANCE parameter
  3. How to speed up convergence?

    • Increase the LEADER_ATTRACT and FOLLOWER_ATTRACT parameters
    • Increase the MAX_VELOCITY_LEADER and MAX_VELOCITY_FOLLOWER parameters
  4. How to optimize visual effects?

    • Adjust the TRAIL_GRADIENT and TRAIL_GRADIENT_COLORS parameters
    • Modify color parameters such as LEADER_COLOR and FOLLOWER_COLOR

Performance Optimization

The code includes multiple performance optimization measures:

% Performance optimization parameters
ENABLE_DRAWNOW = true        % Use drawnow instead of pause to update graphics
SAVE_FRAME_INTERVAL = 5      % Save images every N frames (reduces I/O operations)
TRAIL_SIMPLIFY = true        % Simplify trajectory drawing
OPTIMIZE_SCATTER = true      % Optimize scatter plot drawing

These optimizations can significantly improve simulation speed, especially when handling a large number of UAVs.