After a long time, I have been stuck on related issues. It turns out that because I can't understand the relationship between these files, I still write a post to record:
- Both urdf and sdf are model files and can be loaded in Gazebo;
- urdf can only represent a single robot, and sdf can express the entire environment and multiple robots, so Gazebo is pushing the sdf model, but most of the original work is based on urdf;
- urdf cannot define variables, so xacro can be defined through macros to define some "attributes";
- The sdf file is usually in a folder. The name of the folder is the name of the model we referenced when adding it. There is also a model.config file, meshes folder, materials folder, etc. Reference ~ / .gazebo / models / gas_station /;
- Both the urdf and xacro files use the <robot> tag to represent a robot, while the sdf file uses the <model> tag, and the other tags in it are also different. There may be some that can be converted between each other. For in-depth understanding, such as pysdf, refer here;
- urdf is a concept used in ROS, so it cannot be added to Gazebo in the world file, but it can be added in the launch file through the spawn_model method in the gazebo_ros package;
<launch> ... <node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" args="-file $(find MYROBOR_description)/urdf/bus_mass.urdf -urdf -z 1 -model MYROBOT" /> </launch>
- The sdf file can be directly added by reference in the world file;
<?xml version="1.0" ?> <sdf version="1.4"> <world name="default"> <include> <uri>model://ground_plane</uri> </include> <include> <uri>model://sun</uri> </include> <include> <uri>model://bus</uri> <name>bus</name> <pose>-2.0 7.0 0.0 0 0 0</pose> </include> </world> </sdf>
- Reference xacro file in launch:
<launch> <param name="robot_description" command="$(find xacro)/xacro '$(find MYROBOT_description)/urdf/MYROBOT.xacro'"/> <node name="spawn_model" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen" args="-urdf -x 0.0 -y 0.0 -z 0.0 -model ROBOT_NAME -param robot_description"/> </launch>