How to set the initial camera pose in Gazebo

Sometimes the default camera pose of the Gazebo user interface after start-up is not necessarily the same that you, as a simulation user, would prefer. However, this can be rectified by setting the initial camera pose in Gazebo by first obtaining your desired camera pose and subsequently defining it using SDF format in your world file.

Note: The content of this article applies to Gazebo Harmonic 8.6.0. Same or similar principles apply to other versions of Gazebo, though the specific implementation details may differ.

Step #1) Obtain the desired camera pose using the “View Angle” plugin

As a first step start Gazebo followed by loading the “View Angle” plugin. Now use your mouse (or internal Gazebo functions such as “Move to”) to set your camera to your desired pose. Note down your values for position (X, Y, Z) and orientation (Roll, Pitch, Yaw).

Video Gazebo View Angle

Obtain the current camera pose using the Gazebo “View Angle” plugin

Step #2) Set initial camera pose in Gazebo by defining it using the “MinimalScene” GUI plugin

Gazebo contains numerous GUI plugins including one called MinimalScene which can be used to configure various scene related parameters as well as define the initial camera pose using the <camera_pose> tag. The <camera_pose> tag expects the initial camera position to be defined in the format of <camera_pose>X Y Z Roll Pitch Yaw</camera_pose>, position in meters, Euler angles in radians. The MinimalScene plugin needs to be loaded by defining it within the SDF file defining your simulation world.

<sdf version="1.8">
  <world name="default">
    <gui fullscreen="0">
      <!-- 3D scene -->
      <plugin filename="MinimalScene" name="3D View">
        <gz-gui>
          <title>3D View</title>
          <property type="bool" key="showTitleBar">false</property>
          <property type="string" key="state">docked</property>
        </gz-gui>
        <engine>ogre2</engine>
        <scene>scene</scene>
        <ambient_light>0.4 0.4 0.4</ambient_light>
        <background_color>0.8 0.8 0.8</background_color>
        <camera_pose>-7.90 -0.03 6.03 0.00 0.36 0.02</camera_pose>
        <camera_clip>
          <near>0.25</near>
          <far>25000</far>
        </camera_clip>
      </plugin>
    </gui>
  </world>
</sdf>
How to set the initial camera pose in Gazebo

Alexander Entinger is a highly experienced embedded engineer with a focus on robotic systems. By providing hard-won expertise designing embedded systems for real-world embedded applications Alexander Entinger is helping companies developing robotic systems or components for robotic systems to achieve their desired business outcomes.