This tutorial will cover how to spawn a URDF model in Gazebo Sim. URDF files are often used in ROS to represent robot models. While SDF can describe a world with multiple robot models, URDF can only describe one robot model. More information about URDF can be found at?urdf - ROS Wiki.
This tutorial assumes that the reader already has a URDF file that they'd like to load into Gazebo Sim. If you are looking for a URDF file to use, you can use the?rrbot.urdf?that was preprocessed for you. The?rrbot
?robot model is from the?gazebo_ros_demos?package. You could also use one of the examples listed at?urdf/Examples - ROS Wiki.
If you have a?xacro
?representation of a robot model, you can turn the?xacro
?file into a?URDF
?file using the?xacro?package: see?this tutorial?for more information.
如果你使用的是xacro文件,需要先转换为urdf文件
To spawn a URDF model in Gazebo Sim, we will start a world and make use of the world's?create
?service, which uses the?EntityFactory?message type.
Start by launching an empty world in Gazebo Sim:
ign gazebo empty.sdf
You should see a window that looks like this:
In another terminal, get the list of available services by running?ign service -l
. Look for a?create
?service. You should see this service in the list:
/world/empty/create
We can double-check that this is the service we want to use by running?ign service -is /world/empty/create
. This will show us the service's request and response message types:
ignition.msgs.EntityFactory, ignition.msgs.Boolean
Now that we have found the service that has an?EntityFactory
?request type, we can call this service and pass the URDF file to the service's request so that the robot represented by this URDF file is spawned in the Gazebo Sim world. We do this by setting the desired URDF file to the?sdf_file_name
?field of the?EntityFactory
?request message. The?libsdformat?library will then internally convert the URDF file to an SDF representation, and load this into the running world.
The following command spawns the URDF file?model.urdf
?into the Gazebo Sim world as a model named?urdf_model
:
ign service -s /world/empty/create --reqtype ignition.msgs.EntityFactory --reptype ignition.msgs.Boolean --timeout 1000 --req 'sdf_filename: "/path/to/model.urdf", name: "urdf_model"'
If?model.urdf
?is the URDF representation of?rrbot.xacro?in the?gazebo_ros_demos
?package, executing the service call above should result in a simulation that now looks like this:
只要把上面这个命令的/path/to/model.urdf 改为自己的urdf文件的绝对路径就可以了,其他都不要改
We can now play the simulation to make sure that the loaded URDF model behaves as expected:
?这个是我才用此文章方法显示出来的。需要注意的是在设置路径的时候需要绝对路径,不能设置相对路径,包括~/gazebo这样的路径都是不行的,一定是以? /? 开头的路径例如?
这个是对的/home/actorsun/test/total.urdf.但是后面这个就是错的:~/test/total.urdf
虽然看上去好像都一个true但是结果会不一样