-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulation.m
111 lines (97 loc) · 3.55 KB
/
simulation.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
%---------------------------------------------------------------------------------------------------
% For Paper
% "Nonlinear Distributed Model Predictive Flocking with Obstacle Avoidance"
% by P. Hastedt and H. Werner
% Copyright (c) Institute of Control Systems, Hamburg University of Technology. All rights reserved.
% Licensed under the GPLv3. See LICENSE in the project root for license information.
% Author(s): Philipp Hastedt
%---------------------------------------------------------------------------------------------------
clear;
close all;
%% Select Algorithm and Scenario
% Algorithms
% 1: Proposed Predictive SQP Flocking Algorithm
% 2: Non-predictive Olfati-Saber Flocking with Feedback Linearization
% Scenarios
% 1: Free flocking
% 2: Field of obstacles
% Configurations (for Algorithm 1, free flocking)
% 1: Custom configuration (see generateConfig() in /simulation/lib/ )
% 2: NSQP = 1
% 3: NSQP = 3
% 4: NSQP = 10
% 5: NSQP = 100
algorithmIndex = 2;
scenarioIndex = 1;
configIndex = 1;
%% Setup
addpath(genpath('simulation/mas-simulation/lib'))
addpath(genpath('simulation'))
simPath = "simulation/";
algorithms = simPath + [...
"predictive_sqp_flocking"
"ndi_flocking"
];
preallocate = {...
@preallocateSqpFlocking
@preallocateNdiFlocking
};
generateSetup = {...
@generateSetupSqpFlocking
@generateSetupNdiFlocking
};
%% Set Agent Parameters
cfg = generateConfig(algorithms, algorithmIndex);
if (algorithmIndex == 1)
switch (configIndex)
case (2)
cfg = load(strcat(algorithms(algorithmIndex),"/cfg/")+"config_NSQP_1").cfg;
case (3)
cfg = load(strcat(algorithms(algorithmIndex),"/cfg/")+"config_NSQP_3").cfg;
case (4)
cfg = load(strcat(algorithms(algorithmIndex),"/cfg/")+"config_NSQP_10").cfg;
case (5)
cfg = load(strcat(algorithms(algorithmIndex),"/cfg/")+"config_NSQP_100").cfg;
end
end
%% Simulation Setup
% define output and initialization files and paths; set simulation
% parameters
outPath = strcat(simPath,"out/",erase(algorithms(algorithmIndex),simPath),"/");
outFile = outPath+"results_3_v2.mat";
% set simulation parameters
param.dimension = 2; % Dimension of the space the agents move in
param.range = 8.4; % Agent interaction range
param.ro = 8.4; % Obstacle interaction range
switch (scenarioIndex)
case (1)
initializationFile = simPath+"initialStates_10.mat";
Tf = 50; % Simulation duration [s]
param.agentCount = 10; % Number of agents in the network
param.reference = []; % reference
param.obstacles = []; % obstacles
case (2)
initializationFile = simPath+"initialStates_20.mat";
Tf = 300; % Simulation duration [s]
param.agentCount = 20; % Number of agents in the network
param.reference = [85;85;0;0];
param.obstacles = [ 35 60 30 55 75 15
35 35 60 55 45 45
6 3 2 1 2 1];
end
% set sampling time
switch (algorithmIndex)
case (1)
param.dT = 0.3; % Size of the simulation time steps [s]
case(2)
param.dT = 0.02; % Size of the simulation time steps [s]
end
init = load(initializationFile);
setup = generateSetup{algorithmIndex}(cfg, param, init);
%% Run Simulation
sim = SimulationManager(setup.Network, setup.Agents);
leech = preallocate{algorithmIndex}(setup, sim, Tf);
data = performSimulation(sim, leech, Tf);
out.t = data.t;
out.data = data.data;
save(outFile,'out','setup','param', 'cfg');