Skip to main content

2-2-gazebo-simulation-engine

Gazebo Simulation Engine

At the heart of our digital twin is the simulation engine responsible for recreating the laws of physics. For this, we turn to Gazebo, a powerful and widely-used 3D robotics simulator. Gazebo is more than just a visualizer; it's a robust physics engine that can simulate complex robots and their interactions with the environment in three-dimensional space.

The Physics Engine: ODE, DART, and Bullet

Gazebo is designed to be modular, and this includes its physics engine. It allows you to choose from several different engines, each with its own strengths and weaknesses. The most common ones are:

  • ODE (Open Dynamics Engine): This is the default physics engine in Gazebo. It is a mature, open-source engine that is well-suited for a wide variety of robotics applications. It's known for its speed and stability, particularly in scenarios with many non-interpenetrating contacts.
  • Bullet: Bullet is another popular open-source physics engine, widely known for its use in video games and movies. It's highly optimized for performance and provides excellent support for collision detection and rigid body dynamics.
  • DART (Dynamic Animation and Robotics Toolkit): DART is specifically designed for robotics and biomechanics. Its key feature is its handling of contact and friction, which can be more accurate for complex multi-joint robots (like humanoids) than other engines. However, it can be more computationally intensive.
  • Simbody: Another engine often used for biomechanical and complex articulated systems.

For most of our work with humanoid robots, the default ODE engine provides a good balance of performance and accuracy. However, knowing that other options exist is crucial for advanced use cases where you might need to optimize for specific physical phenomena.

SDF vs. URDF: Describing the World and the Robot

To simulate a robot, you first need to describe it: its links (the solid parts), its joints (the connections between links), its visual appearance, and its physical properties. In the ROS ecosystem, two main formats are used for this:

  • URDF (Unified Robot Description Format): URDF is an XML format developed by ROS to describe the kinematics and dynamics of a single robot. It defines the robot's structure as a tree of links connected by joints. It's excellent for modeling the robot's geometry, mass, and joint types. However, URDF has a key limitation: it can only represent a tree structure and cannot describe a closed-loop chain (like a four-bar linkage) or the environment the robot is in.

  • SDF (Simulation Description Format): SDF is an XML format developed specifically for Gazebo. It is a superset of URDF and is much more powerful. With SDF, you can describe everything in the simulation: multiple robots, static objects (like walls and tables), lighting, sensors, and even the physics engine parameters. SDF is the native language of Gazebo.

So how do they work together?

Gazebo internally uses SDF. When you load a URDF file into Gazebo, it is automatically converted into an SDF file behind the scenes. This works well for most robots.

Here’s a simple breakdown:

  • Use URDF for: Defining your robot's model in a way that is portable across the ROS ecosystem (e.g., for use with RViz, MoveIt, etc.). It is the standard for robot modeling in ROS.
  • Use SDF for: Defining the entire simulation world, including environmental props, lighting, and multiple robots. You can also write your robot models directly in SDF for more Gazebo-specific features.

Key Takeaway: Model your robot in URDF for ROS compatibility. Model your simulation world in SDF. Gazebo will handle the conversion.

Spawning Humanoid Models

Once you have a robot description (typically in URDF), you can "spawn" it into a running Gazebo simulation. This is usually done through a ROS 2 service call provided by the gazebo_ros_pkgs. You provide the robot description, a name for the robot, and its initial position and orientation in the world. The robot model will then appear in the Gazebo client, and the physics engine will take over.

Simulating Gravity, Collisions, and Friction

This is where the magic of Gazebo happens. Once your humanoid is spawned, it immediately becomes subject to the simulated laws of physics defined in your world's SDF file.

  • Gravity: The robot will be pulled downwards. If its feet aren't on a surface, it will fall. If it's a bipedal humanoid, it will likely fall over unless a balancing controller is active.
  • Collisions: The links of the robot are defined with collision meshes. When these meshes intersect with the meshes of other objects (or the robot's own links), Gazebo's physics engine calculates the resulting forces and impulses. Your robot won't pass through walls; it will collide with them.
  • Friction: The contact points between surfaces have friction coefficients. This is what allows your robot's feet to grip the floor. Without friction, the feet would slip, and walking would be impossible. You can tune these properties (in your SDF/URDF) to simulate different surfaces, like ice, rubber, or asphalt.

By manipulating these physical properties, you can create realistic and challenging test environments for your humanoid's control algorithms, all before touching a single piece of real hardware.