ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Spawn_model for gazebo.urdf files

asked 2021-02-08 03:52:19 -0600

Giuseppe_ gravatar image

updated 2021-02-08 18:08:34 -0600

jayess gravatar image

Hi,

I want to edit the file turtlebot3_world.launch that's code is the following in Melodic:

<launch>
  <arg name="model" default="$(env TURTLEBOT3_MODEL)" doc="model type [burger, waffle, waffle_pi]"/>
  <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="robot_description" command="$(find xacro)/xacro --inorder $(find turtlebot3_description)/urdf/turtlebot3_$(arg model).urdf.xacro" />

  <node pkg="gazebo_ros" type="spawn_model" name="spawn_urdf"  args="-urdf -model turtlebot3_$(arg model) -x $(arg x_pos) -y $(arg y_pos) -z $(arg z_pos) -param robot_description" />
</launch>

My question is this: 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. I want to modify this file to charge my definitions and not only that corresponding to turtlebot3, so based on my understanding (wrong I guess) I did this:

<launch>
  <arg name="model" default="$(env TURTLEBOT3_MODEL)" doc="model type [burger, waffle, waffle_pi]"/>
  <arg name="x_pos" default="-2.0"/>
  <arg name="y_pos" default="-0.5"/>
  <arg name="z_pos" default="0.0"/>

  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="world_name" value="$(find turtlebot3_gazebo)/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="robot_description" command="$(find xacro)/xacro --inorder $(find turtlebot3_description)/urdf/turtlebot3_$(arg model).urdf.xacro" />

  <node pkg="gazebo_ros" type="spawn_model" name="spawn_urdf"  args="-file /home/xyz/ros_ws/src/turtlebot3/turtlebot3_description/urdf/turtlebot3_$(arg model).gazebo.xacro -x $(arg x_pos) -y $(arg y_pos) -z $(arg z_pos) -param robot_description" />

</launch>

But then I get this error:

spawn_model: error: argument -param: not allowed with argument -file
[spawn_urdf-4] process has died [pid 3277, exit code 2, cmd /opt/ros/melodic/lib/gazebo_ros/spawn_model -file /home/xyz/ros_ws/src/turtlebot3/turtlebot3_description/urdf/turtlebot3_waffle_pi.gazebo.xacro -x -2.0 -y -0.5 -z 0.0 -param robot_description __name:=spawn_urdf __log:=/home/xyz/.ros/log/e5538a02-69f2-11eb-82a4-40b89aaac2f7/spawn_urdf-4.log].
log file: /home/xyz/.ros/log/e5538a02-69f2-11eb-82a4-40b89aaac2f7/spawn_urdf-4*.log
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-02-08 09:25:53 -0600

tryan gravatar image

updated 2021-02-08 15:34:50 -0600

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 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.

An Example

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 $(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 ...
(more)
edit flag offensive delete link more

Comments

@tryan much thanks to your detailed explanation, I think you solved my problem, I'll let you know ;) So I studied how it works xacro to understand better what you said

Giuseppe_ gravatar image Giuseppe_  ( 2021-02-08 14:14:59 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2021-02-08 03:52:19 -0600

Seen: 3,032 times

Last updated: Feb 08 '21