from kinematic_bicycle_model import Vehicle, VehicleInfo, draw_vehicle
from pure_pursuit_controller import pure_pursuit_steer_control
from Path_generator import Path
import numpy as np
import matplotlib.pyplot as plt
import imageio.v2 as imageio
MAX_SIMULATION_TIME = 200.0# 程序最大运行时间200*dt
def main():
# 设置跟踪轨迹
rx, ry, rv, ref_yaw, ref_s, ref_kappa = Path().get_ref_line_info()
ref_path = np.column_stack((rx, ry, rv, ref_yaw, ref_s, ref_kappa))
# 假设车辆初始位置为(5,60),航向角yaw=0.0,速度为2m/s,时间周期dt为0.1秒
vehicle1 = Vehicle(x=5.0,
y=60.0,
yaw=0.0,
v=2.0,
dt=0.1,
l=VehicleInfo.L)
vehicle2 = Vehicle(x=5.0,
y=60.0,
yaw=0.0,
v=2.0,
dt=0.1,
l=VehicleInfo.L)
time = 0.0# 初始时间
target_ind1 = 0
target_ind2 = 0
# 记录车辆轨迹
trajectory_x1 = []
trajectory_y1 = []
trajectory_x2 = []
trajectory_y2 = []
lat_err1 = [] # 记录横向误差
lat_err2 = [] # 记录横向误差
i = 0
image_list = [] # 存储图片
plt.figure(1, dpi=100)
old_index1 = None
old_index2 = None
last_idx = ref_path.shape[0] - 1# 跟踪轨迹的最后一个点的索引
while MAX_SIMULATION_TIME >= time and (last_idx > target_ind1 or last_idx > target_ind2):
time += vehicle1.dt # 累加一次时间周期
if last_idx > target_ind1:
delta_f1, target_ind1, e_y1 = pure_pursuit_steer_control(vehicle1, ref_path, old_index1, False)
old_index1 = target_ind1
# 横向误差
lat_err1.append(e_y1)
# 更新车辆状态
vehicle1.update(0.0, delta_f1, np.pi/10) # 由于假设纵向匀速运动,所以加速度a=0.0
trajectory_x1.append(vehicle1.x)
trajectory_y1.append(vehicle1.y)
if last_idx > target_ind2:
delta_f2, target_ind2, e_y2 = pure_pursuit_steer_control(vehicle2, ref_path, old_index2, True)
old_index2 = target_ind2
lat_err2.append(e_y2)
vehicle2.update(0.0, delta_f2, np.pi / 10) # 由于假设纵向匀速运动,所以加速度a=0.0
trajectory_x2.append(vehicle2.x)
trajectory_y2.append(vehicle2.y)
# 显示动图
plt.subplots_adjust(hspace=0.5, wspace=0.5) # 调整垂直和水平间距
plt.subplot(3, 1, 1)
plt.cla()
plt.plot(ref_path[:, 0], ref_path[:, 1], '-.k', linewidth=1.0)
draw_vehicle(vehicle1.x, vehicle1.y, vehicle1.yaw, vehicle1.steer, plt, color='blue')
draw_vehicle(vehicle2.x, vehicle2.y, vehicle2.yaw, vehicle2.steer, plt, color='green')
plt.plot(trajectory_x1, trajectory_y1, "-b", label="RWPP-trajectory")
plt.plot(trajectory_x2, trajectory_y2, "-g", label="FWPP-trajectory")
plt.plot(ref_path[target_ind1, 0], ref_path[target_ind1, 1], "b-o", label="RWPP-target")
plt.plot(ref_path[target_ind2, 0], ref_path[target_ind2, 1], "g-o", label="FWPP-target")
plt.xlim(min(vehicle1.x, vehicle2.x, ref_path[target_ind1, 0], ref_path[target_ind2, 0]) - 3,
max(vehicle1.x, vehicle2.x, ref_path[target_ind1, 0], ref_path[target_ind2, 0]) + 3)
plt.ylim(min(vehicle1.y, vehicle2.y, ref_path[target_ind1, 1], ref_path[target_ind2, 1]) - 3,
max(vehicle1.y, vehicle2.y, ref_path[target_ind1, 1], ref_path[target_ind2, 1]) + 3)
plt.legend()
plt.grid(True)
plt.subplot(3, 1, 2)
plt.cla()
plt.plot(ref_path[:, 0], ref_path[:, 1], '-.k', linewidth=1.0)
plt.plot(trajectory_x1, trajectory_y1, 'b', label="RWPP-trajectory")
plt.plot(trajectory_x2, trajectory_y2, 'g', label="FWPP-trajectory")
plt.title("actual tracking effect")
plt.xlim(min(trajectory_x1[-1], trajectory_x2[-1]) - 1, max(trajectory_x1[-1], trajectory_x2[-1]) + 1)
plt.ylim(min(trajectory_y1[-1], trajectory_y2[-1]) - 0.5, max(trajectory_y1[-1], trajectory_y2[-1]) + 0.5)
plt.legend()
plt.grid(True)
plt.subplot(3, 1, 3)
plt.cla()
plt.plot(lat_err1, 'b', label="RWPP")
plt.plot(lat_err2, 'g', label="FWPP")
plt.title("lateral error")
plt.legend()
plt.xlim((len(trajectory_x1) + len(trajectory_x2)) / 2 - 35, (len(trajectory_x1) + len(trajectory_x2)) / 2 + 35)
plt.ylim(min(lat_err1[-1], lat_err2[-1]) - 0.1, max(lat_err1[-1], lat_err2[-1]) + 0.1)
plt.grid(True)
plt.pause(0.001)
plt.savefig("temp.png")
i += 1
if (i % 5) == 0:
image_list.append(imageio.imread("temp.png"))
imageio.mimsave("display.gif", image_list, duration=0.1)
plt.figure(2)
plt.subplots_adjust(hspace=0.5, wspace=0.5) # 调整垂直和水平间距
plt.subplot(2, 1, 1)
plt.plot(ref_path[:, 0], ref_path[:, 1], '-.k', linewidth=1.0)
plt.plot(trajectory_x1, trajectory_y1, 'b', label="RWPP-trajectory")
plt.plot(trajectory_x2, trajectory_y2, 'g', label="FWPP-trajectory")
plt.title("actual tracking effect")
plt.legend()
plt.grid(True)
plt.subplot(2, 1, 2)
plt.plot(lat_err1, 'b', label="Rear Wheel Pure Pursuit")
plt.plot(lat_err2, 'g', label="Front Wheel Pure Pursuit")
plt.title("lateral error")
plt.legend()
plt.grid(True)
plt.show()
if __name__ == '__main__':
main()
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
pure.zip (17个子文件)
pure
Path_generator.py 3KB
pure_pursuit_controller.py 2KB
main.py 5KB
.idea
workspace.xml 8KB
misc.xml 276B
pure.iml 284B
inspectionProfiles
Project_Default.xml 792B
profiles_settings.xml 174B
modules.xml 260B
.gitignore 182B
temp.png 45KB
display.mp4 1001KB
kinematic_bicycle_model.py 3KB
__pycache__
Path_generator.cpython-39.pyc 2KB
kinematic_bicycle_model.cpython-37.pyc 3KB
pure_pursuit_controller.cpython-39.pyc 2KB
kinematic_bicycle_model.cpython-39.pyc 3KB
共 17 条
- 1
资源评论
亿佛
- 粉丝: 323
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Oracle数据库工具安装包(免安装)
- Http上传文件到服务器 php文件
- 114.0.5734.1 Google Chrome谷歌浏览器下载
- meta-llama-3-8b-instruct 的 model-00002-of-00004.safetensors 的2/3
- subversion-1.14.3-6.fc41.x86-64.rpm
- GridLayoutCalculator.zip
- Release QMYSQL driver 6.2.4-msvc2019-x64
- mod-ldap-2.4.54-5.fc37.x86-64.rpm
- mod-ldap-2.4.56-1.fc38.x86-64.rpm
- mod-ldap-2.4.58-7.fc40.x86-64.rpm
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功