Simulation
Overview
Computer simulations represent the physical world as a set of state variables and perform computations to advance this state forward (or backward) in time.
In robotics, simulation is used to perform robotic experiments without requiring robotic hardware. Instead, a mathematical model of the robot and its environment is used to approximate the behavior of a real robot.
Advantages of Simulation
- You control all variables and can replay identical scenarios
- You can inspect and set the full state of the system accurately
- You can easily change properties of the robot, sensors, and the environment
- The robot does not break or run out of battery power
Disadvantages of Simulation
- Behavior differs from the real world
- Only effects that are already modeled and known can be examined
- Even if an effect is modeled, numerical error can become an issue
- Simulated robots can't vacuum your floor
Choosing a simulator
Why is simulation needed?
The purpose of your simulation is a major factor in choosing a simulator:
Here are a few examples:
- Run ROS code without the robot present:
- The actual physics may not matter very much
- The speed of the simulation may not matter much
- The point is just to run code and see some movement
- ROS integration is very important
- Train machine learning models:
- Here trade-offs between speed and accuracy must be weighed
- What simulator is chosen depends on the method
- ROS integration may be un-important: the implementation of the algorithm (particularly the part that connects the policy to robot actions) may not need to be the same between simulation and the real robot
Identifying What Must Be Modeled
The needs of your robotic application dictate the complexity of your model and the requirements for your simulation engine. Choosing the correct level of simulated detail is an important design choice: the more detail, the more accuracy, but also the more computation time and complexity.
Here are some types of simulations used in robotics:
- Discrete Position
- Robots are agents that can move from grid-space to grid-space
- The mechanics of the movement are ignored
- Kinematic
- Control positions and velocities of the joints
- Dynamic
- Robots and objects have inertia and you control forces and torques
- Newton's Laws or Euler Lagrange can be used
- Complexity of the dynamic effects modeled can vary widely
- Finite Element
- Parts of the robot can deform according to stress-strain relations
- Fluid Dynamics
- For underwater or aerial robots
Differences Between Simulation Engines
- What integration scheme do they use?
- Most simulations ultimately hinge on integrating differential equations
- Many simulators provide a choice or parameters that can be tuned
- Accuracy vs speed trade-offs
- Specific types of differential equations may be better suited to different integration schemes
- What phenomenon can be modeled?
- Collisions?
- Friction?
- Lighting conditions?
- Aerodynamics?
- Visualization tools?
- Can you view the simulated objects?
- Can you generate plots based on the simulation?
- How do you provide input?
- How do you read the output?
- What robots are supported?
- Specific to certain types of robots?
- General purpose, can make nearly anything?
- Are their pre-built models available?
Custom Simulators
- Sometimes, you have a simple model for your robot
- Using a simple model, you can usually write your own simulator
- In some cases, writing your own can be simpler than invoking a complicated general purpose simulator like gazebo.
- Writing a simulation for a robot is a good way to verify you understand the system
Gazebo
- Gazebo (Formerly called Ignition Gazebo) is the latest simulator developed by Open Robotics
- This is the simulator with the best ROS 2 integration, because it is developed under the same umbrella organization as ROS
- It is a good simulator for testing ROS code: that is it is easy to use the same ROS nodes to control a real robot and a robot simulated in Gazebo.
- Notes on using Gazebo
Gazebo Features
- Choice of physics engines:
- By default it uses the Dart physics engine
- Graphics: Gazebo provides a graphical interface for viewing and creating
simulated worlds.
- Think of the Gazebo display as being a stand-in for the real world and the RViz display is a visualization based off of what the robot senses.
- Gazebo has powerful rendering features that are aimed at creating photo-realistic models so that computer vision in the simulator can be useful
- Plugin Architecture: Everything in Gazebo is written as a C++ plugin.
- This makes Gazebo extendable, and provides you with the ability to not only add new objects in Gazebo but also new physical phenomena
- Gazebo comes with many plugins, representing, for example, different types of sensors
- ROS support for Gazebo is provided by a plugin
- Network: Like ROS, gazebo consists of multiple processes that communicate with each other using. There are counterparts to ROS mesages and services,but these are entirely different systems
Other Simulators
Here is a list of other robotics simulators. You may encounter them, and some are quite popular, particularly for machine learning
Open Source Simulators
Current Simulators
- MuJoCo - A dynamics simulator specifically built for robotics tasks. This is likely one of the more state-of-the-art simulators.
- Purchased by DeepMind, which has made it open-source (formerly was very expensive and proprietary).
- Drake C++ Simulation tools for dynamic robots, using optimization techniques.
- Started at MIT, now backed by Toyota Research.
- High-fidelity simulation (particularly for contacts), at the expense of simulation speed.
- User has visibility into all algorithms and principles used in computation of the simulation
- Project Chrono - A multi-physics simulation.
- Does finite elements, granular material, real physics that takes a long time to compute.
- Only recommended if you have a specific need for high-fidelity physics
- Webbots - Robot simulator with a long history. Just released a new version in 2023
Less Maintained
- pybullet - A pythons simulator based on Bullet.
- Formerly popular in the reinforcement-learning community, still some residual use.
- Ever since MuJoCo became open-source, it's popularity has waned.
- trep - Developed in Todd Murphey's lab. Good numerical algorithms and transparency in how the dynamics are actually solved. Does not support contact/friction.
The Gazebo Classic (or the simulator formerly known as Gazebo) is the main simulator for ROS 1
- Like ROS, it is maintained by the Open Source Robotics Foundation, but it is a standalone program
- Many concepts in Gazebo are similar to ROS but slightly different
- We will focus on how to use Gazebo from ROS
- Carefully designed ROS programs can seamlessly switch between controlling
a Gazebo simulation and a real robot.
Closed Source Simulators
- CoppeliaSim (formerly V-Rep)
- Free for educational use, but not open source.
- Isaac Sim
- Popular due to its speed (for RL training) and good rendering (can learn from objects rendered in simulation and transfer to real world).
- Ubuntu 24.04 and ROS 2 Jazzy are not yet supported (as of 10/2024).
- Technically, Isaac Sim is Open-Source, but it is built on top of NVIDIA Omniverse, which is not