这个例子展示了如何在Simulink®的ROS 2网络中的各个节点中分布自动泊车代客应用程序,并将它们部署为独立的ROS 2节点。金宝app这个例子扩展了自动停车员(自动驾驶工具箱)示例在自动驾驶工具箱™中。在Simulink示金宝app例中的automatic Parking Valet中使用Simulink模型,在将模型划分为ROS 2节点之前,调整规划器、控制器和车辆动态参数。
先决条件:自动停车员(自动驾驶工具箱),从Simulink®生成一个独立的ROS 2节点金宝app
这个自动驾驶汽车应用程序有以下组件。
这个例子集中于模拟规划,控制和车辆组件。为本地化,这个例子使用预先记录的本地化地图数据。的规划组件又进一步分为行为计划和路径规划组件。这导致了一个由四个ROS 2节点组成的ROS 2网络:行为计划
,路径规划
,控制器
和车辆
.下图显示了网络中每个ROS 2节点与每个节点使用的主题之间的关系。
观察将组件划分为四个单独的Simulink模型。金宝app每个Sim金宝appulink模型代表一个ROS 2节点。
1.打开车辆模型。
open_system (“ROS2ValetVehicleExample”);
2.的订阅
子系统包含ROS 2订阅块读取输入数据控制器节点。
3.的
汽车模型
子系统包含一个自行车模型(自动驾驶工具箱)块,车辆身体3自由度
,模拟车辆控制器效果,并通过ROS 2将车辆信息通过ROS 2网络发送发布块的发布
子系统。
1.打开行为规划者模型。
open_system (“ROS2ValetBehavioralPlannerExample”);
2.该模型从ROS 2网络中读取当前车辆信息,发送下一个目标,并检查车辆是否达到了使用路段的最终姿态rosAutomatedValetHelperGoalChecker
.
3.的行为
规划师
和
目标
检查程序
当其中一个上有新消息可用时,子系统将运行/ currentvel
或/ currentpose
.
4.模型发送状态,如果车辆已经达到最终停车目标使用/ reachgoal
Topic,它使用std_msgs / Bool
消息类型。当此消息为时,所有模型停止模拟真正的
.
1.打开路径规划器模型。
open_system (“ROS2ValetPathPlannerExample”);
2.该模型通过环境图规划出可行的路径pathPlannerRRT
(自动驾驶工具箱)对象,该对象实现快速寻优随机树(RRT*)算法,并通过ROS 2网络将计划发送给控制器。
3.的路径规划
子系统在新消息可用时运行/ plannerConfig
或/ nextgoal
的话题。
1.打开车辆控制器模型。
open_system (“ROS2ValetControllerExample”);
2.该模型通过ROS 2网络计算并发送转向和速度指令。
3.控制器子系统在控制器上有新消息可用时运行/ velprofile
的话题。
验证将系统划分为4个ROS 2节点后,模型的行为保持不变。
1.在MATLAB基础工作空间中加载预先录制的定位地图数据exampleHelperROSValetLoadLocalizationData
helper函数。
exampleHelperROSValetLoadLocalizationData;
2.打开仿真模型。
open_system (“ROS2ValetSimulationExample.slx”);
在左侧的停车场选择区,您也可以选择一个停车位。默认的停车位是第6排。
3.在SIMULATION选项卡中,单击运行从模拟节或运行sim(“ROS2ValetSimulationExample.slx”)
在MATLAB命令窗口。图打开并显示车辆如何跟踪参考路径。蓝色的线代表参考路径,而红色的线是车辆行驶的实际路径。仿真所有模型在车辆到达最终停车点时停止。
sim卡(“ROS2ValetSimulationExample.slx”);
的可视化
在车辆模型中的子系统生成这个例子的结果。
open_system (“ROS2ValetVehicleExample /车辆模型可视化”);
visualizePath
Block负责创建和更新前面显示的车辆路径图。车辆的速度和转向指令显示在一个范围内。
open_system (“ROS2ValetVehicleExample /车辆模型/可视化/命令”)
生成ROS 2申请行为计划
,路径规划
和控制器
节点。模拟车辆
并与仿真结果进行了比较。
生成和部署行为计划
,路径规划
和控制器
节点的应用程序使用exampleHelperROS2ValetDeployNodes
helper函数。helper函数调用slbuild
(金宝app模型)命令,使用每个模型的Simulink模型名作为输入参数,生金宝app成c++代码并在主机上部署应用程序。
exampleHelperROS2ValetDeployNodes ();%生成c++代码并为ROS 2节点部署应用程序
在\ user \joshchen\ onedrive - MathWorks\Documents\MATLAB\Examples\ros-ex88924338\ROS2ValetBehavioralPlannerExample_ert_rtw . ###在\ user \joshchen\ onedrive \ MathWorks\Documents\MATLAB\Examples\ ROS2ValetBehavioralPlannerExample_ert_rtw . \ \
###为“ROS2ValetBehavioralPlannerExample”生成的代码是最新的,因为没有发现结构、参数或代码替换库更改。### #在C:/Users/joshchen/OneDrive - MathWorks/Documents/MATLAB/Examples/ os-ex88924338文件夹中运行Colcon build成功生成所有二进制输出。### # Creating HTML report file ROS2ValetBehavioralPlannerExample_codegen_rpt.html build Summary模型重建行动的原因 =========================================================================================== ROS2ValetBehavioralPlannerExample编译的代码编译工件是过时了。### Build procedure for: ROS2ValetPathPlannerExample ### # generate code and artifacts to 'Model specific' folder structure ### #在Build folder中生成代码:C:\Users\joshchen\OneDrive - MathWorks\Documents\MATLAB\Examples\罗斯-ex88924338\ ros2valetpathplanannerexample_ert_rtw ###为' ros2valetpathplanannerexample '生成的代码是最新的,因为没有发现结构、参数或代码替换库的变化。### # Using toolchain: Colcon Tools ### # build ' ros2valetpathplanerexample ': all ' Running Colcon build in folder 'C:/Users/joshchen/OneDrive - MathWorks/Documents/MATLAB/Examples/ros-ex88924338'.完成。成功生成所有二进制输出。### # Creating HTML report file ROS2ValetPathPlannerExample_codegen_rpt.html build Summary Model Action Rebuild Reason ===================================================================================== ROS2ValetPathPlannerExample Code compiled Compilation artifacts were out of date. 1 of 1 models built (0 models already up to date) Build duration: 0h 1m 53.874s ### Starting build procedure for: ROS2ValetControllerExample ### Generating code and artifacts to 'Model specific' folder structure ### Generating code into build folder: C:\Users\joshchen\OneDrive - MathWorks\Documents\MATLAB\Examples\ros-ex88924338\ROS2ValetControllerExample_ert_rtw ### Generated code for 'ROS2ValetControllerExample' is up to date because no structural, parameter or code replacement library changes were found. ### Evaluating PostCodeGenCommand specified in the model ### Using toolchain: Colcon Tools ### Building 'ROS2ValetControllerExample': all Running colcon build in folder 'C:/Users/joshchen/OneDrive - MathWorks/Documents/MATLAB/Examples/ros-ex88924338'.Done. Success ### Successfully generated all binary outputs. ### Successful completion of build procedure for: ROS2ValetControllerExample ### Creating HTML report file ROS2ValetControllerExample_codegen_rpt.html Build Summary Top model targets built: Model Action Rebuild Reason ==================================================================================== ROS2ValetControllerExample Code compiled Compilation artifacts were out of date. 1 of 1 models built (0 models already up to date) Build duration: 0h 2m 1.851s
打开车辆模型,开始仿真。
open_system (“ROS2ValetVehicleExample”);set_param (“ROS2ValetVehicleExample”,“SimulationCommand”,“开始”);
验证仿真结果与部署的ROS 2节点匹配。