33 lambda_q.push_back(0);
34 mu.push_back(std::vector<unsigned int>());
38 previously_added_body_id = 0;
43 v.push_back(zero_spatial);
44 a.push_back(zero_spatial);
47 mJoints.push_back(root_joint);
48 S.push_back (zero_spatial);
51 v_J.push_back (zero_spatial);
52 c_J.push_back (zero_spatial);
55 multdof3_S.push_back (Matrix63::Zero());
56 multdof3_U.push_back (Matrix63::Zero());
57 multdof3_Dinv.push_back (Matrix3d::Zero());
58 multdof3_u.push_back (Vector3d::Zero());
59 multdof3_w_index.push_back (0);
62 c.push_back(zero_spatial);
63 IA.push_back(SpatialMatrix::Identity());
64 pA.push_back(zero_spatial);
65 U.push_back(zero_spatial);
67 u = VectorNd::Zero(1);
68 d = VectorNd::Zero(1);
70 f.push_back (zero_spatial);
76 hc.push_back (zero_spatial);
77 hdotc.push_back (zero_spatial);
83 mBodies.push_back(root_body);
84 mBodyNameMap[
"ROOT"] = 0;
86 fixed_body_discriminator = std::numeric_limits<unsigned int>::max() / 2;
91 const unsigned int parent_id,
95 std::string body_name)
97 FixedBody fbody = FixedBody::CreateFromBody (body);
101 if (model.IsFixedBodyId(parent_id)) {
103 model.mFixedBodies[parent_id - model.fixed_body_discriminator];
114 SpatialRigidBodyInertia::createFromMassComInertiaC (
119 model.mFixedBodies.push_back (fbody);
121 if (model.mFixedBodies.size() > std::numeric_limits<unsigned int>::max() -
122 model.fixed_body_discriminator) {
123 std::ostringstream errormsg;
124 errormsg <<
"Error: cannot add more than "
125 << std::numeric_limits<unsigned int>::max() - model.mFixedBodies.size()
126 <<
" fixed bodies. You need to modify "
127 <<
"Model::fixed_body_discriminator for this."
132 if (body_name.size() != 0) {
133 if (model.mBodyNameMap.find(body_name) != model.mBodyNameMap.end()) {
134 std::ostringstream errormsg;
135 errormsg <<
"Error: Body with name '"
137 <<
"' already exists!"
141 model.mBodyNameMap[body_name] = model.mFixedBodies.size()
142 + model.fixed_body_discriminator - 1;
145 return model.mFixedBodies.size() + model.fixed_body_discriminator - 1;
150 const unsigned int parent_id,
154 std::string body_name)
159 unsigned int joint_count = 0;
160 if (joint.mJointType == JointType1DoF) {
162 }
else if (joint.mJointType == JointType2DoF) {
164 }
else if (joint.mJointType == JointType3DoF) {
166 }
else if (joint.mJointType == JointType4DoF) {
168 }
else if (joint.mJointType == JointType5DoF) {
170 }
else if (joint.mJointType == JointType6DoF) {
172 }
else if (joint.mJointType == JointTypeFloatingBase)
176 std::ostringstream errormsg;
177 errormsg <<
"Error: Invalid joint type: "
186 unsigned int null_parent = parent_id;
189 if (joint.mJointType == JointTypeFloatingBase) {
190 null_parent = model.AddBody (parent_id,
192 JointTypeTranslationXYZ,
195 return model.AddBody (null_parent,
202 Joint single_dof_joint;
208 for (j = 0; j < joint_count; j++) {
209 single_dof_joint = Joint (joint.mJointAxes[j]);
211 if (single_dof_joint.mJointType == JointType1DoF) {
213 joint.mJointAxes[j][0],
214 joint.mJointAxes[j][1],
215 joint.mJointAxes[j][2]);
217 joint.mJointAxes[j][3],
218 joint.mJointAxes[j][4],
219 joint.mJointAxes[j][5]);
221#ifdef RBDL_USE_CASADI_MATH
222 if (rotation.is_zero()) {
224 if (rotation ==
Vector3d (0., 0., 0.)) {
226 single_dof_joint = Joint (JointTypePrismatic, translation);
228#ifdef RBDL_USE_CASADI_MATH
229 if (translation.is_zero()) {
231 else if (translation ==
Vector3d (0., 0., 0.)) {
233 single_dof_joint = Joint (JointTypeRevolute, rotation);
240 joint_frame_transform = joint_frame;
245 if (j == joint_count - 1)
251 null_parent = model.AddBody (null_parent,
252 joint_frame_transform,
258 return model.AddBody (null_parent,
259 joint_frame_transform,
265unsigned int Model::AddBody(
266 const unsigned int parent_id,
270 std::string body_name)
272 assert (lambda.size() > 0);
273 assert (joint.mJointType != JointTypeUndefined);
275 if (joint.mJointType == JointTypeFixed) {
283 return previously_added_body_id;
284 }
else if ( (joint.mJointType == JointTypeSpherical)
285 || (joint.mJointType == JointTypeEulerZYX)
286 || (joint.mJointType == JointTypeEulerXYZ)
287 || (joint.mJointType == JointTypeEulerYXZ)
288 || (joint.mJointType == JointTypeEulerZXY)
289 || (joint.mJointType == JointTypeTranslationXYZ)
290 || (joint.mJointType == JointTypeCustom)
293 }
else if (joint.mJointType != JointTypePrismatic
294 && joint.mJointType != JointTypeRevolute
295 && joint.mJointType != JointTypeRevoluteX
296 && joint.mJointType != JointTypeRevoluteY
297 && joint.mJointType != JointTypeRevoluteZ
298 && joint.mJointType != JointTypeHelical
306 return previously_added_body_id;
311 unsigned int movable_parent_id = parent_id;
314 if (IsFixedBodyId(parent_id)) {
315 unsigned int fbody_id = parent_id - fixed_body_discriminator;
316 movable_parent_id = mFixedBodies[fbody_id].mMovableParent;
317 movable_parent_transform = mFixedBodies[fbody_id].mParentTransform;
321 lambda.push_back(movable_parent_id);
322 unsigned int lambda_q_last = mJoints[mJoints.size() - 1].q_index;
324 if (mJoints[mJoints.size() - 1].mDoFCount > 0
325 && mJoints[mJoints.size() - 1].mJointType != JointTypeCustom) {
326 lambda_q_last = lambda_q_last + mJoints[mJoints.size() - 1].mDoFCount;
327 }
else if (mJoints[mJoints.size() - 1].mJointType == JointTypeCustom) {
328 unsigned int custom_index = mJoints[mJoints.size() - 1].custom_joint_index;
329 lambda_q_last = lambda_q_last
330 + mCustomJoints[mCustomJoints.size() - 1]->mDoFCount;
333 for (
unsigned int i = 0; i < joint.mDoFCount; i++) {
334 lambda_q.push_back(lambda_q_last + i);
336 mu.push_back(std::vector<unsigned int>());
337 mu.at(movable_parent_id).push_back(mBodies.size());
342 mBodies.push_back(body);
344 if (body_name.size() != 0) {
345 if (mBodyNameMap.find(body_name) != mBodyNameMap.end()) {
346 std::ostringstream errormsg;
347 errormsg <<
"Error: Body with name '"
349 <<
"' already exists!"
353 mBodyNameMap[body_name] = mBodies.size() - 1;
361 unsigned int prev_joint_index = mJoints.size() - 1;
362 mJoints.push_back(joint);
364 if (mJoints[prev_joint_index].mJointType != JointTypeCustom) {
365 mJoints[mJoints.size() - 1].q_index =
366 mJoints[prev_joint_index].q_index + mJoints[prev_joint_index].mDoFCount;
368 mJoints[mJoints.size() - 1].q_index =
369 mJoints[prev_joint_index].q_index + mJoints[prev_joint_index].mDoFCount;
372 S.push_back (joint.mJointAxes[0]);
375 v_J.push_back (joint.mJointAxes[0]);
379 multdof3_S.push_back (Matrix63::Zero());
380 multdof3_U.push_back (Matrix63::Zero());
381 multdof3_Dinv.push_back (Matrix3d::Zero());
382 multdof3_u.push_back (Vector3d::Zero());
383 multdof3_w_index.push_back (0);
385 dof_count = dof_count + joint.mDoFCount;
389 int multdof3_joint_counter = 0;
390 int mCustomJoint_joint_counter = 0;
391 for (
unsigned int i = 1; i < mJoints.size(); i++) {
392 if (mJoints[i].mJointType == JointTypeSpherical) {
393 multdof3_w_index[i] = dof_count + multdof3_joint_counter;
394 multdof3_joint_counter++;
399 + multdof3_joint_counter;
401 qdot_size = qdot_size + joint.mDoFCount;
405 X_T.push_back(joint_frame * movable_parent_transform);
409 IA.push_back(SpatialMatrix::Zero());
413 d = VectorNd::Zero (mBodies.size());
414 u = VectorNd::Zero (mBodies.size());
419 SpatialRigidBodyInertia::createFromMassComInertiaC (body.
mMass,
428 if (mBodies.size() == fixed_body_discriminator) {
429 std::ostringstream errormsg;
430 errormsg <<
"Error: cannot add more than "
431 << fixed_body_discriminator
432 <<
" movable bodies. You need to modify Model::fixed_body_discriminator for this."
437 previously_added_body_id = mBodies.size() - 1;
439 mJointUpdateOrder.clear();
442 std::vector<std::pair<JointType, unsigned int> > joint_types;
443 for (
unsigned int i = 0; i < mJoints.size(); i++) {
444 joint_types.push_back(
445 std::pair<JointType, unsigned int> (mJoints[i].mJointType,i));
446 mJointUpdateOrder.push_back (mJoints[i].mJointType);
449 mJointUpdateOrder.clear();
450 JointType current_joint_type = JointTypeUndefined;
451 while (joint_types.size() != 0) {
452 current_joint_type = joint_types[0].first;
454 std::vector<std::pair<JointType, unsigned int> >::iterator type_iter =
457 while (type_iter != joint_types.end()) {
458 if (type_iter->first == current_joint_type) {
459 mJointUpdateOrder.push_back (type_iter->second);
460 type_iter = joint_types.erase (type_iter);
472 return previously_added_body_id;
475unsigned int Model::AppendBody (
479 std::string body_name)
481 return Model::AddBody (previously_added_body_id,
488unsigned int Model::AddBodyCustomJoint (
489 const unsigned int parent_id,
491 CustomJoint *custom_joint,
493 std::string body_name)
495 Joint proxy_joint (JointTypeCustom, custom_joint->mDoFCount);
496 proxy_joint.custom_joint_index = mCustomJoints.size();
500 mCustomJoints.push_back (custom_joint);
502 unsigned int body_id = AddBody (parent_id,
unsigned int AddBodyMultiDofJoint(Model &model, const unsigned int parent_id, const SpatialTransform &joint_frame, const Joint &joint, const Body &body, std::string body_name)
unsigned int AddBodyFixedJoint(Model &model, const unsigned int parent_id, const SpatialTransform &joint_frame, const Joint &joint, const Body &body, std::string body_name)
Base class for all RBDL exceptions.
Math types such as vectors and matrices and utility functions.
SpatialVector_t SpatialVector
Describes all properties of a single body.
Math::Matrix3d mInertia
Inertia matrix at the center of mass.
void Join(const Math::SpatialTransform &transform, const Body &other_body)
Joins inertial parameters of two bodies to create a composite body.
Math::Vector3d mCenterOfMass
The position of the center of mass in body coordinates.
Math::Scalar mMass
The mass of the body.
Keeps the information of a body and how it is attached to another body.
unsigned int mMovableParent
Id of the movable body that this fixed body is attached to.
Math::SpatialTransform mParentTransform
Transforms spatial quantities expressed for the parent to the.
Compact representation for Spatial Inertia.
Compact representation of spatial transformations.