-
Notifications
You must be signed in to change notification settings - Fork 0
/
collision-avoidance.cpp
101 lines (79 loc) · 3.16 KB
/
collision-avoidance.cpp
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
#include "vibes.h"
#include "ibex.h"
#include "functions.h"
#include "json.hpp"
#include <fstream>
using namespace ibex;
using namespace std;
using json = nlohmann::json;
int main(int argc, char** argv){
ifstream input("config.json");
json config;
input >> config;
//navigation zone :
vector<vector<vector<double>>> borderList = config["borderList"];
//coordinate {x,y} of the waypoints
vector<vector<double>> waypoints = config["waypoints"];
//initial boat speed for each segment
vector<Interval> boatSpeed(waypoints.size()-1, Interval(2,2.5));
vibes::beginDrawing();
cout << "before collision avoidance" << endl;
cout << "waypoints :" << endl;
for ( int i = 0; i < waypoints.size(); i++){
cout << waypoints[i][0] << "," << waypoints[i][1] << endl;
}
cout << "speed :" << endl;
for (int i = 0; i < boatSpeed.size(); i++){
cout << boatSpeed[i] << endl;
}
vector<double> drawx, drawy;
for (int i=0; i< waypoints.size(); i++){
drawx.push_back(waypoints[i][0]);
drawy.push_back(waypoints[i][1]);
}
vibes::newFigure("path");
vibes::setFigureProperties(vibesParams("x",0 , "y", 0, "width", 800, "height", 800));
vibes::drawLine(drawx, drawy, "yellow");
for (int i=0; i<borderList.size(); i++){
drawx.resize(0);
drawy.resize(0);
for (int j=0; j<=borderList[i].size(); j++){
drawx.push_back(borderList[i][j%borderList[i].size()][0]);
drawy.push_back(borderList[i][j%borderList[i].size()][1]);
}
vibes::drawLine(drawx, drawy, "red");
}
//informations about obstacles
IntervalVector obsi(4);
vector<IntervalVector> obstacles;
for (int i = 0; i < config["obstaclesInfos"].size(); i++){
obsi[0] = Interval(config["obstaclesInfos"][i][0][0], config["obstaclesInfos"][i][0][1]);
obsi[1] = Interval(config["obstaclesInfos"][i][1][0], config["obstaclesInfos"][i][1][1]);
obsi[2] = Interval(config["obstaclesInfos"][i][2][0], config["obstaclesInfos"][i][2][1]);
obsi[3] = Interval(config["obstaclesInfos"][i][3][0], config["obstaclesInfos"][i][3][1]);
obstacles.push_back(obsi);
}
/*initial position of the boat, by default on the 1st waypoint */
double _boatState[2][2] = {{waypoints[0][0]-1, waypoints[0][0]+1}, {waypoints[0][1]-1, waypoints[0][1]+1}};
IntervalVector boatState(2, _boatState);
functions::manageCollision(waypoints, boatState, boatSpeed, obstacles, borderList);
cout << "after collision avoidance" << endl;
cout << "waypoints :" << endl;
for (int i = 0; i < waypoints.size(); i++){
cout << waypoints[i][0] << "," << waypoints[i][1] << endl;
}
cout << "speed :" << endl;
for (int i = 0; i< boatSpeed.size(); i++){
cout << boatSpeed[i] << endl;
}
vibes::selectFigure("path");
drawx.resize(0);
drawy.resize(0);
for (int i=0; i< waypoints.size(); i++){
drawx.push_back(waypoints[i][0]);
drawy.push_back(waypoints[i][1]);
}
vibes::drawLine(drawx, drawy, "blue");
functions::drawTrajectory(waypoints, boatSpeed, boatState, obstacles);
return 0;
}