-
Notifications
You must be signed in to change notification settings - Fork 1
/
path_planner.cpp
82 lines (63 loc) · 2.57 KB
/
path_planner.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
#include <utility>
//
// Created by aoool on 8/8/18.
//
#include "car.hpp"
#include "helpers.hpp"
#include "path_planner.hpp"
#include "behavior_layer.hpp"
#include "localization_layer.hpp"
#include "prediction_layer.hpp"
#include <cmath>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <vector>
#include <typeinfo>
std::vector< std::vector<double> >&
PathPlanner::GetNextXYTrajectories(const Car& current_ego_car,
const std::vector<double>& prev_path_x,
const std::vector<double>& prev_path_y,
const std::vector< std::vector<double> >& sensor_fusion)
{
assert( prev_path_x.size() == prev_path_y.size() );
auto prev_path_size = prev_path_x.size();
static uint64_t invocation_counter = 0;
if (invocation_counter == 0) {
car_ = current_ego_car;
trajectory_layer_.Initialize(car_);
}
std::cout << "\n======" << ++invocation_counter << "======\n";
// update the list of characteristics of other cars
localization_layer_.Update(sensor_fusion, car_.T());
for (int i = 0; i < prev_path_size; i++) {
// we do not re-plan the route
next_coords_[0][i] = prev_path_x[i];
next_coords_[1][i] = prev_path_y[i];
}
std::vector<Car> cars = trajectory_layer_.GetTrajectory(config_.path_len - prev_path_size);
for (auto i = 0; i < config_.path_len - prev_path_size; ++i) {
std::vector<double> coords = GetXY(static_cast<double>(cars[i].S()), cars[i].D(), config_);
next_coords_[0][i + prev_path_size] = coords[0];
next_coords_[1][i + prev_path_size] = coords[1];
car_ = cars[i];
}
std::cout << typeid(this).name() << "::GetNextXYTrajectories: last ego car in planned path is\n" << car_ << '\n';
std::cout << "======" << invocation_counter << "======\n\n" << std::endl;
return next_coords_;
}
PathPlanner::~PathPlanner() = default;
PathPlanner::PathPlanner(PathPlannerConfig path_config):
config_{std::move(path_config)},
next_coords_{2, std::vector<double>(config_.path_len)},
car_{},
localization_layer_{config_},
prediction_layer_{config_, localization_layer_},
behavior_layer_{config_, localization_layer_, prediction_layer_},
trajectory_layer_{config_, localization_layer_, prediction_layer_, behavior_layer_}
{
std::cout << '\n' << config_ << '\n' << std::endl;
}
const PathPlannerConfig& PathPlanner::GetPathPlannerConfig() const {
return config_;
}