Files
RDC_Simulation/docs/gazebo_worlds.md

3.9 KiB

Custom Gazebo Worlds

Create custom environments for the ARG simulation.

Quick Start

  1. Copy template world:
cp gazebo/worlds/custom_landing.sdf gazebo/worlds/my_world.sdf
  1. Edit the world file

  2. Run:

./scripts/run_ardupilot_sim.sh gazebo/worlds/my_world.sdf

World Structure

<?xml version="1.0" ?>
<sdf version="1.9">
  <world name="my_world">
    
    <!-- Required plugins -->
    <plugin filename="gz-sim-physics-system" name="gz::sim::systems::Physics"/>
    <plugin filename="gz-sim-sensors-system" name="gz::sim::systems::Sensors"/>
    <plugin filename="gz-sim-user-commands-system" name="gz::sim::systems::UserCommands"/>
    <plugin filename="gz-sim-scene-broadcaster-system" name="gz::sim::systems::SceneBroadcaster"/>
    <plugin filename="gz-sim-imu-system" name="gz::sim::systems::Imu"/>
    
    <!-- Physics -->
    <physics name="1ms" type="ode">
      <max_step_size>0.001</max_step_size>
      <real_time_factor>1.0</real_time_factor>
    </physics>
    
    <!-- Lighting -->
    <light type="directional" name="sun">
      <pose>0 0 10 0 0 0</pose>
      <diffuse>0.8 0.8 0.8 1</diffuse>
    </light>
    
    <!-- Ground -->
    <model name="ground">
      <static>true</static>
      <link name="link">
        <collision name="collision">
          <geometry><plane><normal>0 0 1</normal></plane></geometry>
        </collision>
        <visual name="visual">
          <geometry><plane><normal>0 0 1</normal><size>100 100</size></plane></geometry>
        </visual>
      </link>
    </model>
    
    <!-- Your models here -->
    
    <!-- ArduPilot drone (required) -->
    <include>
      <uri>model://iris_with_ardupilot</uri>
      <name>iris</name>
      <pose>0 0 0.195 0 0 0</pose>
    </include>
    
  </world>
</sdf>

Adding Objects

Basic Shapes

<model name="box">
  <static>true</static>
  <pose>5 0 0.5 0 0 0</pose>
  <link name="link">
    <collision name="collision">
      <geometry><box><size>1 1 1</size></box></geometry>
    </collision>
    <visual name="visual">
      <geometry><box><size>1 1 1</size></box></geometry>
      <material>
        <ambient>0.8 0.2 0.2 1</ambient>
      </material>
    </visual>
  </link>
</model>

Cylinder

<model name="cylinder">
  <static>true</static>
  <pose>0 5 1 0 0 0</pose>
  <link name="link">
    <collision name="collision">
      <geometry><cylinder><radius>0.5</radius><length>2</length></cylinder></geometry>
    </collision>
    <visual name="visual">
      <geometry><cylinder><radius>0.5</radius><length>2</length></cylinder></geometry>
    </visual>
  </link>
</model>

Include Model

<include>
  <uri>model://my_custom_model</uri>
  <name>obstacle_1</name>
  <pose>3 4 0 0 0 0.5</pose>
</include>

Landing Pad with Rover

<model name="landing_pad">
  <static>false</static>
  <pose>0 0 0.05 0 0 0</pose>
  <link name="base">
    <inertial><mass>10</mass></inertial>
    <collision name="collision">
      <geometry><cylinder><radius>0.75</radius><length>0.1</length></cylinder></geometry>
    </collision>
    <visual name="visual">
      <geometry><cylinder><radius>0.75</radius><length>0.1</length></cylinder></geometry>
      <material><diffuse>0.2 0.8 0.2 1</diffuse></material>
    </visual>
  </link>
  <plugin filename="gz-sim-velocity-control-system" name="gz::sim::systems::VelocityControl">
    <topic>/landing_pad/cmd_vel</topic>
  </plugin>
</model>

Camera Sensor

Add to drone or create camera model:

<sensor name="camera" type="camera">
  <pose>0 0 -0.1 0 1.5708 0</pose>
  <always_on>true</always_on>
  <update_rate>30</update_rate>
  <camera>
    <horizontal_fov>1.047</horizontal_fov>
    <image>
      <width>640</width>
      <height>480</height>
    </image>
  </camera>
  <topic>/drone/camera</topic>
</sensor>

Tips

  • Use <static>true</static> for non-moving objects
  • Pose format: x y z roll pitch yaw
  • Angles are in radians
  • Colors are RGBA (0-1 range)