forked from MiyagiRonin/auto_parking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
73 lines (60 loc) · 1.96 KB
/
main.cc
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
#include "reverse_verticle_parking.h"
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <absl/strings/str_split.h>
#include "absl/strings/numbers.h"
using namespace apollo::common::math;
int main() {
Pose start;
std::vector<LineSegment2d> boundaries;
std::string file_name = "../problems/reverse_verticle_1.txt";
std::ifstream inFile;
inFile.open(file_name, std::ios::in);
if (!inFile.is_open())
{
std::cout <<"Can't open "<<file_name<<std::endl;
return 1;
}
std::string buff;
bool first_line = true;
while (getline(inFile, buff))
{
const std::vector<absl::string_view> data = absl::StrSplit(buff, " ");
if (first_line) {
double x, y, theta;
absl::SimpleAtod(data[0], &x);
absl::SimpleAtod(data[1], &y);
absl::SimpleAtod(data[2], &theta);
start = {Vec2d(x, y), theta, Vec2d::CreateUnitVec2d(theta)};
first_line = false;
}else {
double x1, y1, x2, y2;
absl::SimpleAtod(data[0], &x1);
absl::SimpleAtod(data[1], &y1);
absl::SimpleAtod(data[2], &x2);
absl::SimpleAtod(data[3], &y2);
boundaries.emplace_back(Vec2d(x1, y1), Vec2d(x2, y2));
}
}
inFile.close();
LineCirclePath result;
std::ofstream outFile;
outFile.open("output_path.txt", std::ios::out);
const auto start_t = std::clock();
const bool success = RunReverseVerticleParking(boundaries, start, &result);
const double time = (double)(std::clock() - start_t) / CLOCKS_PER_SEC;
printf("Time consuming is %.2f ms.\n", time * 1000.0);
if (success) {
const auto path = ConvertPathToDiscretePoses(result, 0.1);
for(const auto& pose : path) {
outFile<<pose.pos.x()<<" "<<pose.pos.y()<<" "<<pose.theta<<std::endl;
}
printf("Success!\n");
}else{
printf("Fail!\n");
}
outFile.close();
return 0;
}