Here is a simple example how one can create a meaningless model and compute the forward dynamics for it:
#include <iostream>
int main (int argc, char* argv[]) {
Model* model = NULL;
unsigned int body_a_id, body_b_id, body_c_id;
Body body_a, body_b, body_c;
Joint joint_a, joint_b, joint_c;
model = new Model();
model->gravity =
Vector3d (0., -9.81, 0.);
joint_a = Joint(
JointTypeRevolute,
);
body_a_id = model->AddBody(0,
Xtrans(
Vector3d(0., 0., 0.)), joint_a, body_a);
joint_b = Joint (
JointTypeRevolute,
);
body_b_id = model->AddBody(body_a_id,
Xtrans(
Vector3d(1., 0., 0.)), joint_b, body_b);
joint_c = Joint (
JointTypeRevolute,
);
body_c_id = model->AddBody(body_b_id,
Xtrans(
Vector3d(0., 1., 0.)), joint_c, body_c);
VectorNd Q = VectorNd::Zero (model->q_size);
VectorNd QDot = VectorNd::Zero (model->qdot_size);
VectorNd Tau = VectorNd::Zero (model->qdot_size);
VectorNd QDDot = VectorNd::Zero (model->qdot_size);
std::cout << QDDot.transpose() << std::endl;
delete model;
return 0;
}
RBDL_DLLAPI void ForwardDynamics(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &Tau, Math::VectorNd &QDDot, std::vector< Math::SpatialVector > *f_ext=NULL)
Computes forward dynamics with the Articulated Body Algorithm.
Math types such as vectors and matrices and utility functions.
SpatialTransform Xtrans(const Vector3d &r)
RBDL_DLLAPI void rbdl_check_api_version(int version)
If the library itself is already created, one can compile this example with CMake. In the example folder is a CMakeLists.txt file, that can be used to automatically create the makefiles by using CMake. It uses the script FindRBDL.cmake which can be used to find the library and include directory of the headers.
The FindRBDL.cmake script can use the environment variables RBDL_PATH, RBDL_INCLUDE_PATH, and RBDL_LIBRARY_PATH to find the required files.
To build it manually you have to specify the following compiler and linking switches:
g++ example.cc -I<path to build folder>/src -I<path to src folder> -lrbdl -L<path to librbdl.a> -o example