ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
My understanding of this suggests to me that I need two files, a .urdf.xacro for the visual part and a .gazebo.xacro for the various sensors and plugin.
You are generally correct, but it's not strictly necessary to separate the files like that. That is a convenient way to organize the information, but you can put it all in one file or several files if you want. The URDF tutorials are great for gaining a better understanding. Here's another one from Gazebo. One thing to note is that although the information may be in many separate files, there is one definition file that includes references to the others, so that's the only one you need in the launch file.
In the first launch file above, the definition is loaded from the URDF file ($(find turtlebot3_description)/urdf/turtlebot3_$(arg model).urdf.xacro
) to the robot_description
parameter:
<param name="robot_description" command="$(find xacro)/xacro --inorder $(find turtlebot3_description)/urdf/turtlebot3_$(arg model).urdf.xacro" />
Then, the -param
argument tells the spawn_urdf
node to load the description from a parameter, in this case named robot_description
. The -model
argument simply tells the node the name of model--not what it contains.
People often use the parameter method because the description is useful elsewhere, like in RViz, but you can also load it directly to the spawn_model
node, in which case you'd use the -file
argument instead of the -param
argument. That brings us to your error:
spawn_model: error: argument -param: not allowed with argument -file
The issue is that your telling the spawn_urdf
node to look in two different places for the model. You can only use one of these arguments at a time. In your case, I recommend deleting the file part and just using the param part like the first launch file. If the file loaded to robot_description
contains or includes references to your changes, it should work.
Let's say I wrote an entirely new description file, my_robot.urdf.xacro
. If I've divided the Gazebo parts into a separate file, I could include it with this line in my_robot.urdf.xacro
:
<xacro:include filename="$(find my_pkg)/urdf/my_robot.gazebo.xacro" />
Then I could spawn that model with this launch file:
<launch>
<arg name="x_pos" default="-1.0"/>
<arg name="y_pos" default="-6"/>
<arg name="z_pos" default="0.0"/>
<include file="$(find gazebo_ros)/launch/empty_world.launch">
<arg name="world_name" value="$(find multibot3)/worlds/turtlebot3_world.world"/>
<arg name="paused" value="false"/>
<arg name="use_sim_time" value="true"/>
<arg name="gui" value="true"/>
<arg name="headless" value="false"/>
<arg name="debug" value="false"/>
</include>
<param name="my_robot_description" command="$(find xacro)/xacro --inorder $(find my_pkg)/urdf/my_robot.urdf.xacro" />
<node pkg="gazebo_ros" type="spawn_model" name="spawn_urdf" args="-urdf -model my_robot_name -x $(arg x_pos) -y $(arg y_pos) -z $(arg z_pos) -param my_robot_description" />
</launch>
I changed the robot_description
parameter name to my_robot_description
for illustrative purposes. You can name the parameter whatever you want and reference it in the spawn node's arguments. robot_description
is pretty standard though, and some other code may look for it by default.
Hopefully, my rambling has helped, but feel free to ask for clarifications.
2 | No.2 Revision |
My understanding of this suggests to me that I need two files, a .urdf.xacro for the visual part and a .gazebo.xacro for the various sensors and plugin.
You are generally correct, but it's not strictly necessary to separate the files like that. That is a convenient way to organize the information, but you can put it all in one file or several files if you want. The URDF tutorials are great for gaining a better understanding. Here's another one from Gazebo. One thing to note is that although the information may be in many separate files, there is one definition file that includes references to the others, so that's the only one you need in the launch file.
In the first launch file above, the definition is loaded from the URDF file ($(find turtlebot3_description)/urdf/turtlebot3_$(arg model).urdf.xacro
) to the robot_description
parameter:
<param name="robot_description" command="$(find xacro)/xacro --inorder $(find turtlebot3_description)/urdf/turtlebot3_$(arg model).urdf.xacro" />
Then, the -param
argument tells the spawn_urdf
node to load the description from a parameter, in this case named robot_description
. The -model
argument simply tells the node the name of the model--not what it contains.
People often use the parameter method because the description is useful elsewhere, like in RViz, but you can also load it directly to the spawn_model
node, in which case you'd use the -file
argument instead of the -param
argument. That brings us to your error:
spawn_model: error: argument -param: not allowed with argument -file
The issue is that your you're telling the spawn_urdf
node to look in two different places for the model. You can only use one of these arguments at a time. In your case, I recommend deleting the file part and just using the param part like the first launch file. If the file loaded to robot_description
contains or includes references to your changes, it should work.
Let's say I wrote an entirely new description file, my_robot.urdf.xacro
. If I've divided the Gazebo parts into a separate file, I could include it with this line in my_robot.urdf.xacro
:
<xacro:include filename="$(find my_pkg)/urdf/my_robot.gazebo.xacro" />
Then I could spawn that model with this launch file:
<launch>
<arg name="x_pos" default="-1.0"/>
<arg name="y_pos" default="-6"/>
<arg name="z_pos" default="0.0"/>
<include file="$(find gazebo_ros)/launch/empty_world.launch">
<arg name="world_name" value="$(find multibot3)/worlds/turtlebot3_world.world"/>
<arg name="paused" value="false"/>
<arg name="use_sim_time" value="true"/>
<arg name="gui" value="true"/>
<arg name="headless" value="false"/>
<arg name="debug" value="false"/>
</include>
# Note: the `--inorder` option is default as of Melodic, so it's not necessary.
<param name="my_robot_description" command="$(find xacro)/xacro --inorder $(find my_pkg)/urdf/my_robot.urdf.xacro" />
<node pkg="gazebo_ros" type="spawn_model" name="spawn_urdf" args="-urdf -model my_robot_name -x $(arg x_pos) -y $(arg y_pos) -z $(arg z_pos) -param my_robot_description" />
</launch>
I changed the robot_description
parameter name to my_robot_description
for illustrative purposes. You can name the parameter whatever you want and reference it in the spawn node's arguments. robot_description
is pretty standard though, and some other code may look for it by default.
Hopefully, my rambling has helped, but feel free to ask for clarifications.