Drake Simulation
This page illustrates how the Drake Simulation works. We will introduce 3 components that drake uses. They are Simulator, SceneGraph, and Diagram.
Diagram
To explain what a diagram is, 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.
diagram is the main graph of Drake. diagram is composed of systems like MultibodyPlant, controllers and other useful blocks. Like Simulink, the diagram determines how the system is constructed, what each block is, and how they are connected. Drake has aDiagramBuilder class to help glue the system blocks together. It adds system blocks into the diagram and 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 MultibodyPlant. The MultibodyPlant is a huge class containing all the parameters and data related to the robots.
SceneGraph
SceneGraph is the visualization and collision checking tool.
Collision Checking
Before simulation, SceneGraph is initiated and connected to MultibodyPlant.
During simulation, SceneGraph would give the information of whether two objects collide and what is the distance between two objects, given the state input from MultibodyPlant. Then the MultibodyPlant decides whether the collision is a soft contact or a fierce crash, how much force is generated in between objects given the collision information.
Visualization
To visualize the robot, MultibodyPlant should be registered to the SceneGraph. The SceneGraph would then send rendering message to another process called drake_visualizer using LCM.
drake_visualizer would handle the rendering job. It would draw the robot, frames, arrows per request.
Simulator
The Simulator takes the whole system diagram and runs the simulation. Using the robot dynamics equation of motion and environment forces, the Simulator computes 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.
Steps: from URDF to a moving robot
Import URDF or SDF file to create the robot
MultibodyPlantindiagram.Connect the
MultibodyPlantinput with torque input block, which could be controller block or signal source block.Register the robot into
SceneGraphfor visualization, usebuilderto connect theSceneGraphandMultibodyPlantfor collision checking.Create
Simulatorto simulate thediagram.Compile and run. Open
drake_visualizerto see the result.
A complete example of this process could be found below.
PID control of double pendulumLast updated
Was this helpful?