This page illustrates how the Drake Simulation works. We will introduce 3 components that drake uses. They are Simulator, SceneGraph, and Diagram.
To explain what a
diagramis, we could look at how Matlab Simulink works. Matlab Simulink is a simulation tool. Simulink's main graph is composed of connected systems. A complex system can host multiple subsystems. All these subsystems connect in some way to form the entire system.
diagramis the main graph of Drake.
diagramis composed of systems like
MultibodyPlant, controllers and other useful blocks. Like Simulink, the
diagramdetermines how the system is constructed, what each block is, and how they are connected. Drake has a
DiagramBuilderclass to help glue the system blocks together. It adds system blocks into the
diagramand connects input and output ports of blocks together.
Thinking: what are the information and data format that's being transmitted between the ports?
For a robotic system, there is a special system block that represents all the robots in
diagram. This system is called
MultibodyPlantis a huge class containing all the parameters and data related to the robots.
SceneGraphis the visualization and collision checking tool.
SceneGraphis initiated and connected to
SceneGraphwould give the information of whether two objects collide and what is the distance between two objects, given the state input from
MultibodyPlant. Then the
MultibodyPlantdecides whether the collision is a soft contact or a fierce crash, how much force is generated in between objects given the collision information.
To visualize the robot,
MultibodyPlantshould be registered to the
SceneGraphwould then send rendering message to another process called
drake_visualizerwould handle the rendering job. It would draw the robot, frames, arrows per request.
Simulatortakes the whole system
diagramand runs the simulation. Using the robot dynamics equation of motion and environment forces, the
Simulatorcomputes the state change. It then runs numerical integration for continuous system or state update for discrete system, to calculate the next system state, and write the states back to the diagram's corresponding
context. It keeps updating the states until the simulation finishes.
- 1.Import URDF or SDF file to create the robot
- 2.Connect the
MultibodyPlantinput with torque input block, which could be controller block or signal source block.
- 3.Register the robot into
SceneGraphfor visualization, use
builderto connect the
MultibodyPlantfor collision checking.
Simulatorto simulate the
- 5.Compile and run. Open
drake_visualizerto see the result.
A complete example of this process could be found below.