长安的花

当学问走过漫漫古道
凿刻入千窟,心也从愚昧中苏醒

0%

Udacity 5.Behavior_Planning 4

udacity5_Behavior_Planner 设计4 vehicle.h 代码解析

vehicle.h 头文件代码解析

定义车辆类

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
#ifndef VEHICLE_H
#define VEHICLE_H

#include <map>
#include <string>
#include <vector>

using std::map;
using std::string;
using std::vector;

class Vehicle {
public:
// Constructors
Vehicle();//这里实现了一个多态
Vehicle(int lane, float s, float v, float a, string state="CS");

// Destructor
virtual ~Vehicle();

// Vehicle functions 选择下一个状态, 使用的应该是向量机
vector<Vehicle> choose_next_state(map<int, vector<Vehicle>> &predictions);

vector<string> successor_states();// 继承状态

vector<Vehicle> generate_trajectory(string state, //生成轨迹
map<int, vector<Vehicle>> &predictions);

vector<float> get_kinematics(map<int, vector<Vehicle>> &predictions, int lane);

vector<Vehicle> constant_speed_trajectory();//定速车辆

vector<Vehicle> keep_lane_trajectory(map<int, vector<Vehicle>> &predictions);//保持道路

vector<Vehicle> lane_change_trajectory(string state, //转弯路线
map<int, vector<Vehicle>> &predictions);

vector<Vehicle> prep_lane_change_trajectory(string state, //预转弯路线
map<int, vector<Vehicle>> &predictions);

void increment(int dt);//时间增量

float position_at(int t);//找出在哪个位置

bool get_vehicle_behind(map<int, vector<Vehicle>> &predictions, int lane,
Vehicle &rVehicle);//找到后面的车

bool get_vehicle_ahead(map<int, vector<Vehicle>> &predictions, int lane,
Vehicle &rVehicle);//获取前面的车

vector<Vehicle> generate_predictions(int horizon=2);//生成2之后的预测

void realize_next_state(vector<Vehicle> &trajectory);//到达下一个状态

void configure(vector<int> &road_data);//配置,路的数据

// public Vehicle variables
struct collider{//对撞机
bool collision; // is there a collision? 是不是碰撞
int time; // time collision happens
};

map<string, int> lane_direction = {{"PLCL", 1}, {"LCL", 1}, //道路方向
{"LCR", -1}, {"PLCR", -1}};

int L = 1;

int preferred_buffer = 6; // impacts "keep lane" behavior. 首选缓冲区

int lane, s, goal_lane, goal_s, lanes_available;

float v, target_speed, a, max_acceleration;

string state;
};

#endif // VEHICLE_H
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

欢迎关注我的其它发布渠道