Here is a simple example of the Python API that showcases a subset of the wrapped functions and how to access them from python:
import numpy as np
import rbdl
model = rbdl.Model()
joint_rot_y = rbdl.Joint.fromJointType ("JointTypeRevoluteY")
body = rbdl.Body.fromMassComInertia (
1.,
np.array([0., 0.5, 0.]),
np.eye(3) * 0.05)
xtrans= rbdl.SpatialTransform()
xtrans.r = np.array([0., 1., 0.])
print (joint_rot_y)
print (model)
print (body)
print (body.mInertia)
print (xtrans)
body_1 = model.AppendBody (rbdl.SpatialTransform(), joint_rot_y, body)
body_2 = model.AppendBody (xtrans, joint_rot_y, body)
body_3 = model.AppendBody (xtrans, joint_rot_y, body)
q = np.zeros (model.q_size)
qdot = np.zeros (model.qdot_size)
qddot = np.zeros (model.qdot_size)
tau = np.zeros (model.qdot_size)
q[0] = 1.3
q[1] = -0.5
q[2] = 3.2
point_local = np.array([1., 2., 3.])
point_base = rbdl.CalcBodyToBaseCoordinates (model, q, body_3, point_local)
point_local_2 = rbdl.CalcBaseToBodyCoordinates (model, q, body_3, point_base)
rbdl.ForwardDynamics (model, q, qdot, tau, qddot)
print ("qddot = " + str(qddot.transpose()))
G = np.zeros([3,model.qdot_size])
rbdl.CalcPointJacobian (model, q, body_3, point_local, G)
print ("G = \n" + str(G))
To build the wrapper one needs both Cython and the development libraries for NumPy installed on the system. If this is the case you can build the wrapper by enabling the CMake option RBDL_BUILD_PYTHON_WRAPPER when configuring RBDL. You can find the wrapper in the subdirectory python/
of your build directory. By running the python interpreter in this directory you can load it within the python shell using
Python 2.7.11+ (default, Apr 17 2016, 14:00:29)
[GCC 5.3.1 20160413] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import rbdl
To install the wrapper you can use the python/setup.py
script:
This installs the RBDL python module globally and allows you to import it from any python script.