simulate a mobile robot in a warehouse using gazebo -凯发k8网页登录
this example shows how to simulate a warehouse robot in gazebo. gazebo enabled you to simulate a mobile robot that uses a range sensor, while executing certain tasks in a simulated environment. this example details how to use a simulator to apply the example, where a robot delivers packages in a warehouse scenario. the robot makes use of the simulated range sensor in gazebo to detect possible collisions with a dynamic environment and avoid them.
prerequisites
download a to set up a simulated robot.
review the example for the workflow of path planning and navigating in a warehouse scenario.
review the example for basic steps of collecting sensor data and controlling a robot in gazebo.
model overview
open the model.
open_system('simulatewarehouserobotingazebo.slx')
the model can be divided into the following elements:
sense: read data from sensors in gazebo.
schedule: assign packages and plan paths for robots to deliver the packages.
control: generate commands to follow the predefined path and avoid obstacles.
actuate: send commands to gazebo to actuate the robot in the environment.
schedule
the robot performs the task of going between the charging station, the loading station, and the unloading station as guided by the scheduler.
sense
the current robot pose, the wheel speeds, and the range sensor readings are read from the simulated environment in gazebo. the figure below is the expanded view of the read from gazebo sensors subsystem.
control
the controller generates control commands for following the waypoints using the pure pursuit block. if the range sensor on the robot detects an obstacle within the avoidcollisiondistance
threshold, the robot stops. also, the robot stops when gets near enough to the goal.
actuate
based on the generated control commands, the pioneer wheel control subsystem generates a torque value for each wheel. the torque is applied as an applyjointtorque
command.
setup
warehouse facility
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 make a binaryoccupancymap
object. specify a resolution of 100 cells per meter.
the map is based off of the warehouseextensions.world
file, which was made using the building editor on the same scaling factor as mentioned below. a .png
file for the map can be made using the collision_map_creator_plugin
plugin to generate the map matrix. the details on how to install the plugin can be found at .
mapscalingfactor = 100; load gazebowarehousemap.mat map logicalmap = ~map; map = binaryoccupancymap(logicalmap,mapscalingfactor); show(map)
assign the xy-locations of the charging station, sorting station, and the unloading location near shelves in the warehouse. the values chosen are based on the simulated world in gazebo.
chargingstn = [12,5]; loadingstn = [24,5]; unloadingstn = [15,24];
show the various locations on the map.
hold on; text(chargingstn(1), chargingstn(2), 1, 'charging'); plottransforms([chargingstn, 0], [1 0 0 0]) text(loadingstn(1), loadingstn(2), 1, 'sorting station'); plottransforms([loadingstn, 0], [1 0 0 0]) text(unloadingstn(1), unloadingstn(2), 1, 'unloading station'); plottransforms([unloadingstn, 0], [1 0 0 0]) hold off;
range sensor
the read lidar scan block in the section is used to read the range values from the simulated range sensor. the warehouseextensions.world
file contains the details of the various models and actors (warehouse workers) in the scene. because <actor>
tags are static links with only visual meshes, the sensor type of the range sensor is gpu_ray
.
additionally, the range sensor uses 640 range, but the default is 128. this requires modification of the buses used in the in the read lidar scan block. load the examplehelperwarehouserobotwithgazebobuses.mat
file to get a modified bus with gazebo_sl_bus_gazebo_msgs_laserscan.range
set to 640. the modified buses were saved to a .mat
file using the type editor.
load examplehelperwarehouserobotwithgazebobuses.mat
collision avoidance
the actors in the world are walking a predefined trajectory. the robot makes use of a range sensor to check for obstacles within a range of 2.0 m (avoidcollisiondistance)
with range angles from [-pi/10, pi/10]
upon a non-zero reading within that range and view, the robot stops and only resumes after the range is clear. the "stop robot on sensing obstacles" function block incorporates this logic.
while running the simulation, the stop lamp turns green when the robot senses that it is good to proceed. if it has stopped the lamp turns red.
avoidcollisiondistance = 2;
simulate
to simulate the scenario, set up the connection to gazebo.
first, run the gazebo simulator. in the virtual machine, click the gazebo warehouse robot icon. if the gazebo simulator fails to open, you may need to reinstall the plugin. see install gazebo plugin manually in perform co-simulation between simulink and gazebo.
in simulink, open the gazebo pacer block and click configure gazebo network and simulation settings. specify the network address as custom, the hostname/ip address for your gazebo simulation, and a port of 14581
, 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, see perform co-simulation between simulink and gazebo.
click the initialize model button at the top of the model to initialize all the variables declared above.
run the simulation. the robot drives around the environment and stops whenever a worker gets within the defined threshold.