用MATLAB做自动驾驶之与虚拟引擎(Unreal Engine)联合仿真

**

用MATLAB做自动驾驶之与虚拟引擎(Unreal engine)联合仿真

**
本文主要为使用MATLAB2020b无人驾驶simlulink中Automated Driving Toolbox模块库的用户提供指导学习

1.安装Unreal engine 软件

Unreal Engine 4 使用 Epic Games Launcher 进行安装。进入 Unreal Engine 网站 并点击 Get Unreal 按钮(右上角)。
unreal engine 4 官网界面
下载并安装完安装器之后,运行安装器。会显示一个窗口,注册账户之后进入Epic Games Launcher 进行虚幻引擎安装,MATLAB2020b目前只支持4.23版本的虚幻引擎。在这里插入图片描述
安装完成后进入MATLAB进行插件的安装。

2.MATLAB插件安装

安装matlab支持包并配置环境
1.在matlab主页选项卡,在环境部分找到附加功能,选择获取附加功能。在这里插入图片描述
2.在“附加资源管理器”中搜索Vehicle Dynamics Blockset Interface for Unreal Engine 4 Projects 项目并下载安装。安装时无需选择安装路径。
3.安装完成后此支持包需要VIsual studio code 2017环境。
4.进行环境配置可手动复制文件或者使用如下代码或者手动复制,本人推荐使用代码,因为手动复制的话容易出问题,个人尝试了很多次都没有成功,最后通过代码复制完成配置此代码也可在matlab帮助文档中找到。

%% STEP1
% Specify the location of the support package project files and a local folder destination
% Note:  Only one path is supported. Select latest download path.
dest_root = "C:\Local";
src_root = fullfile(matlabshared.supportpkg.getSupportPackageRoot, ...
    "toolbox", "shared", "sim3dprojects", "automotive");

%% STEP2
% Specify the location of the Unreal Engine installation.
ueInstFolder = "C:\Program Files\Epic Games\UE_4.23";

%% STEP3
% Copy the MathWorksSimulation plugin to the Unreal Engine plugin folder.
mwPluginName = "MathWorksSimulation";
mwPluginFolder = fullfile(src_root, "PluginResources", "UE423"); % choose UE version
uePluginFolder = fullfile(ueInstFolder, "Engine", "Plugins");
uePluginDst = fullfile(uePluginFolder, "Marketplace", "MathWorks");

cd(uePluginFolder)
foundPlugins = dir("**/" + mwPluginName + ".uplugin");

if ~isempty(foundPlugins)
    numPlugins = size(foundPlugins, 1);
    msg2 = cell(1, numPlugins);
    pluginCell = struct2cell(foundPlugins);

    msg1 = "Plugin(s) already exist here:" + newline + newline;
    for n = 1:numPlugins
        msg2{n} = "    " + pluginCell{2,n} + newline;
    end
    msg3 = newline + "Please remove plugin folder(s) and try again.";
    msg  = msg1 + msg2 + msg3;
    warning(msg);
else
    copyfile(mwPluginFolder, uePluginDst);
    disp("Successfully copied MathWorksSimulation plugin to UE4 engine plugins!")
end

%% STEP4
% Copy the support package folder that contains the AutoVrtlEnv.uproject
% files to the local folder destination.
projFolderName = "AutoVrtlEnv";
projSrcFolder = fullfile(src_root, projFolderName);
projDstFolder = fullfile(dest_root, projFolderName);
if ~exist(projDstFolder, "dir")
    copyfile(projSrcFolder, projDstFolder);
end

步骤一:将AutoVrtlEnv文件夹复制到C:\Local文件夹中。此文件夹的默认目录为C:\ProgramData\MATLAB\SupportPackages\R2020b\toolbox\shared\sim3dprojects\automotive\AutoVrtlEnv.
步骤二:将MathWorksSimulation.uplugin文件复制到虚幻引擎工作目录中。C:\ProgramData\MATLAB\SupportPackages\R2020b\toolbox\shared\sim3dprojects\driving\PluginResources\UE423\MathWorksSimulation
在上述目录中找到文件并且复制到
H:\xuhuanyinqing\UE_4.23\Engine\Plugins\Marketplace\MathWorks\MathWorksSimulation(此文件夹为虚幻引擎的安装文件夹,可自行寻找)
若无法找到MathWorksSimulation.uplugin文件,需要在“附加资源管理器”中搜索Automated Driving Toolbox Interface for Unreal Engine 4 Projects 获取并安装。安装之后就可以找到了这个文件了。
在这里插入图片描述

3.通过matlab打开虚幻引擎进行场景自定义。
上述工作完成后,在matlab命令窗口输入openExample(‘vdynblks/SceneInterrogationReferenceApplicationExample’)打开实例工程在这里插入图片描述
选择Simulation 3D Scene Configuration模块双击进入编辑界面,在scene source中选择Unreal Editor并在下面的project中选择C:\Local\AutoVrtlEnv目录下的AutoVrtlEnv.uproject。在这里插入图片描述
在这里插入图片描述

点击Open Unreal Editor 即可打开虚幻引擎进行场景编辑。成功打开虚幻引擎即表示联合仿真环境配置成功。
在这里插入图片描述

参考资料:
[1]: https://www.mathworks.com/help/vdynblks/vehicle-scenarios.html?category=vehicle-scenarios&s_tid=CRUX_topnav

  • 6
    点赞
  • 68
    收藏
    觉得还不错? 一键收藏
  • 22
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值