[自动驾驶系列一]Introduction to Self-Driving Cars

Introduction to Self-Driving Cars

  • Module 1: The Requirements for Autonomy
    • Lesson 1: Taxonomy of Driving(驾驶分类)
    • Lesson 1:Practice
    • Lesson 2: Requirements for Perception
    • Lesson 2:Practice
    • Lesson 3: Driving Decisions and Actions
    • 测验1
  • Module 2: Self-Driving Hardware and Software Architectures
    • Lesson 1: Sensors and Computing Hardware
    • Lesson 2: Hardware Configuration Design
    • Lesson 3: Software Architecture
    • Lesson 4: Environment Representation
    • 测验2
  • Module 3: Safety Assurance for Autonomous Vehicles
    • Lesson 1: Safety Assurance for Self-Driving Vehicles
    • Lesson 2: Industry Methods for Safety Assurance and Testing
    • Lesson 3: Safety Frameworks for Self-Driving
    • 测验3
  • Module 4: Vehicle Dynamic Modeling
    • Lesson 1: Kinematic Modeling in 2D
    • Lesson 2: The Kinematic Bicycle Model
    • Lesson 3: Dynamic Modeling in 2D
    • Lesson 4: Longitudinal Vehicle Modeling
    • Lesson 5: Lateral Dynamics of Bicycle Model
    • Lesson 6: Vehicle Actuation
    • Lesson 7: Tire Slip and Modeling
    • 编程1
    • 编程2
  • Module 5: Vehicle Longitudinal Control
    • Lesson 1: Proportional-Integral-Derivative (PID) Control
    • Lesson 2: Longitudinal Speed Control with PID
    • Lesson 3: Feedforward Speed Control
    • 测验3
  • Module 6: Vehicle Lateral Control
    • Lesson 1: Introduction to Lateral Vehicle Control
    • Lesson 2: Geometric Lateral Control - Pure Pursuit
    • Lesson 3: Geometric Lateral Control - Stanley
    • Lesson 4: Advanced Steering Control - MPC
    • 测验4
    • Module 7: Putting it all together
    • Lesson 1: Carla Overview - Self-Driving Car Simulation
    • Lesson 2: Final Project Overview
    • Final Project Solution

很幸运的搜到了这门课程,作为某实验室的一个小白,对这个行业很有兴趣,希望真的会有那么一天,L5的实现给人们带来极大的便利。记录一下课程重要的ppt和课后作业,这个是多伦多大学的一门课程,COURSERA上可以找的到,配套的作业很不错,有精力的可以去申请一下。
https://www.coursera.org/specializations/self-driving-cars

Module 1: The Requirements for Autonomy

Lesson 1: Taxonomy of Driving(驾驶分类)

[自动驾驶系列一]Introduction to Self-Driving Cars_第1张图片

  • ODD:设计运行范围,自动驾驶系统被设计的起作用的条件及适用范围,把我们知道的天气环境、道路情况(直路、弯路的半径)、车速、车流量等信息作出测定,以确保系统的能力在安全的环境之内

[自动驾驶系列一]Introduction to Self-Driving Cars_第2张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第3张图片

  • Lateral control: 横向控制,左右转,直行或沿曲线行驶
  • Longitudinal control: 纵向控制,刹车加速控制汽车的位置或速度
  • Object and Event Detection and Response(OEDR):感知和判断,对车辆纵向运动方向操作、通过对物体和事件检测、认知归类和后续响应,达到对车辆周围环境的监测和执行对应操作、车辆运动的计划还有对外信息的传递

[自动驾驶系列一]Introduction to Self-Driving Cars_第4张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第5张图片

[自动驾驶系列一]Introduction to Self-Driving Cars_第6张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第7张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第8张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第9张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第10张图片

Lesson 1:Practice

在这里插入图片描述
[自动驾驶系列一]Introduction to Self-Driving Cars_第11张图片
转弯:swerve
[自动驾驶系列一]Introduction to Self-Driving Cars_第12张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第13张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第14张图片

Lesson 2: Requirements for Perception

[自动驾驶系列一]Introduction to Self-Driving Cars_第15张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第16张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第17张图片
curbs:路边[自动驾驶系列一]Introduction to Self-Driving Cars_第18张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第19张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第20张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第21张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第22张图片
illumination:照明
[自动驾驶系列一]Introduction to Self-Driving Cars_第23张图片

Lesson 2:Practice

potholes: 坑洼
sidewalks:人行道
sensor occlusion:传感器阻塞
inertial:惯性的

[自动驾驶系列一]Introduction to Self-Driving Cars_第24张图片

[自动驾驶系列一]Introduction to Self-Driving Cars_第25张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第26张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第27张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第28张图片

Lesson 3: Driving Decisions and Actions

[自动驾驶系列一]Introduction to Self-Driving Cars_第29张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第30张图片

[自动驾驶系列一]Introduction to Self-Driving Cars_第31张图片

测验1

take a nap:小睡一下
[自动驾驶系列一]Introduction to Self-Driving Cars_第32张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第33张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第34张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第35张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第36张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第37张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第38张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第39张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第40张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第41张图片

[自动驾驶系列一]Introduction to Self-Driving Cars_第42张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第43张图片
应该是B
[自动驾驶系列一]Introduction to Self-Driving Cars_第44张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第45张图片

[自动驾驶系列一]Introduction to Self-Driving Cars_第46张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第47张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第48张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第49张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第50张图片

Module 2: Self-Driving Hardware and Software Architectures

Lesson 1: Sensors and Computing Hardware

[自动驾驶系列一]Introduction to Self-Driving Cars_第51张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第52张图片
stereo:立体的
[自动驾驶系列一]Introduction to Self-Driving Cars_第53张图片
LIDAR——Light Detection And Ranging,GPS+IMU,更精确,900-1500nm,激光
RADAR——radio detection and ranging,4-12mm,无线电
[自动驾驶系列一]Introduction to Self-Driving Cars_第54张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第55张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第56张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第57张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第58张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第59张图片

Lesson 2: Hardware Configuration Design

[自动驾驶系列一]Introduction to Self-Driving Cars_第60张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第61张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第62张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第63张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第64张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第65张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第66张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第67张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第68张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第69张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第70张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第71张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第72张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第73张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第74张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第75张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第76张图片
在这里插入图片描述

Lesson 3: Software Architecture

CARLA:
[自动驾驶系列一]Introduction to Self-Driving Cars_第77张图片
感知,建图,规划,控制,监督
[自动驾驶系列一]Introduction to Self-Driving Cars_第78张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第79张图片
三种地图
[自动驾驶系列一]Introduction to Self-Driving Cars_第80张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第81张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第82张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第83张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第84张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第85张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第86张图片
在这里插入图片描述
参考这篇文章有几个常见的单词
ego-vehicle 表示自我概念呢,用来表示被自动控制的车辆,相对于没被自动控制的车辆,或者也叫self-vehicle
类似的,经常用exo来表示其他的车辆,如exo-agent表示外智能体

Lesson 4: Environment Representation

[自动驾驶系列一]Introduction to Self-Driving Cars_第87张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第88张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第89张图片

测验2

[自动驾驶系列一]Introduction to Self-Driving Cars_第90张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第91张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第92张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第93张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第94张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第95张图片
由于定位测绘(localization mapping)只涉及识别车辆在环境中的姿势,因此可以使用点特征或物体位置,不需要密集地覆盖整个环境,而占位网格测绘(occupancy grid mapping)必须捕捉所有需要避开的障碍物的位置,因此必须密集。

localization mapping是估计自主车辆如何在环境中移动的关键测量,依赖于将当前时间的传感器测量结果与定位图进行匹配。占位网格图以车辆周围被占用和未被占用的单元格的形式存储实时避撞数据
[自动驾驶系列一]Introduction to Self-Driving Cars_第96张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第97张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第98张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第99张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第100张图片

Module 3: Safety Assurance for Autonomous Vehicles

Lesson 1: Safety Assurance for Self-Driving Vehicles

[自动驾驶系列一]Introduction to Self-Driving Cars_第101张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第102张图片

Lesson 2: Industry Methods for Safety Assurance and Testing

[自动驾驶系列一]Introduction to Self-Driving Cars_第103张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第104张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第105张图片

FMEA: Failure Mode and Effects Analysis
一种由下而上(bottom up)的失败分析方法,衡量个别原因和决定其在更高层系统中的影响
[自动驾驶系列一]Introduction to Self-Driving Cars_第106张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第107张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第108张图片

Lesson 3: Safety Frameworks for Self-Driving

[自动驾驶系列一]Introduction to Self-Driving Cars_第109张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第110张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第111张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第112张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第113张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第114张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第115张图片

测验3

rollover 车辆翻滚
intersection 交叉路口
lane change 变道
rear-end 追尾
road departure 失控冲出路面事故
扩展:

  • head-on collision 迎头对撞事故
  • rear-end collision 追尾事故;
  • Back-up collisions 倒车事故;
  • side collisions 侧面撞击事故;
  • run-off-road collision / roadway departure / road departure 失控冲出路面事故;
  • rollovers 翻车事故;
  • pile-up / multiple vehicle collision 多车相撞事故;
  • hit-and-run incident 肇事逃逸事故

[自动驾驶系列一]Introduction to Self-Driving Cars_第116张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第117张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第118张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第119张图片
在这里插入图片描述
[自动驾驶系列一]Introduction to Self-Driving Cars_第120张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第121张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第122张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第123张图片

[自动驾驶系列一]Introduction to Self-Driving Cars_第124张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第125张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第126张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第127张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第128张图片

Module 4: Vehicle Dynamic Modeling

Lesson 1: Kinematic Modeling in 2D

[自动驾驶系列一]Introduction to Self-Driving Cars_第129张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第130张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第131张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第132张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第133张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第134张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第135张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第136张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第137张图片

Lesson 2: The Kinematic Bicycle Model

[自动驾驶系列一]Introduction to Self-Driving Cars_第138张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第139张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第140张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第141张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第142张图片

Lesson 3: Dynamic Modeling in 2D

[自动驾驶系列一]Introduction to Self-Driving Cars_第143张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第144张图片

Lesson 4: Longitudinal Vehicle Modeling

Torque converter:变矩器
[自动驾驶系列一]Introduction to Self-Driving Cars_第145张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第146张图片

Lesson 5: Lateral Dynamics of Bicycle Model

decouple:解耦
tire force:轮胎力
stiffness:刚性
在这里插入图片描述
[自动驾驶系列一]Introduction to Self-Driving Cars_第147张图片

Lesson 6: Vehicle Actuation

kinematics:动力学
[自动驾驶系列一]Introduction to Self-Driving Cars_第148张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第149张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第150张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第151张图片
gear ratios 齿轮比
whell torque 扭矩

[自动驾驶系列一]Introduction to Self-Driving Cars_第152张图片

Lesson 7: Tire Slip and Modeling

编程1

在本笔记本中,你将实现自行车运动学模型。该模型接受速度和转向率的输入,并通过自行车运动学方程来实现。一旦模型实现,你将提供一组输入来驱动自行车在图8的轨迹。

自行车运动学由以下方程组控制。
[自动驾驶系列一]Introduction to Self-Driving Cars_第153张图片
其中输入为自行车速度v和转向角率ω。输入也可以直接是转向角δ,而不是简化后的速率。Python模型将允许我们实现这两种情况。

为了创建这个模型,利用Python类对象是个好主意。这使我们可以存储状态变量,以及为实现自行车运动学而制作函数。

自行车的初始条件为零,最大转弯速率为1.22rad/s,轴距长度为2m,从后轴到其质量中心的长度为1.2m。

从这些条件出发,我们初始化Python类如下。

from notebook_grader import BicycleSolution, grade_bicycle
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg

class Bicycle():
    def __init__(self):
        self.xc = 0
        self.yc = 0
        self.theta = 0
        self.delta = 0
        self.beta = 0
        
        self.L = 2
        self.lr = 1.2
        self.w_max = 1.22
        
        self.sample_time = 0.01
        
    def reset(self):
        self.xc = 0
        self.yc = 0
        self.theta = 0
        self.delta = 0
        self.beta = 0

当通过时间传播运动学时,数值积分需要一个采样时间。这个时间被设置为10毫秒。我们还有一个复位函数,将所有的状态变量设置为0。

有了这个采样时间,使用下一个单元格中定义的函数步骤来实现运动学模型。该函数应该将速度+角速率作为输入,并更新状态变量。不要忘了自行车的最大转弯率!

class Bicycle(Bicycle):
    def step(self, v, w):
        # ==================================
        #  Implement kinematic model here
        # ==================================
        class Bicycle(Bicycle):
    def step(self, v, w):
        # ==================================
        #  Implement kinematic model here
        # ==================================
        if w > 0:
            w = min(w,self.w_max)
        else:
            w = max(w,-self.w_max)
        
        sample_T = 10e-3
        
        # bicycle kinematics
        
        xc_dot= v * np.cos(self.theta + self.beta)
        yc_dot= v * np.sin(self.theta+self.beta)
        theta_dot= v * np.cos(self.beta) * np.tan(self.delta) / self.L
        delta_dot= w
        
        # update the state variables
        
        self.xc += xc_dot * sample_T
        self.yc += yc_dot * sample_T
        self.theta += theta_dot * sample_T
        self.delta += delta_dot * sample_T
        
        pass


        pass

有了模型设置,我们现在可以开始给自行车输入并产生轨迹。

假设我们希望模型在20秒内走完一个半径为10米的圆。利用曲率半径和转向角之间的关系,可以计算出所需的转向角。
[自动驾驶系列一]Introduction to Self-Driving Cars_第154张图片
如果使用模拟自行车模型直接将转向角设置为0.1974,那么自行车将在圆周内行驶,而不需要任何额外的转向输入。

所需的速度可以从圆周上计算出来。
[自动驾驶系列一]Introduction to Self-Driving Cars_第155张图片
现在,我们可以在循环中实现这一点,以逐步完成模型方程。我们还将与您的模型一起运行我们的自行车模型解决方案,以显示您的预期轨迹。这将帮助您验证模型的正确性。

sample_time = 0.01
time_end = 20
model = Bicycle()
solution_model = BicycleSolution()

# set delta directly
model.delta = np.arctan(2/10)
solution_model.delta = np.arctan(2/10)

t_data = np.arange(0,time_end,sample_time)
x_data = np.zeros_like(t_data)
y_data = np.zeros_like(t_data)
x_solution = np.zeros_like(t_data)
y_solution = np.zeros_like(t_data)

for i in range(t_data.shape[0]):
    x_data[i] = model.xc
    y_data[i] = model.yc
    model.step(np.pi, 0)
    
    x_solution[i] = solution_model.xc
    y_solution[i] = solution_model.yc
    solution_model.step(np.pi, 0)
    
    #model.beta = 0
    #solution_model.beta=0
    
plt.axis('equal')
plt.plot(x_data, y_data,label='Learner Model')
plt.plot(x_solution, y_solution,label='Solution Model')
plt.legend()
plt.show()

上图显示了所需的半径为10米的圆,路径略有偏移,这是由于β造成的侧滑效应。通过取消循环中最后一行的注释,强制β=0,你可以看到偏移消失了,圆的中心位置变成了(0,10)。

然而,在实践中,转向角不能直接设置,必须通过角速率输入ω来改变。下面的单元格对此进行了修正,并设置角速率输入,生成相同的圆轨迹。速度v仍然保持在π m/s。

sample_time = 0.01
time_end = 20
model.reset()
solution_model.reset()

t_data = np.arange(0,time_end,sample_time)
x_data = np.zeros_like(t_data)
y_data = np.zeros_like(t_data)
x_solution = np.zeros_like(t_data)
y_solution = np.zeros_like(t_data)

for i in range(t_data.shape[0]):
    x_data[i] = model.xc
    y_data[i] = model.yc
    
    if model.delta < np.arctan(2/10):
        model.step(np.pi, model.w_max)
    else:
        model.step(np.pi, 0)
        
    x_solution[i] = solution_model.xc
    y_solution[i] = solution_model.yc
    
    if solution_model.delta < np.arctan(2/10):
        solution_model.step(np.pi, model.w_max)
    else:
        solution_model.step(np.pi, 0)    

plt.axis('equal')
plt.plot(x_data, y_data,label='Learner Model')
plt.plot(x_solution, y_solution,label='Solution Model')
plt.legend()
plt.show()

[自动驾驶系列一]Introduction to Self-Driving Cars_第156张图片

下面是一些其他的轨迹示例:正方形路径、螺旋路径和波浪路径。取消标注每个部分来查看。

sample_time = 0.01
time_end = 60
model.reset()
solution_model.reset()

t_data = np.arange(0,time_end,sample_time)
x_data = np.zeros_like(t_data)
y_data = np.zeros_like(t_data)
x_solution = np.zeros_like(t_data)
y_solution = np.zeros_like(t_data)

# maintain velocity at 4 m/s
v_data = np.zeros_like(t_data)
v_data[:] = 4 

w_data = np.zeros_like(t_data)

# ==================================
#  Square Path: set w at corners only
# ==================================
w_data[670:670+100] = 0.753
w_data[670+100:670+100*2] = -0.753
w_data[2210:2210+100] = 0.753
w_data[2210+100:2210+100*2] = -0.753
w_data[3670:3670+100] = 0.753
w_data[3670+100:3670+100*2] = -0.753
w_data[5220:5220+100] = 0.753
w_data[5220+100:5220+100*2] = -0.753

# ==================================
#  Spiral Path: high positive w, then small negative w
# ==================================
# w_data[:] = -1/100
# w_data[0:100] = 1

# ==================================
#  Wave Path: square wave w input
# ==================================
#w_data[:] = 0
#w_data[0:100] = 1
#w_data[100:300] = -1
#w_data[300:500] = 1
#w_data[500:5700] = np.tile(w_data[100:500], 13)
#w_data[5700:] = -1

# ==================================
#  Step through bicycle model
# ==================================
for i in range(t_data.shape[0]):
    x_data[i] = model.xc
    y_data[i] = model.yc
    model.step(v_data[i], w_data[i])

    x_solution[i] = solution_model.xc
    y_solution[i] = solution_model.yc
    solution_model.step(v_data[i], w_data[i])
    
plt.axis('equal')
plt.plot(x_data, y_data,label='Learner Model')
plt.plot(x_solution, y_solution,label='Solution Model')
plt.legend()
plt.show()

[自动驾驶系列一]Introduction to Self-Driving Cars_第157张图片

现在我们想让自行车走一个图八的轨迹。图八中的两个圆的半径都是8米,路径应该在30秒内完成。路径从左边圆的底部开始,如下图所示。
[自动驾驶系列一]Introduction to Self-Driving Cars_第158张图片

确定产生这种轨迹所需的速度和转向率输入,并在下面的单元格中实现。确保将您的输入保存到数组v_data和w_data中,这些将用于对您的解决方案进行评分。下面的单元格也绘制了你自己的模型所产生的轨迹。

sample_time = 0.01
time_end = 30
model.reset()

t_data = np.arange(0,time_end,sample_time)
x_data = np.zeros_like(t_data)
y_data = np.zeros_like(t_data)
v_data = np.zeros_like(t_data)
w_data = np.zeros_like(t_data)

# ==================================
#  Learner solution begins here
# ==================================
radius=8
#delta=np.arctan(np.arctan(np.arctan(np.arctan(model.L/radius))))
#delta=np.arctan(np.arctan(np.arctan(model.L/radius)))
delta=np.arctan(np.arctan(model.L/radius))
#delta=np.arctan(model.L/radius)
delta=0.983*np.arctan(model.L/radius)
print(delta)
print(np.arctan(np.arctan(model.L/radius)))
v_data[:]=2*2*np.pi*radius/time_end

for i in range(t_data.shape[0]):
    x_data[i]=model.xc
    y_data[i]=model.yc
    
    #w direction will change in first 1/4 circle (t/8) and 5/4 circle (5t/8)
    if i< t_data.shape[0]/8:
        # if model delta < delta then we should use max w
        if model.delta<delta:
            temp_w=abs(model.delta-delta)/model.delta*model.w_max
            if temp_w>0:
                w=min(temp_w,model.w_max)
            else:
                w=max(temp_w,-model.w_max)
            model.step(v_data[i],w)
            w_data[i]=w
            #print(w_data[i],t_data[i])
        #else we should use w=0 don't turn your front wheel
        else:
            model.step(v_data[i],0)
            #w_data[i]=0
        
    elif i< 5*t_data.shape[0]/8:
        #print(model.delta,delta,t_data[i])
        if model.delta>-delta:
            model.step(v_data[i],-model.w_max)
            w_data[i]=-model.w_max
            #print(w_data[i],t_data[i])
        else:
            model.step(v_data[i],0)
            #w_data[i]=0
    else:
        if model.delta<delta:
            model.step(v_data[i],model.w_max)
            w_data[i]=model.w_max
        else:
            model.step(v_data[i],0)
            #w_data[i]=0
#     model.beta = 0
#     solution_model.beta=0  
   
# ==================================
#  Learner solution ends here
# ==================================
plt.axis('equal')
plt.plot(x_data, y_data)
plt.show()

现在我们将通过自行车模型解决方案运行您的速度和角速率输入。这是为了确保你的轨迹与你的模型是正确的。下面的单元格将显示由我们的模型生成的路径,以及一些航点在所需的图8上。这些航点周围是半径为1.5米的误差容差圈,如果生成的轨迹保持在这些容差圈的80%以内,你的解决方案将通过分级机。

grade_bicycle(t_data,v_data,w_data)

下面的单元格将把时间和车辆输入保存为名为fig8.txt的文本文件。要找到该文件,请将网络目录的末尾改为/notebooks/Course_1_Module_4/figure8.txt。
到了那里,你就可以下载文件,然后提交给Coursera评分器来完成这个评估。
[自动驾驶系列一]Introduction to Self-Driving Cars_第159张图片

data = np.vstack([t_data, v_data, w_data]).T
np.savetxt('figure8.txt', data, delimiter=', ')

编程2

[自动驾驶系列一]Introduction to Self-Driving Cars_第160张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第161张图片

class Vehicle(Vehicle):
    def step(self, throttle, alpha):
        # ==================================
        #  Implement vehicle model here
        # ==================================
        w_w=self.GR*self.w_e
        s=(w_w*self.r_e-self.v)/self.v
        
        if abs(s)<1:
            F_x=self.c*s
        else:
            F_x=self.F_max
            
        F_aero=self.c_a*(self.v**2)
        R_x=self.c_r1*self.v
        F_g=self.m*self.g*np.sin(alpha)
        
        F_load=R_x+F_aero+F_g
        

        
        self.a=(F_x-F_load)/self.m
        self.v += self.a * self.sample_time
        self.x += self.v * self.sample_time
        
        T_e=throttle*(self.a_0+self.a_1*self.w_e+self.a_2*self.w_e**2)
        
        self.w_e_dot = (T_e - self.GR*self.r_e*F_load)/self.J_e
        self.w_e += self.w_e_dot * self.sample_time
        pass
sample_time = 0.01
time_end = 100
model = Vehicle()

t_data = np.arange(0,time_end,sample_time)
v_data = np.zeros_like(t_data)

# throttle percentage between 0 and 1
throttle = 0.2

# incline angle (in radians)
alpha = 0

for i in range(t_data.shape[0]):
    v_data[i] = model.v
    model.step(throttle, alpha)
    
plt.plot(t_data, v_data)
plt.show()

[自动驾驶系列一]Introduction to Self-Driving Cars_第162张图片

throttle_data = np.zeros_like(t_data)
alpha_data = np.zeros_like(t_data)
for i,t in enumerate(t_data):
    if t<5:
        throttle_data[i]=0.2+(0.5-0.2)*t/5
    elif t<15:
        throttle_data[i]=0.5
    else:
        throttle_data[i]=0.5-0.5*(t-15)/5
    
for i in range(t_data.shape[0]):
    v_data[i]=model.v
    
    if model.x<60:
        alpha_data[i]=np.arctan(3/60)
    elif model.x<150:
        alpha_data[i]=np.arctan((12-3)/90)
    else:
        alpha_data[i]=0

    model.step(throttle_data[i], alpha_data[i])
    
    x_data[i]=model.x
    v_data[i]=model.v
    w_w=model.GR*model.w_e
 	s_data[i]=(w_w*model.r_e-model.v)/model.v

[自动驾驶系列一]Introduction to Self-Driving Cars_第163张图片

Module 5: Vehicle Longitudinal Control

Lesson 1: Proportional-Integral-Derivative (PID) Control

[自动驾驶系列一]Introduction to Self-Driving Cars_第164张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第165张图片

Lesson 2: Longitudinal Speed Control with PID

[自动驾驶系列一]Introduction to Self-Driving Cars_第166张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第167张图片

Lesson 3: Feedforward Speed Control

[自动驾驶系列一]Introduction to Self-Driving Cars_第168张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第169张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第170张图片

测验3

[自动驾驶系列一]Introduction to Self-Driving Cars_第171张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第172张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第173张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第174张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第175张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第176张图片
增加微分控制可改善超调量和调节时间方面的阶跃响应,但会降低上升时间。相反,添加积分项可保持较短的上升时间,并且能够减少振荡和超调量,从而也缩短了调节时间。将导数和积分控制项相加会带来这两种方法的优点。
[自动驾驶系列一]Introduction to Self-Driving Cars_第177张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第178张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第179张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第180张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第181张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第182张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第183张图片

Module 6: Vehicle Lateral Control

Lesson 1: Introduction to Lateral Vehicle Control

[自动驾驶系列一]Introduction to Self-Driving Cars_第184张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第185张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第186张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第187张图片

Lesson 2: Geometric Lateral Control - Pure Pursuit

[自动驾驶系列一]Introduction to Self-Driving Cars_第188张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第189张图片

Lesson 3: Geometric Lateral Control - Stanley

[自动驾驶系列一]Introduction to Self-Driving Cars_第190张图片

Lesson 4: Advanced Steering Control - MPC

[自动驾驶系列一]Introduction to Self-Driving Cars_第191张图片

测验4

[自动驾驶系列一]Introduction to Self-Driving Cars_第192张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第193张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第194张图片
后轮
[自动驾驶系列一]Introduction to Self-Driving Cars_第195张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第196张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第197张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第198张图片
在这里插入图片描述
[自动驾驶系列一]Introduction to Self-Driving Cars_第199张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第200张图片
[自动驾驶系列一]Introduction to Self-Driving Cars_第201张图片

Module 7: Putting it all together

Lesson 1: Carla Overview - Self-Driving Car Simulation

Lesson 2: Final Project Overview

详情见这里CLICK

Final Project Solution

你可能感兴趣的:(无人驾驶,CARLA,CARLA,无人驾驶,仿真,COUSERA,多伦多大学)