- 3.0.2 Documentation
|
In this tutorial, we will create a simple Rigid Body Dynamics system.
The Rigid Body Dynamics module of the Control Toolbox relies on RobCoGen, a code-generation framework for Rigid Body Dynamics and Kinematics. This involves a separate code generation step for creating the dynamics and kinematics equations prior to using your model in the Control Toolbox. However, as of writing this documentation, RobCoGen is the only Rigid Body Dynamics framework that supports Auto-Differentiation, a major ingredient for fast Optimal Control. We plan to support more modelling frameworks in the future.
RobCoGen requires a special robot description format (kindsl). If you already have a URDF description of your robot, you can use the urdf2robcogen converter.
As a first step, download RobCoGen version 0.4ad.0 from the official website. Follow the instruction on the website for creating your kindsl and dtdsl files. Generate all C++ outputs.
As a next step, we suggest to first create a new package
As you can see, we made our package depend on ct_rbd. Next, we create the folder structure
Copy all files generated by RobCoGen into this folder. We generally recommend adding your kindsl/dtdsl files to a subfolder called "model" as well for later reference.
Next, edit the CMakeLists.txt in your package and add the following lines:
Next, create a header file for your robot in include/my_robot/MyRobot.h with the following content
You need to adjust a few variables. First, set the namespace (ROBCOGEN_NS) which the RobCoGen files have been created in. Also, you can define a target namespace (MyRobot). Next, you need to define your base link (CT_BASE, which is either floating or fixed, depending on your kindsl). Afterwards, define all links (CT_L0, CT_L1, CT_L2, ...) by using the frames you defined in RobCoGen. Last but not least, you can but do not have to specify endeffectors. Endeffectors can be useful for contacts or optimal control. If in doubt, skip these for now.
Once you need end-effectors, specify their number (CT_N_EE). Then, for each end-effector, specify its name in RobCoGen (CT_EEx) and which link it is rigidly attached to (CT_EEx_IS_ON_LINK). Then specify the first joint in the kinematic chain leading up to the end-effector (CT_EEx_FIRST_JOINT, often but not necessarily 0) as well as the last joint (CT_EEx_LAST_JOINT). The Control Toolbox assumes that all joint numbers in between those two also influence the end-effector.
Above steps automatically create the following useful types:
The Dynamics and Kinematics class have some useful functions including computing forward and inverse dynamics as well as transforms and Jacobians. Please refer to the documentation for more details.
That's it! You can verify your setup by looking into the ct models package, e.g. at the HyA robot. Feel free to check out our tutorials on how to Simulate your robot and create a controller as well as Useful RBD types.