长安的花

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

0%

Udacity 5.Behavior_Planning 1

udacity5_Behavior_Planner 设计1

接下里开始设计行为规划器

MPH 英里每小时

行为规划器的使用范围是对于高速路段设计的

汽车的状态有五个: 保持直行,左转,右转,预备左转,预备右转

完成损失函数

仿真器假定汽车已经使用了很好的控制器

主函数 main.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
#include <iostream>
#include <vector>
#include "road.h" //道路类
#include "vehicle.h" // 交通工具类

using std::cout;
using std::endl;

// impacts default behavior for most states
int SPEED_LIMIT = 10; //定义车速限制

// all traffic in lane (besides ego) follow these speeds
vector<int> LANE_SPEEDS = {6,7,8,9}; //除了自己的车辆,其他车辆都遵循这个车速

// Number of available "cells" which should have traffic
double TRAFFIC_DENSITY = 0.15;//车辆密度

// At each timestep, ego can set acceleration to value between
// -MAX_ACCEL and MAX_ACCEL
int MAX_ACCEL = 2; //车辆信息,最大加速度

// s value and lane number of goal.
vector<int> GOAL = {300, 0}; //目标距离和目标的d,确定了目标位置

// These affect the visualization
int FRAMES_PER_SECOND = 4; //可视化的帧率
int AMOUNT_OF_ROAD_VISIBLE = 40;//路的宽度

int main() {
//初始化道路信息,包含限速,车流量。每个车道的车速
Road road = Road(SPEED_LIMIT, TRAFFIC_DENSITY, LANE_SPEEDS);
//更新车道的宽度
road.update_width = AMOUNT_OF_ROAD_VISIBLE;
//给道路中填充车辆
road.populate_traffic();
//定义目标位置
int goal_s = GOAL[0];
int goal_lane = GOAL[1];

// configuration data: speed limit, num_lanes, goal_s, goal_lane,
// and max_acceleration
//配置数据,本车的限速,车道数量,目标位置,最大加速度
int num_lanes = LANE_SPEEDS.size();//根据车道来定义
//定义一个向量,里面存放本车的初始化参数
vector<int> ego_config = {SPEED_LIMIT,num_lanes,goal_s,goal_lane,MAX_ACCEL};
//在道路里增加本车辆
road.add_ego(2,0, ego_config);
int timestep = 0;//定义时间步长

while (road.get_ego().s <= GOAL[0]) {//判断是否到达目标点
++timestep;
if (timestep > 100) {//时间大于100就跳出判断
break;
}
road.advance();//路段更新
road.display(timestep);//显示道路
//time.sleep(float(1.0) / FRAMES_PER_SECOND);
}

Vehicle ego = road.get_ego();//得到当前车辆信息
if (ego.lane == GOAL[1]) {
cout << "You got to the goal in " << timestep << " seconds!" << endl;
if(timestep > 35) {
cout << "But it took too long to reach the goal. Go faster!" << endl;
}
} else {
cout << "You missed the goal. You are in lane " << ego.lane
<< " instead of " << GOAL[1] << "." << endl;
}

return 0;
}
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

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