This example is an extension to theSimulate a Mobile Robot in a Warehouse Using Gazebo的例子。这个例子显示了to change the PRM path planner with an A* planner, and add a vector field histogram (VFH) algorithm to avoid obstacles.
Prerequisites
Review theSimulate a Mobile Robot in a Warehouse Using Gazeboexample to setup the sensing and actuation elements. This example goes over how to download and use a virtual machine (VM) to setup a simulated robot.
Review theExecute Tasks for a Warehouse Robotexample for the workflow of path planning and navigating in a warehouse scenario.
There are two major changes to this model from theExecute Tasks for a Warehouse Robot的例子。The goal is to replace the path planner algorithm used and add a controller that avoids obstacles in the environment.
ThePlannerMATLAB® Function Block now uses theplannerAStarGrid
(Navigation Toolbox)object to run the A* path planning algorithm.
TheObstacle Avoidancesubsystem now uses aVector Field Histogramblock as part of the controller. TherangeReadings
function block outputs the ranges and angles when the data received is not empty. The VFH block then generates a steering direction based on obstacles within the scan range. For close obstacles, the robot should turn to drive around them. Tune the VFH parameters for different obstacle avoidance performance.
open_system("aStarPathPlanningAndObstacleAvoidanceInWarehouse.slx");
Load the example map file,map
, which is a matrix of logical values indicating occupied space in the warehouse. Invert this matrix to indicate free space, and create abinaryOccupancyMap
object. Specify a resolution of 100 cells per meter.
The map is based off of theobstacleAvoidanceWorld.world
, which is loaded in the VM. A PNG-file was generated to use as the map matrix with thecollision_map_creator_plugin
plugin. For more information, seeCollision Map Creator Plugin.
close figure("Name","Warehouse Map","Visible","on") loadexampleHelperWarehouseRobotWithGazeboBuses.matloadhelperPlanningAndObstacleAvoidanceWarehouseMap.matmaplogicalMap = map.getOccupancy; mapScalingFactor = 100; show(map)
Assign thexy-locations of the charging station, sorting station, and the unloading location near shelves in the warehouse. The values chosen are based on the simlated world in Gazebo.
chargingStn = [2, 13]; loadingStn = [15, 5]; unloadingStn = [15, 15];
Show the various locations on the map.
holdon; localOrigin = map.LocalOriginInWorld; localTform = trvec2tform([localOrigin 0]); text(chargingStn(1), chargingStn(2),1,'Charging'); plotTransforms([chargingStn, 0],[1 0 0 0]) text(loadingStn(1), loadingStn(2),1,'Loading Station'); plotTransforms([loadingStn, 0], [1 0 0 0]) text(unloadingStn(1), unloadingStn(2),1,'Unloading Station'); plotTransforms([unloadingStn, 0], [1 0 0 0]) holdoff;
To simulate the scenario, set up the connection to Gazebo.
First, run the Gazebo Simulator. In the virtual machine, click theGazebo Warehouse Robot with Obstaclesicon. If the Gazebo simulator fails to open, you may need to reinstall the plugin. SeeInstall Gazebo Plugin ManuallyinPerform Co-Simulation between Simulink and Gazebo.
在仿真金宝app软件,打开Gazebo Pacerblock and clickConfigure Gazebo network and simulation settings. Specify theNetwork AddressasCustom,theHostname/IP Addressfor your Gazebo simulation, and aPortof14581
, which is the default port for Gazebo. The desktop of the VM displays the IP address.
For more information about connecting to Gazebo to enable co-simulation, seePerform Co-Simulation between Simulink and Gazebo.
Click theInitialize Modelbutton at the top of the model to intialize all the variables declared above.
Runthe simulation. The robot drives around the environment and avoids unexepected obstacles.
sim卡("aStarPathPlanningAndObstacleAvoidanceInWarehouse.slx");
Notice that there are a two cylindrical obstacles which are not present on the occupancy map. The robot still avoids them when detected using the VFH algorithm.
A green lamp AvoidingObstacle lights up when the robot is trying to avoid an obstacle.