本文档详细介绍了3D无人机正方形编队控制算法的实现、参数配置和使用方法。
- 在MATLAB中打开
quadrangular_formation_control_3D_V4_white_bg.m
文件(或其他版本) - 根据需要调整参数
- 运行脚本开始仿真
- 仿真结果将保存在
uav_square_formation3D/frames_时间戳/
目录下
- V1版本:基础实现,简单的视觉效果
- V2版本:增强了避碰能力,优化了视觉效果
- V3版本:深色背景优化版本,增强了光照效果和材质渲染
- V4版本:白色背景版本,适合论文和报告使用,增强了图像质量设置
仿真过程分为两个主要阶段:
- 无人机从地面(z=0)起飞到指定高度
- 起飞轨迹呈现垂直上升的路径
- 使用绿色轨迹表示起飞路径
- 无人机从起飞终点开始向目标正方形位置移动
- 在移动过程中自动避开其他无人机
- 最终形成正方形编队
本项目实现了基于人工势场法的三维空间无人机正方形编队控制算法。主要特点包括:
- 完整的3D编队过程:包含起飞和编队两个阶段
- 领导者-跟随者结构:第一架无人机作为领导者,其余无人机作为跟随者
- 人工势场法:结合吸引力和斥力实现编队控制和碰撞避免
- 高质量可视化:支持光照效果、材质渲染和轨迹渐变
-
吸引力:无人机受到目标位置的吸引力
- 领导者吸引力:
LEADER_ATTRACT * 方向向量
- 跟随者吸引力:
FOLLOWER_ATTRACT * 方向向量
- 领导者吸引力:
-
斥力:无人机之间的避碰斥力
- 当两架无人机距离小于安全距离时产生斥力
- 斥力大小:
K_REPULSE * (1/距离 - 1/SAFE_DISTANCE) * (1/距离²)
-
碰撞避免优先级:通过
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
脚本可以将仿真生成的图像合成为多子图面板:
- 运行脚本后,会提示选择包含图片的文件夹
- 选择要处理的阶段(起飞、编队或全部)
- 选择要包含的图片
- 脚本会自动生成4×2的子图面板,适合用于论文或报告展示
运行create_uav_gif.m
脚本可以将保存的图片序列转换为GIF动画:
- 运行脚本后,会提示选择包含图片的文件夹
- 选择要处理的阶段(起飞、编队或全部)
- 设置GIF帧率和压缩质量
- 脚本会自动生成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)
-
如何调整编队形状?
- 修改
SQUARE_SIZE
参数可以改变正方形的大小 - 修改
CENTER_POSITION
可以改变编队中心位置和高度
- 修改
-
如何提高避碰效果?
- 增大
K_REPULSE
和COLLISION_AVOIDANCE_PRIORITY
参数 - 增大
SAFE_DISTANCE
参数
- 增大
-
如何优化视觉效果?
- 调整
USE_LIGHTING
和MATERIAL_SHININESS
参数 - 修改
USE_GLOW_EFFECT
和相关参数 - 调整
TRAIL_GRADIENT
和颜色参数
- 调整
-
如何加快仿真速度?
- 减小
NUM_UAV
参数 - 增大
TIME_STEP
参数 - 设置
ENABLE_DRAWNOW = true
- 减小
FIGURE_WIDTH
和FIGURE_HEIGHT
参数
- 减小
This document provides detailed information about the implementation, parameter configuration, and usage of the 3D UAV square formation control algorithm.
- Open
quadrangular_formation_control_3D_V4_white_bg.m
(or other versions) in MATLAB - Adjust parameters as needed
- Run the script to start the simulation
- Simulation results will be saved in
uav_square_formation3D/frames_timestamp/
- 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
The simulation process consists of two main phases:
- UAVs take off from the ground (z=0) to a specified height
- Takeoff trajectories show vertical ascending paths
- Green trails represent takeoff paths
- UAVs move from the takeoff endpoint toward the target square position
- They automatically avoid other UAVs during movement
- Finally form a square formation
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
-
Attractive Force: UAVs are attracted to target positions
- Leader attraction:
LEADER_ATTRACT * direction vector
- Follower attraction:
FOLLOWER_ATTRACT * direction vector
- Leader attraction:
-
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²)
-
Collision Avoidance Priority: Adjusted through the
COLLISION_AVOIDANCE_PRIORITY
parameter
quadrangular_formation_control_3D.m
: Basic implementationquadrangular_formation_control_3D_V2.m
: Improved version with enhanced collision avoidance and visual effectsquadrangular_formation_control_3D_V3.m
: Dark background optimized version with enhanced lighting effectsquadrangular_formation_control_3D_V4_white_bg.m
: White background version suitable for papers and reportscreate_subfigure_3D.m
: Used to generate multi-panel displayscreate_uav_gif.m
: Used to convert saved images to GIF animations
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
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
Run the create_subfigure_3D.m
script to combine simulation-generated images into a multi-panel display:
- After running the script, you will be prompted to select a folder containing images
- Choose the phase to process (takeoff, formation, or all)
- Select the images to include
- The script will automatically generate a 4×2 panel suitable for papers or reports
Run the create_uav_gif.m
script to convert saved image sequences to GIF animations:
- After running the script, you will be prompted to select a folder containing images
- Choose the phase to process (takeoff, formation, or all)
- Set the GIF frame rate and compression quality
- The script will automatically generate a GIF animation
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)
-
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
- Modify the
-
How to improve collision avoidance?
- Increase the
K_REPULSE
andCOLLISION_AVOIDANCE_PRIORITY
parameters - Increase the
SAFE_DISTANCE
parameter
- Increase the
-
How to optimize visual effects?
- Adjust the
USE_LIGHTING
andMATERIAL_SHININESS
parameters - Modify
USE_GLOW_EFFECT
and related parameters - Adjust
TRAIL_GRADIENT
and color parameters
- Adjust the
-
How to speed up simulation?
- Reduce the
NUM_UAV
parameter - Increase the
TIME_STEP
parameter - Set
ENABLE_DRAWNOW = true
- Reduce the
FIGURE_WIDTH
andFIGURE_HEIGHT
parameters
- Reduce the