Multibody is the highlight of Drake. It represents a robot in a tree of bodies.
MultibodyPlantexposes APIs that compute robot mathematics including the kinematics, the dynamics, jacobian, etc.
To create a Multibody robot, the best way is to parse robot description file such as URDF or SDF. Drake could read URDF or SDF using a
parseruses tinyxml2 library to parse the XML file. It would iteratively parse each link, joint, transmission and generate a Multibody tree with the same structure described as in the XML file.
Be careful that Drake does not support mesh file for geometry collision yet. In other words, if you need to simulate collision, you would need to create your own collision model, usually some simple geometry that wraps around your mesh file. (I found it more convenient to add collision model using Rviz, because it has a check box allows you to show the collision geometry, way easier to visualize and compare between mesh and the simplified collision geometry.)
If you migrate your robot from ROS, your URDF is probably using package to find the mesh file rather than using relative path. Drake support "package" concept used in ROS. However, you need to change the folder with URDF files into a
package, which means you should provide a
package.xmlfile and modify the
BUILD.bazelfile to make
package. In addition, in your code, the
package.xmlfile path should be specified, so Drake could find the package as well. There is an example for that. (TODO: Add example here.)
One thing worth mentioning is that drake requires the model to have at least one
transmissionin the URDF, or it will fail to create input torque port for the plant. So if you do not have any
transmissiontag in the URDF, do create
SimpleTransmissionfor each actuated joint.
One more thing,
MultibodyPlanthas a unique body called
world_body. Every body created in Drake by default is a floating body, unless it is connected with some other bodies. Floating body is connected to the
world_bodywith a floating joint. So if your robot should be connected to the ground, you would create new joints to connect the body and world. The floating joint will be overwritten.
Mobilizerto connect two links, it is a different concept from the traditional
ModelInstanceIndexis the ID of robots. The root
diagramcould have only one
MultibodyPlant. So if you have more robots, they are grouped as
ModelInstanceIndexwithin the same
MultibodyPlant. Every element, like body, joint, etc, in the
ModelInstanceIndex0 is world. It has only one body, the world_body, with
ModelInstanceIndex1 includes bodies created by Drake API with no
For each robot loaded from SDF/URDF, Drake will create a unique
ModelInstanceIndexfor that robot.
After the URDF file is imported, the
MultibodyPlantis created. The plant is a class hosting a whole bunch of useful robotics function that we use to do motion planning and control.
Drake support compute all kinds of jacobian. To calculate the derivative with respect to something,
AutoDiffis used to ease the way of calculating.