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

Revision history [back]

click to hide/show revision 1
initial version

Hi,

To spawn a urdf.xacro file in gazebo you have to first convert xacro file using xacro.py script. For example if you have robot.xacro.urdf file in a package called robot_package then following launch file will spawn your robot in Gazebo.

<launch>
<!-- Convert xacro and put on parameter server -->
<param name="robot_description" command="$(find xacro)/xacro.py $(find robot_package)/urdf/robot.urdf.xacro" />

<!-- Spawn a robot into Gazebo -->
<node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" args="-param robot_description -urdf -model robot" />
</launch>

Note: Replace the node and package if you are using simulator_gazebo and not stand alone gazebo accordingly. Additionally: you can find more details in this tutorial and its better to ask gazebo related questions on Gazebo sim forum. To add color in gazebo navigate to the file gazebo.material in materials/scripts folder of your gazebo and include your own color definition. Other colors are defined there you can follow the pattern. To assign this color to a model use following code in your file.

<material>
     <script>Gazebo/yourcolor</script>
</material>

Note: This code is for SDF 1.4 change accordingly for your version see documentation hereSDF.

Hi,

To spawn a urdf.xacro file in gazebo you have to first convert xacro file using xacro.py script. For example if you have robot.xacro.urdf file in a package called robot_package then following launch file will spawn your robot in Gazebo.

<launch>
<!-- Convert xacro and put on parameter server -->
<param name="robot_description" command="$(find xacro)/xacro.py $(find robot_package)/urdf/robot.urdf.xacro" />

<!-- Spawn a robot into Gazebo -->
<node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" args="-param robot_description -urdf -model robot" />
</launch>

Note: Replace the node and package if you are using simulator_gazebo and not stand alone gazebo accordingly. Additionally: Additionally, you can find more details in this tutorial and its better to ask gazebo related questions on Gazebo sim forum. .

To add color in gazebo navigate to the file gazebo.material in materials/scripts folder of your gazebo and include your own color definition. Other colors are defined there you can follow the pattern. To assign this color to a model use following code in your file.

<material>
     <script>Gazebo/yourcolor</script>
</material>

Note: This code is for SDF 1.4 change accordingly for your version see documentation hereSDF.