Skip to content

Latest commit

 

History

History
386 lines (277 loc) · 15.4 KB

File metadata and controls

386 lines (277 loc) · 15.4 KB

🇨🇳 中文文档 | 🇺🇸 English

3D无人机正方形编队控制

Status Language MATLAB Version

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

运行方法

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

版本差异

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

仿真过程

仿真过程分为两个主要阶段:

1. 起飞阶段

  • 无人机从地面(z=0)起飞到指定高度
  • 起飞轨迹呈现垂直上升的路径
  • 使用绿色轨迹表示起飞路径

2. 编队阶段

  • 无人机从起飞终点开始向目标正方形位置移动
  • 在移动过程中自动避开其他无人机
  • 最终形成正方形编队

示例效果

3D编队动画演示

3D编队多子图面板

算法原理

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

  • 完整的3D编队过程:包含起飞和编队两个阶段
  • 领导者-跟随者结构:第一架无人机作为领导者,其余无人机作为跟随者
  • 人工势场法:结合吸引力和斥力实现编队控制和碰撞避免
  • 高质量可视化:支持光照效果、材质渲染和轨迹渐变

势场力计算

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

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

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

文件说明

  • quadrangular_formation_control_3D.m:基础版本实现
  • quadrangular_formation_control_3D_V2.m:改进版本,增强了避碰能力和视觉效果
  • quadrangular_formation_control_3D_V3.m:深色背景优化版本,增强了光照效果
  • quadrangular_formation_control_3D_V4_white_bg.m:白色背景版本,适合论文和报告使用
  • create_subfigure_3D.m:用于生成多子图面板展示
  • create_uav_gif.m:用于将保存的图片转换为GIF动画

参数配置

主要参数及其含义:

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

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

% 动画和仿真参数
TIME_STEP = 0.1;          % 时间步长(影响无人机移动速度)
MAX_ITERATIONS = 500;     % 最大迭代次数
PAUSE_TIME = 0.05;        % 每步动画的暂停时间
TAKEOFF_STEPS = 30;       % 起飞阶段的步数

视觉效果参数

3D版本提供了丰富的视觉效果参数,可以创建高质量的可视化效果:

% 视觉效果参数
BACKGROUND_COLOR = [0.12, 0.12, 0.30];   % 深蓝色背景
GRID_COLOR = [0.25, 0.25, 0.35];         % 网格颜色
SQUARE_COLOR = [0.6, 0.7, 0.9];          % 目标正方形颜色
LEADER_COLOR = [1, 0.61, 0.61];          % 领导者颜色
FOLLOWER_COLOR = [0.3, 0.7, 0.9];        % 跟随者颜色
TAKEOFF_TRAIL_COLOR = [0.4, 0.8, 0.5];   % 起飞轨迹颜色

% 光照效果
USE_LIGHTING = true;                  % 使用光照效果
LIGHT_AZIMUTH = 45;                   % 光源方位角(度)
LIGHT_ELEVATION = 30;                 % 光源仰角(度)
LIGHT_COLOR = [1, 1, 1];              % 光源颜色(白色)
MATERIAL_SHININESS = 50;              % 材质光泽度

% 发光效果
USE_GLOW_EFFECT = true;               % 使用发光效果
GLOW_SIZE_LEADER = 100;               % 领导者发光大小
GLOW_SIZE_FOLLOWER = 70;              % 跟随者发光大小
GLOW_ALPHA_LEADER = 0.8;              % 领导者发光透明度
GLOW_ALPHA_FOLLOWER = 0.8;            % 跟随者发光透明度

结果处理

创建多子图面板

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

  1. 运行脚本后,会提示选择包含图片的文件夹
  2. 选择要处理的阶段(起飞、编队或全部)
  3. 选择要包含的图片
  4. 脚本会自动生成4×2的子图面板,适合用于论文或报告展示

创建GIF动画

运行create_uav_gif.m脚本可以将保存的图片序列转换为GIF动画:

  1. 运行脚本后,会提示选择包含图片的文件夹
  2. 选择要处理的阶段(起飞、编队或全部)
  3. 设置GIF帧率和压缩质量
  4. 脚本会自动生成GIF动画

性能优化

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

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

% 图像质量参数
FIGURE_DPI = 300;                % 图像DPI (dots per inch)
FIGURE_WIDTH = 1600;             % 图形窗口宽度(像素)
FIGURE_HEIGHT = 1200;            % 图形窗口高度(像素)
OUTPUT_IMAGE_FORMAT = 'png';     % 输出图像格式 ('png','jpg','tiff')
IMAGE_COMPRESSION = 'none';      % 图像压缩方式 ('none','lzw','jpeg')
ANTIALIASING_ON = true;          % 抗锯齿
GIF_QUALITY = 256;               % GIF颜色质量 (通常128或256)

常见问题

  1. 如何调整编队形状?

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

    • 增大K_REPULSECOLLISION_AVOIDANCE_PRIORITY参数
    • 增大SAFE_DISTANCE参数
  3. 如何优化视觉效果?

    • 调整USE_LIGHTINGMATERIAL_SHININESS参数
    • 修改USE_GLOW_EFFECT和相关参数
    • 调整TRAIL_GRADIENT和颜色参数
  4. 如何加快仿真速度?

    • 减小NUM_UAV参数
    • 增大TIME_STEP参数
    • 设置ENABLE_DRAWNOW = true
    • 减小FIGURE_WIDTHFIGURE_HEIGHT参数

🇨🇳 中文文档 | 🇺🇸 English

3D UAV Square Formation Control

Status Language MATLAB Version

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

How to Run

  1. Open quadrangular_formation_control_3D_V4_white_bg.m (or other versions) in MATLAB
  2. Adjust parameters as needed
  3. Run the script to start the simulation
  4. Simulation results will be saved in uav_square_formation3D/frames_timestamp/

Version Differences

  • V1 Version: Basic implementation with simple visual effects
  • V2 Version: Enhanced collision avoidance and improved visual effects
  • V3 Version: Dark background optimized version with enhanced lighting effects and material rendering
  • V4 Version: White background version suitable for papers and reports with enhanced image quality settings

Simulation Process

The simulation process consists of two main phases:

1. Takeoff Phase

  • UAVs take off from the ground (z=0) to a specified height
  • Takeoff trajectories show vertical ascending paths
  • Green trails represent takeoff paths

2. Formation Phase

  • UAVs move from the takeoff endpoint toward the target square position
  • They automatically avoid other UAVs during movement
  • Finally form a square formation

Example Results

3D Formation Animation

3D Formation Multi-panel

Algorithm Principles

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

  • Complete 3D Formation Process: Includes takeoff and formation phases
  • 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
  • High-Quality Visualization: Supports lighting effects, material rendering, and trajectory gradients

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_3D.m: Basic implementation
  • quadrangular_formation_control_3D_V2.m: Improved version with enhanced collision avoidance and visual effects
  • quadrangular_formation_control_3D_V3.m: Dark background optimized version with enhanced lighting effects
  • quadrangular_formation_control_3D_V4_white_bg.m: White background version suitable for papers and reports
  • create_subfigure_3D.m: Used to generate multi-panel displays
  • create_uav_gif.m: Used to convert saved images to GIF animations

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, 15]; % Center coordinates of the square formation (x, y, z)
SQUARE_SIZE = 45;         % Side length of the square formation

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

% Animation and simulation parameters
TIME_STEP = 0.1;          % Time step (affects UAV movement speed)
MAX_ITERATIONS = 500;     % Maximum number of iterations
PAUSE_TIME = 0.05;        % Pause time for each animation step
TAKEOFF_STEPS = 30;       % Number of steps for the takeoff phase

Visual Effect Parameters

The 3D version provides rich visual effect parameters to create high-quality visualizations:

% Visual effect parameters
BACKGROUND_COLOR = [0.12, 0.12, 0.30];   % Deep blue background
GRID_COLOR = [0.25, 0.25, 0.35];         % Grid color
SQUARE_COLOR = [0.6, 0.7, 0.9];          % Target square color
LEADER_COLOR = [1, 0.61, 0.61];          % Leader color
FOLLOWER_COLOR = [0.3, 0.7, 0.9];        % Follower color
TAKEOFF_TRAIL_COLOR = [0.4, 0.8, 0.5];   % Takeoff trail color

% Lighting effects
USE_LIGHTING = true;                  % Use lighting effects
LIGHT_AZIMUTH = 45;                   % Light source azimuth (degrees)
LIGHT_ELEVATION = 30;                 % Light source elevation (degrees)
LIGHT_COLOR = [1, 1, 1];              % Light source color (white)
MATERIAL_SHININESS = 50;              % Material shininess

% Glow effects
USE_GLOW_EFFECT = true;               % Use glow effects
GLOW_SIZE_LEADER = 100;               % Leader glow size
GLOW_SIZE_FOLLOWER = 70;              % Follower glow size
GLOW_ALPHA_LEADER = 0.8;              % Leader glow transparency
GLOW_ALPHA_FOLLOWER = 0.8;            % Follower glow transparency

Result Processing

Creating Multi-panel Figures

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

  1. After running the script, you will be prompted to select a folder containing images
  2. Choose the phase to process (takeoff, formation, or all)
  3. Select the images to include
  4. The script will automatically generate a 4×2 panel suitable for papers or reports

Creating GIF Animations

Run the create_uav_gif.m script to convert saved image sequences to GIF animations:

  1. After running the script, you will be prompted to select a folder containing images
  2. Choose the phase to process (takeoff, formation, or all)
  3. Set the GIF frame rate and compression quality
  4. The script will automatically generate a GIF animation

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

% Image quality parameters
FIGURE_DPI = 300;                % Image DPI (dots per inch)
FIGURE_WIDTH = 1600;             % Figure window width (pixels)
FIGURE_HEIGHT = 1200;            % Figure window height (pixels)
OUTPUT_IMAGE_FORMAT = 'png';     % Output image format ('png','jpg','tiff')
IMAGE_COMPRESSION = 'none';      % Image compression method ('none','lzw','jpeg')
ANTIALIASING_ON = true;          % Anti-aliasing
GIF_QUALITY = 256;               % GIF color quality (usually 128 or 256)

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 and height 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 optimize visual effects?

    • Adjust the USE_LIGHTING and MATERIAL_SHININESS parameters
    • Modify USE_GLOW_EFFECT and related parameters
    • Adjust TRAIL_GRADIENT and color parameters
  4. How to speed up simulation?

    • Reduce the NUM_UAV parameter
    • Increase the TIME_STEP parameter
    • Set ENABLE_DRAWNOW = true
    • Reduce the FIGURE_WIDTH and FIGURE_HEIGHT parameters