28#ifndef RBDL_USE_CASADI_MATH
29EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(RigidBodyDynamics::Joint)
123struct RBDL_DLLAPI Model {
129 std::vector<unsigned int> lambda;
132 std::vector<unsigned int> lambda_q;
134 std::vector<std::vector<unsigned int> >mu;
141 unsigned int dof_count;
158 unsigned int qdot_size;
161 unsigned int previously_added_body_id;
168 std::vector<Math::SpatialVector> v;
170 std::vector<Math::SpatialVector> a;
177 std::vector<Joint> mJoints;
179 std::vector<Math::SpatialVector> S;
182 std::vector<Math::SpatialVector> v_J;
183 std::vector<Math::SpatialVector> c_J;
185 std::vector<unsigned int> mJointUpdateOrder;
189 std::vector<Math::SpatialTransform> X_T;
192 std::vector<unsigned int> mFixedJointCount;
197 std::vector<Math::Matrix63> multdof3_S;
198 std::vector<Math::Matrix63> multdof3_U;
199 std::vector<Math::Matrix3d> multdof3_Dinv;
200 std::vector<Math::Vector3d> multdof3_u;
201 std::vector<unsigned int> multdof3_w_index;
203 std::vector<CustomJoint*> mCustomJoints;
209 std::vector<Math::SpatialVector> c;
211 std::vector<Math::SpatialMatrix> IA;
213 std::vector<Math::SpatialVector> pA;
215 std::vector<Math::SpatialVector> U;
221 std::vector<Math::SpatialVector> f;
224 std::vector<Math::SpatialRigidBodyInertia> I;
225 std::vector<Math::SpatialRigidBodyInertia> Ic;
226 std::vector<Math::SpatialVector> hc;
227 std::vector<Math::SpatialVector> hdotc;
237 std::vector<Math::SpatialTransform> X_lambda;
239 std::vector<Math::SpatialTransform> X_base;
242 std::vector<FixedBody> mFixedBodies;
255 unsigned int fixed_body_discriminator;
264 std::vector<Body> mBodies;
267 std::map<std::string, unsigned int> mBodyNameMap;
299 unsigned int AddBody (
300 const unsigned int parent_id,
301 const Math::SpatialTransform &joint_frame,
304 std::string body_name =
""
307 unsigned int AddBodySphericalJoint (
308 const unsigned int parent_id,
309 const Math::SpatialTransform &joint_frame,
312 std::string body_name =
""
321 unsigned int AppendBody (
322 const Math::SpatialTransform &joint_frame,
325 std::string body_name =
""
328 unsigned int AddBodyCustomJoint (
329 const unsigned int parent_id,
330 const Math::SpatialTransform &joint_frame,
331 CustomJoint *custom_joint,
333 std::string body_name =
""
347 unsigned int GetBodyId (
const char *body_name)
const
349 if (mBodyNameMap.count(body_name) == 0) {
350 return std::numeric_limits<unsigned int>::max();
353 return mBodyNameMap.find(body_name)->second;
357 std::string GetBodyName (
unsigned int body_id)
const
359 std::map<std::string, unsigned int>::const_iterator iter
360 = mBodyNameMap.begin();
362 while (iter != mBodyNameMap.end()) {
363 if (iter->second == body_id) {
375 bool IsFixedBodyId (
unsigned int body_id)
377 if (body_id >= fixed_body_discriminator
378 && body_id < std::numeric_limits<unsigned int>::max()
379 && body_id - fixed_body_discriminator < mFixedBodies.size()) {
385 bool IsBodyId (
unsigned int id)
387 if (
id > 0 &&
id < mBodies.size()) {
390 if (
id >= fixed_body_discriminator
391 &&
id < std::numeric_limits<unsigned int>::max()) {
392 if (
id - fixed_body_discriminator < mFixedBodies.size()) {
406 unsigned int GetParentBodyId (
unsigned int id)
408 if (
id >= fixed_body_discriminator) {
409 return mFixedBodies[
id - fixed_body_discriminator].mMovableParent;
412 unsigned int parent_id = lambda[id];
414 while (mBodies[parent_id].mIsVirtual) {
415 parent_id = lambda[parent_id];
424 Math::SpatialTransform GetJointFrame (
unsigned int id)
426 if (
id >= fixed_body_discriminator) {
427 return mFixedBodies[
id - fixed_body_discriminator].mParentTransform;
430 unsigned int child_id = id;
431 unsigned int parent_id = lambda[id];
432 if (mBodies[parent_id].mIsVirtual) {
433 while (mBodies[parent_id].mIsVirtual) {
434 child_id = parent_id;
435 parent_id = lambda[child_id];
437 return X_T[child_id];
446 void SetJointFrame (
unsigned int id,
447 const Math::SpatialTransform &transform)
449 if (
id >= fixed_body_discriminator) {
450 throw Errors::RBDLError(
"Error: setting of parent transform not supported for fixed bodies!");
453 unsigned int child_id = id;
454 unsigned int parent_id = lambda[id];
455 if (mBodies[parent_id].mIsVirtual) {
456 while (mBodies[parent_id].mIsVirtual) {
457 child_id = parent_id;
458 parent_id = lambda[child_id];
460 X_T[child_id] = transform;
471 Math::Quaternion GetQuaternion (
unsigned int i,
474 assert (mJoints[i].mJointType == JointTypeSpherical);
475 unsigned int q_index = mJoints[i].q_index;
476 return Math::Quaternion ( Q[q_index],
479 Q[multdof3_w_index[i]]);
487 void SetQuaternion (
unsigned int i,
488 const Math::Quaternion &quat,
491 assert (mJoints[i].mJointType == JointTypeSpherical);
492 unsigned int q_index = mJoints[i].q_index;
494 Q[q_index] = quat[0];
495 Q[q_index + 1] = quat[1];
496 Q[q_index + 2] = quat[2];
497 Q[multdof3_w_index[i]] = quat[3];
Describes all properties of a single body.
Keeps the information of a body and how it is attached to another body.