主要内容

自动泊车代客与ROS在MATLAB

这个例子展示了如何分发自动停车员(自动驾驶工具箱)在ROS网络中各个节点之间的应用。根据您的系统,本示例使用MATLAB®或Simulink®为ROS和ROS 2网络提供。万博1manbetx这里显示的示例使用了ROS和MATLAB。其他示例请参见:

概述

的扩展自动停车员(自动驾驶工具箱)示例在自动驾驶工具箱™。一个典型的自治应用程序有以下组件。

为简单起见,该示例集中在规划,控制和简化的车型上。该示例使用预先记录的数据来替换本地化信息。

此应用程序演示了在ROS节点中的各种功能的典型拆分。下图显示了上述示例如何分为各种节点。每个节点:规划,控制和车辆是实现如下所示功能的ROS节点。节点之间的互连显示了节点的每个互连上使用的主题。

设置

首先,加载行为规划器和路径分析器使用的路线计划和给定的成本图。行为规划器,路径规划器,路径分析器,横向和纵向控制器都是通过helper类实现的,这些类是通过这个示例helper函数调用来设置的。

examplehelperrosvaletsetupglobals;

初始化的全局变量被组织为全局结构中的字段,代客

disp(管家)
mapLayers:(1×1结构)costmap:[1×1 vehicleCostmap] vehicleDims:[1×1 vehicleDimensions] maxSteeringAngle: 35数据:[1×1 struct] routePlan:[4×3表]currentPose: [4 12 0] vehicleSim:[1×1 ExampleHelperROSValetVehicleSimulator] behavioralPlanner:[1×1 ExampleHelperROSValetBehavioralPlanner] motionPlanner:[1×1 pathPlannerRRT] goalPose:[56 11 0] refPath: [1×1 driving.]路径]transitionpose: [14×3 double] directions: [522×1 double] currentVel: 0 approxSeparation: 0.1000 numsmoothpose: 522 maxSpeed: 5 startSpeed: 0 endSpeed: 0 refpose: [522×3 double] cumlength: [522×1 double]曲率:[522×1 double] refvelocity: [522×1 double] sampleTime: 0.1000 lonController:[1×1 examplehelperrosvaletlongitude controller] controlRate: [1×1 ExampleHelperROSValetFixedRate] pathAnalyzer: [1×1 ExampleHelperROSValetPathAnalyzer] parkPose: [36 44 90]

初始化ROS网络

rosinit;
推出ROS核心..................................................................................在5.3625秒内完成。

初始化ROS Master http://192.168.0.10:60903。使用nodeuri初始化全局节点/ matlab_global_node_49911 http:// sbd508773glnxa64:42335 /
masterhost =“localhost”;

应用程序中的功能分布在ROS节点中。这个例子使用了三个ROS节点:Cranslnode.controlNode,vehicleNode

规划

规划节点根据当前车辆位置计算每个路径段。该节点负责生成平滑路径并将路径发布到网络。

此节点发布以下主题:

  • / smoothpath.

  • / velprofile

  • /方向

  • /速度

  • / nextgoal.

该节点订阅以下主题:

  • / currentvel

  • /湿润

  • /后vel.

  • /达成目标

接受A./达成目标消息,节点运行exampleHelperROS2ValetPlannerCallback回调,计划下一个部分。

创建规划节点

planningNode = ros。节点(“规划”,masterhost);

为规划节点创建发布者。为ROS网络上不存在的主题指定发布者或订阅者的消息类型。

Plann.PatchPub = ROS.Publisher(Cranchnnode,' / smoothpath '“std_msgs / Float64MultiArray”);规划。VelPub = ros。出版商(planningNode' / velprofile '“std_msgs / Float64MultiArray”);Plann.Dirpub = ROS.Publisher(CillingNode,' /方向'“std_msgs / Float64MultiArray”);规划。SpeedPub = ros。出版商(planningNode' /速度'“std_msgs / Float64MultiArray”);Plann.Nxtpub = ROS.Publisher(Cranchnnode,' / nextgoal ''geometry_msgs / pose2d');

为计划器创建订阅者,Cranslnode.

规划。CurVelSub = ros。订户(planningNode'/ currentvel''std_msgs / float64');Plann.Curposeub = ROS.Subscriber(Cranchnnode,' / currentpose ''geometry_msgs / pose2d');plann.desrvelsub = ros.subscriber(Cranchnnode,' / desiredvel ''std_msgs / float64');

创建订阅者,GoaleReachSub.,听取/达成目标主题,并指定回调操作。

GoalReachSub = ros。订户(planningNode'/达成目标'“std_msgs / Bool”);GoalReachSub。NewMessageFcn = @(~,msg)exampleHelperROSValetPlannerCallback(msg, planning, valet);

控制

控制节点负责纵向和横向控制器。此节点发布以下主题:

  • / steeringangle

  • / Accelcmd.

  • / decelcmd

  • / vehdir.

  • /达成目标

该节点订阅以下主题:

  • / smoothpath.

  • /方向

  • /速度

  • /湿润

  • / currentvel

  • / nextgoal.

  • / velprofile

接受A./ velprofile消息,节点运行exampleHelperROS2ValetControlCallback回调,它向车辆发送控制消息

创建一个控制器,controlNode,并在节点中设置发布者和订阅者。

controlNode = ros。节点(“控制”,masterhost);控制节点的%发布者控制。SteeringPub = ros。出版商(controlNode' / steeringangle ''std_msgs / float64');control.accelpub = ros.publisher(ControlNode,' / accelcmd ''std_msgs / float64');control.decelpub = ros.publisher(ControlNode,' / decelcmd ''std_msgs / float64');control.vehdirpub = ros.publisher(ControlNode,' / vehdir ''std_msgs / float64');control.vehgoalreachpub = ros.publisher(ControlNode,'/达成目标');控制节点的订阅者控制。PathSub = ros。订户(controlNode' / smoothpath ');控制。DirSub = ros。订户(controlNode' /方向');控制。SpeedSub = ros。订户(controlNode' /速度');控制。CurPoseSub = ros。订户(controlNode' / currentpose ');控制。CurVelSub = ros。订户(controlNode'/ currentvel');控制。NextGoalSub = ros。订户(controlNode' / nextgoal ');%为控制节点/velprofile创建订阅者并提供回调函数。velprofsub = ros.subscriber(ControlNode,' / velprofile ');VelProfSub.NewMessageFcn = @(〜,MSG)exampleHelperROSValetControlCallback(MSG,控制,收费);

车辆

Vehicle节点负责仿真车辆模型。此节点发布以下主题:

  • / currentvel

  • /湿润

该节点订阅以下主题:

  • / Accelcmd.

  • / decelcmd

  • / vehdir.

  • / steeringangle

接受A./ steeringangle消息,车辆模拟器在回调函数中运行,exampleHelperROSValetVehicleCallback

创建车辆节点。vehiclenode = ros.node(“汽车”,masterhost);%为车辆节点创建发布商。车辆。CurVelPub = ros。出版商(vehicleNode'/ currentvel');车辆。CurPosePub = ros。出版商(vehicleNode' / currentpose ');%为车辆节点创建订阅者。车辆。AccelSub = ros。订户(vehicleNode' / accelcmd ');车辆。DecelSub = ros。订户(vehicleNode' / decelcmd ');车辆。DirSub = ros。订户(vehicleNode' / vehdir ');%创建用户|/方向盘角度|,用于运行车辆模拟器% 打回来。SteeringSub = ros。订户(vehicleNode' / steeringangle '......@(〜,msg)examplehelperrosvaletvehiclecallballballballballballballballballballballballballballballballballballballballballballballballballballballballballballballack;

初始化模拟

要初始化模拟,请发送第一个速度消息和当前姿势消息。此消息导致策划器启动计划循环。

curvelmsg = getrosmessage(车辆.curvelpub.messageType);curvelmsg.data = valet.vehiclesim.getvehiclevelocity;发送(车辆.Curvelpub,CurvelMsg);curposemsg = getrosmessage(车辆.curposepub.messageType);curposemsg.x = valet.currentospose(1);curposemsg.y = valet.currentosht(2);curposemsg.theta = valet.currentospose(3);发送(车辆.Curposepub,curposemsg);REACHMSG = GETROSMESSAGE(CONTROL.VEHGOALREACHPUB.MESSAGETYPE);REACHMSG.DATA = TRUE; send(control.VehGoalReachPub, reachMsg);

主循环

主循环等待behavioralPlanner要说车辆达到了预先售前。

〜达到的临时(valet.behavioralplanner)暂停(1);结尾显示车辆模拟数字。showFigure (valet.vehicleSim);

公园机动

停车操纵回调与正常驾驶Manueuver略有不同。替换回调/ velprofile/达成目标订阅者。

velprofsub.newmessagefcn = @(〜,msg)examplehelperrosvaletparkControlcallback(msg,控制,代客);GoaleReachSub.NewMessageFCN = @(〜,msg)examplehelperrosvaletparkmaneuver(msg,规划,植物);暂停(1);REACHMSG = GETROSMESSAGE(CONTROL.VEHGOALREACHPUB.MESSAGETYPE);READMSG.DATA = FALSE;发送(Control.VehgoalReachpub,ReadeMsg);%使用订阅者从|/reachgoal|主题接收消息。这%等待,直到收到新消息。显示图。车辆%已完成完整的自动化代客Manuever。收到(GoalReachSub);exampleHelperROSValetCloseFigures;snapnow;

通过清除发布者、订阅者和节点句柄来删除模拟器并关闭所有节点。

删除(valet.vehicleSim);上面创建的%清除变量。清除('valet');GoaleReachSub.NewMessageFCN = [];valprofsub.newmessagefcn = [];清除(“规划”“planningNode”“GoalReachSub”);清除(“控制”“controlNode”'velprofsub');清除(“汽车”'vehiclenode'“SteeringSub”);清除('curposemsg'“curVelMsg”“reachMsg”);清除('masterhost');%关闭ROS网络。rosshutdown;
使用nodeuri关闭全局节点/ matlab_global_node_49911 http:// sbd508773glnxa64:42335 /关闭ros master http://192.168.0.0.10:10.10:60903。.....