目录
1 概述
2 运行结果
3 参考文献
4 Matlab代码
本次使用轨迹优化技术来控制汽车。假设汽车遵循自行车模型的动力学。为了实现稳定和安全的跟踪,我们使用了离散时间模型预测控制。
一个离散的比例控制器(基于定义为偏离赛道中心线的函数的误差)用于生成我们的赛车将遵循的近似轨迹。
复制或下载此存储库后,在系统上打开MATLAB并运行main.m。
[1]李晓芳,何俊.智能自动驾驶汽车的轨迹优化[J].价值工程,2017,36(21):129-130.DOI:10.14018/j.cnki.cn13-1085/n.2017.21.055.
主函数部分代码:
clear
close all
clc
trackDataFileName = 'TestTrack';
%% Proportional Control
initialState = [287,5,-176,0,2,0];
initialTrajectoryFileName = initialTrajectoryGenerator(trackDataFileName,initialState);
disp('Initial Trajectory Generated');
%% MPC
% differentInitialState = initialState; % to keep the same initial state
differentInitialState = [284,5,-180,0,2,0]; % to provide a different initial state
finalTrajectoryFileName = discreteMPC(initialTrajectoryFileName,differentInitialState);
disp('MPC Trajectory Generated');
%% Plots
load(trackDataFileName);
leftLine = TestTrack.bl;
rightLine = TestTrack.br;
load(initialTrajectoryFileName);
initialTraj_X = InitialTraj.states(:,1);
initialTraj_Y = InitialTraj.states(:,3);
load(finalTrajectoryFileName);
finalTraj_X = FinalTraj.states(:,1);
finalTraj_Y = FinalTraj.states(:,3);
figure(1)
title('Initial Trajectory - Using Proportional Controller')
hold on
plot(initialTraj_X, initialTraj_Y, 'r','LineWidth',2);
plot(leftLine(1,:), leftLine(2,:), 'k','LineWidth',1);
plot(rightLine(1,:),rightLine(2,:),'k','LineWidth',1);
legend('Trajectory','Left Border','Right Border','Location','NorthWest')
hold off
figure(2)
title('Final Trajectory - Using MPC Controller')
hold on
plot(finalTraj_X, finalTraj_Y, 'r','LineWidth',2);
plot(leftLine(1,:), leftLine(2,:), 'k','LineWidth',1);
plot(rightLine(1,:),rightLine(2,:),'k','LineWidth',1);
legend('Trajectory','Left Border','Right Border','Location','NorthWest')
hold off
figure(3)
title('Comparing initial part of track')
subplot(2,1,1);
hold on
plot(initialTraj_X, initialTraj_Y, 'r','LineWidth',2);
plot(leftLine(1,:), leftLine(2,:), 'k','LineWidth',1);
plot(rightLine(1,:),rightLine(2,:),'k','LineWidth',1);
legend('Trajectory','Left Border','Right Border','Location','NorthWest')
hold off
subplot(2,1,2);
hold on
plot(finalTraj_X, finalTraj_Y, 'r','LineWidth',2);
plot(leftLine(1,:), leftLine(2,:), 'k','LineWidth',1);
plot(rightLine(1,:),rightLine(2,:),'k','LineWidth',1);
legend('Trajectory','Left Border','Right Border','Location','NorthWest')
hold off