main content

automated parking valet with ros in matlab -凯发k8网页登录

this example shows how to distribute the automated parking valet (automated driving toolbox) application among various nodes in a ros network. depending on your system, this example is provided for ros and ros 2 networks using either matlab® or simulink® . the example shown here uses ros and matlab. for the other examples, see:

overview

this example is an extension of the automated parking valet (automated driving toolbox) example in automated driving toolbox™. a typical autonmous application has the following components.

for simplicity, this example concentrates on planning, control, and a simplified vehicle model. the example uses prerecorded data to substitute localization information.

this application demonstrates a typical split of various functions into ros nodes. the following picture shows how the above example is split into various nodes. each node: planning, control and vehicle is a ros node implementing the functionalities shown as below. the interconnections between the nodes show the topics used on each interconnection of the nodes.

setup

first, load a route plan and a given costmap used by the behavior planner and path analyzer. behavior planner, path planner, path analyzer, lateral and lognitudinal controllers are implemented by helper classes, which are setup with this example helper function call.

examplehelperrosvaletsetupglobals;

the initialized globals are organized as fields in the global structure, valet.

disp(valet)
            maplayers: [1×1 struct]
              costmap: [1×1 vehiclecostmap]
          vehicledims: [1×1 vehicledimensions]
     maxsteeringangle: 35
                 data: [1×1 struct]
            routeplan: [4×3 table]
          currentpose: [4 12 0]
           vehiclesim: [1×1 examplehelperrosvaletvehiclesimulator]
    behavioralplanner: [1×1 examplehelperrosvaletbehavioralplanner]
        motionplanner: [1×1 pathplannerrrt]
             goalpose: [56 11 0]
              refpath: [1×1 driving.path]
      transitionposes: [14×3 double]
           directions: [522×1 double]
           currentvel: 0
     approxseparation: 0.1000
       numsmoothposes: 522
             maxspeed: 5
           startspeed: 0
             endspeed: 0
             refposes: [522×3 double]
           cumlengths: [522×1 double]
           curvatures: [522×1 double]
        refvelocities: [522×1 double]
           sampletime: 0.1000
        loncontroller: [1×1 examplehelperrosvaletlongitudinalcontroller]
          controlrate: [1×1 examplehelperrosvaletfixedrate]
         pathanalyzer: [1×1 examplehelperrosvaletpathanalyzer]
             parkpose: [36 44 90]

initialize the ros network.

rosinit;
launching ros core...
..................................................................................done in 5.3625 seconds.

initializing ros master on http://192.168.0.10:60903.
initializing global node /matlab_global_node_49911 with nodeuri http://sbd508773glnxa64:42335/
masterhost = 'localhost';

the functions in the application are distributed amongst ros nodes. this example uses three ros nodes: planningnode, controlnode, and vehiclenode.

planning

the planning node calculates each path segment based on the current vehicle position. this node is responsible for generating the smooth path and publishes the path to the network.

this node publishes these topics:

  • /smoothpath

  • /velprofile

  • /directions

  • /speed

  • /nextgoal

the node subscribes to these topics:

  • /currentvel

  • /currentpose

  • /desiredvel

  • /reachgoal

on receiving a /reachgoal message, the node runs the examplehelperros2valetplannercallback callback, which plans the next segment.

create the planning node

planningnode = ros.node('planning', masterhost);

create publishers for planning node. specify the message types for the publisher or subscriber for a topic that is not present on ros network.

planning.pathpub = ros.publisher(planningnode, '/smoothpath', 'std_msgs/float64multiarray');
planning.velpub = ros.publisher(planningnode, '/velprofile', 'std_msgs/float64multiarray');
planning.dirpub = ros.publisher(planningnode, '/directions', 'std_msgs/float64multiarray');
planning.speedpub = ros.publisher(planningnode,'/speed','std_msgs/float64multiarray');
planning.nxtpub = ros.publisher(planningnode, '/nextgoal', 'geometry_msgs/pose2d');

create the subscribers for the planner, planningnode.

planning.curvelsub = ros.subscriber(planningnode, '/currentvel', 'std_msgs/float64');
planning.curposesub = ros.subscriber(planningnode, '/currentpose', 'geometry_msgs/pose2d');
planning.desrvelsub = ros.subscriber(planningnode, '/desiredvel', 'std_msgs/float64');

create subscriber, goalreachsub, to listen to the /reachgoal topic of planning node and specify the callback action.

goalreachsub = ros.subscriber(planningnode, '/reachgoal', 'std_msgs/bool');
goalreachsub.newmessagefcn = @(~,msg)examplehelperrosvaletplannercallback(msg, planning, valet);

control

the control node is responsible for longitudinal and lateral controllers. this node publishes these topics:

  • /steeringangle

  • /accelcmd

  • /decelcmd

  • /vehdir

  • /reachgoal

the node subscribes to these topics:

  • /smoothpath

  • /directions

  • /speed

  • /currentpose

  • /currentvel

  • /nextgoal

  • /velprofile

on receiving a /velprofile message, the node runs the examplehelperros2valetcontrolcallback callback, which sends control messages to the vehicle

create the controller, controlnode, and setup the publishers and subscribers in the node.

controlnode = ros.node('control', masterhost);
% publishers for controlnode
control.steeringpub = ros.publisher(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, '/reachgoal');
% subscribers for controlnode
control.pathsub = ros.subscriber(controlnode, '/smoothpath');
control.dirsub = ros.subscriber(controlnode, '/directions');
control.speedsub = ros.subscriber(controlnode, '/speed');
control.curposesub = ros.subscriber(controlnode, '/currentpose');
control.curvelsub = ros.subscriber(controlnode, '/currentvel');
control.nextgoalsub = ros.subscriber(controlnode, '/nextgoal');
% create subscriber for /velprofile for control node and provide the callback function.
velprofsub = ros.subscriber(controlnode, '/velprofile');
velprofsub.newmessagefcn = @(~,msg)examplehelperrosvaletcontrolcallback(msg, control, valet);

vehicle

the vehicle node is responsible for simulating the vehicle model. this node publishes these topics:

  • /currentvel

  • /currentpose

the node subscribes to these topics:

  • /accelcmd

  • /decelcmd

  • /vehdir

  • /steeringangle

on receiving a /steeringangle message, the vehicle simulator is run in the callback function, examplehelperrosvaletvehiclecallback.

examplehelperrosvaletvehiclenode.png

% create vehicle node.
vehiclenode = ros.node('vehicle', masterhost);
% create publishers for vehicle node.
vehicle.curvelpub = ros.publisher(vehiclenode, '/currentvel');
vehicle.curposepub = ros.publisher(vehiclenode, '/currentpose');
% create subscribers for vehicle node.
vehicle.accelsub = ros.subscriber(vehiclenode, '/accelcmd');
vehicle.decelsub = ros.subscriber(vehiclenode, '/decelcmd');
vehicle.dirsub = ros.subscriber(vehiclenode, '/vehdir');
% create subscriber for |/steeringangle|, which runs the vehicle simulator 
% callback.
steeringsub = ros.subscriber(vehiclenode, '/steeringangle', ...
    @(~,msg)examplehelperrosvaletvehiclecallback(msg, vehicle, valet));

initialize simulation

to initialize the simulation, send the first velocity message and current pose message. this message causes the planner to start the planning loop.

curvelmsg = getrosmessage(vehicle.curvelpub.messagetype);
curvelmsg.data = valet.vehiclesim.getvehiclevelocity;
send(vehicle.curvelpub, curvelmsg);
curposemsg = getrosmessage(vehicle.curposepub.messagetype);
curposemsg.x = valet.currentpose(1);
curposemsg.y = valet.currentpose(2);
curposemsg.theta = valet.currentpose(3);
send(vehicle.curposepub, curposemsg);
reachmsg = getrosmessage(control.vehgoalreachpub.messagetype);
reachmsg.data = true;
send(control.vehgoalreachpub, reachmsg);

main loop

the main loop waits for the behavioralplanner to say the vehicle reached the prepark position.

while ~reacheddestination(valet.behavioralplanner)
    pause(1);
end
% show the vehicle simulation figure.
showfigure(valet.vehiclesim);

park maneuver

the parking maneuver callbacks are slightly different from the normal driving manueuver. replace the callbacks for the /velprofile and /reachgoal subscribers.

velprofsub.newmessagefcn = @(~,msg)examplehelperrosvaletparkcontrolcallback(msg, control, valet);
goalreachsub.newmessagefcn = @(~,msg)examplehelperrosvaletparkmaneuver(msg, planning, valet);
pause(1);
reachmsg = getrosmessage(control.vehgoalreachpub.messagetype);
reachmsg.data = false;
send(control.vehgoalreachpub, reachmsg);
% receive a message from the |/reachgoal| topic using the subcriber. this 
% waits until a new message is received. display the figure. the vehicle
% has completed the full automated valet manuever.
receive(goalreachsub);
examplehelperrosvaletclosefigures;
snapnow;

delete the simulator and shutdown all the nodes by clearing publishers, subscribers and node handles.

delete(valet.vehiclesim);
% clear variables that were created above.
clear('valet');
goalreachsub.newmessagefcn = [];
velprofsub.newmessagefcn = [];
clear('planning', 'planningnode', 'goalreachsub');
clear('control', 'controlnode', 'velprofsub');
clear('vehicle', 'vehiclenode', 'steeringsub');
clear('curposemsg', 'curvelmsg', 'reachmsg');
clear('masterhost');
% shutdown the ros network.
rosshutdown;
shutting down global node /matlab_global_node_49911 with nodeuri http://sbd508773glnxa64:42335/
shutting down ros master on http://192.168.0.10:60903.
.....
网站地图