22 Model::Model(
unsigned int* n_threads) : work(new boost::asio::io_service::work(io_service))
36 mu.push_back(std::vector<unsigned int>());
42 std::vector<unsigned int> id_chain;
43 id_chain.push_back(0);
52 v.push_back(rootBodySpatialVelocity);
53 a.push_back(rootBodySpatialAcceleration);
79 u = VectorNd::Zero(1);
80 d = VectorNd::Zero(1);
100 unsigned int num_threads = n_threads ==
nullptr ? std::thread::hardware_concurrency() : *n_threads;
101 for(
unsigned int i = 0; i < num_threads; ++i)
108 std::string body_name)
138 std::string msg =
"Error: cannot add more than " + std::to_string(std::numeric_limits<unsigned int>::max() - model.
mFixedBodies.size()) +
139 " fixed bodies. You need to modify Model::fixed_body_discriminator for this.";
147 if (body_name.size() != 0)
151 std::string msg =
"Error: Fixed body with name '" + body_name +
"' already exists!";
162 std::string body_name)
167 unsigned int joint_count = 0;
198 std::cerr <<
"Error: Invalid joint type: " << joint.
mJointType << std::endl;
200 assert(0 && !
"Invalid joint type!");
206 unsigned int null_parent = parent_id;
216 Joint single_dof_joint;
222 for (j = 0; j < joint_count; j++)
230 if (rotation ==
Vector3d(0., 0., 0.))
234 else if (translation ==
Vector3d(0., 0., 0.))
240 std::cerr <<
"Invalid joint axis: " << joint.
mJointAxes[0].transpose() <<
". Helical joints not (yet) supported." << std::endl;
249 joint_frame_transform = joint_frame;
256 if (j == joint_count - 1)
264 null_parent = model.
addBody(null_parent, joint_frame_transform, single_dof_joint, null_body);
268 return model.
addBody(null_parent, joint_frame_transform, single_dof_joint, body, body_name);
273 assert(
lambda.size() > 0);
296 unsigned int movable_parent_id = parent_id;
302 movable_parent_id =
mFixedBodies.at(fbody_id).mMovableParent;
303 movable_parent_transform =
mFixedBodies.at(fbody_id).mParentTransform;
307 lambda.push_back(movable_parent_id);
308 unsigned int lambda_q_last =
mJoints.back().q_index;
312 lambda_q_last = lambda_q_last +
mJoints.back().mDoFCount;
316 lambda_q_last = lambda_q_last +
mCustomJoints.back()->mDoFCount;
319 for (
unsigned int i = 0; i < joint.
mDoFCount; i++)
321 lambda_q.push_back(lambda_q_last + i);
323 mu.push_back(std::vector<unsigned int>());
324 mu.at(movable_parent_id).push_back(
mBodies.size());
327 for(
unsigned int i = 0; i <
mu.size(); ++i)
329 if(
mu[i].size() == 0)
340 if (!movable_parent_id)
348 parentBodyFrame =
bodyFrames.at(movable_parent_id);
349 bodyFrame.reset(
new ReferenceFrame(body_name, parentBodyFrame, joint_frame * movable_parent_transform,
true,
mBodies.size()));
359 if (!body_name.empty())
363 std::string msg =
"Error: Body with name '" + body_name +
"' already exists!";
375 unsigned int prev_joint_index =
mJoints.size() - 1;
378 mJoints.back().q_index =
mJoints.at(prev_joint_index).q_index +
mJoints.at(prev_joint_index).mDoFCount;
406 int multdof3_joint_counter = 0;
407 for (
unsigned int i = 1; i <
mJoints.size(); i++)
412 multdof3_joint_counter++;
427 X_T.push_back(joint_frame * movable_parent_transform);
431 IA.push_back(SpatialMatrix::Zero(6, 6));
448 std::cerr <<
"\033[1;31m Body " << body_name <<
" failed inertia validation\033[0m" << std::endl;
454 I.push_back(bodyInertia);
455 Ib_c.push_back(bodyCenteredInertia);
456 Ic.push_back(bodyInertia);
463 <<
" movable bodies. You need to modify " 464 "Model::fixed_body_discriminator for this." 475 std::vector<std::pair<JointType, unsigned int>> joint_types;
476 for (
unsigned int i = 0; i <
mJoints.size(); i++)
478 joint_types.push_back(std::pair<JointType, unsigned int>(
mJoints[i].mJointType, i));
484 while (joint_types.size() != 0)
486 current_joint_type = joint_types[0].first;
488 std::vector<std::pair<JointType, unsigned int>>::iterator type_iter = joint_types.begin();
490 while (type_iter != joint_types.end())
492 if (type_iter->first == current_joint_type)
495 type_iter = joint_types.erase(type_iter);
504 std::vector<unsigned int> parent_chain(
lambda_chain.at(movable_parent_id).size() + 1);
505 for (
unsigned int idx = 0; idx <
lambda_chain.at(movable_parent_id).size(); idx++)
507 parent_chain[idx] =
lambda_chain.at(movable_parent_id).at(idx);
523 std::string body_name)
534 unsigned int body_id =
addBody(parent_id, joint_frame, proxy_joint, body, body_name);
543 if(Q && !QDot && !QDDot)
547 else if(Q && QDot && !QDDot)
549 jcalc(*
this, b_id, *Q, *QDot);
552 unsigned int lambda_id =
lambda[b_id];
556 v[b_id].set(
v[lambda_id].transform_copy(bodyFrame->getTransformFromParent()) +
v_J[b_id]);
557 c[b_id] =
c_J[b_id] +
v[b_id] %
v_J[b_id];
561 v[b_id].set(
v_J[b_id]);
562 c[b_id] =
c_J[b_id] +
v[b_id] %
v_J[b_id];
565 else if(Q && QDot && QDDot)
567 jcalc(*
this, b_id, *Q, *QDot);
570 unsigned int lambda_id =
lambda[b_id];
574 v[b_id].set(
v[lambda_id].transform_copy(bodyFrame->getTransformFromParent()) +
v_J[b_id]);
575 c[b_id] =
c_J[b_id] +
v[b_id] %
v_J[b_id];
579 v[b_id].set(
v_J[b_id]);
580 c[b_id] =
c_J[b_id] +
v[b_id] %
v_J[b_id];
583 unsigned int q_index =
mJoints[b_id].q_index;
587 a[b_id].set(
a[lambda_id].transform_copy(bodyFrame->getTransformFromParent()) +
c[b_id]);
591 a[b_id].set(
c[b_id]);
596 if(
mJoints[b_id].mDoFCount == 1)
598 a[b_id].set(
a[b_id] +
S[b_id] * (*QDDot)[q_index]);
600 else if(
mJoints[b_id].mDoFCount == 3)
602 Vector3d omegadot_temp((*QDDot)[q_index], (*QDDot)[q_index + 1], (*QDDot)[q_index + 2]);
603 a[b_id].set(
a[b_id] +
multdof3_S[b_id] * omegadot_temp);
608 unsigned int custom_index =
mJoints[b_id].custom_joint_index;
610 unsigned int joint_dof_count = custom_joint->
mDoFCount;
612 a[b_id].set(
a[b_id] + (
mCustomJoints[custom_index]->
S * (QDDot->block(q_index, 0, joint_dof_count, 1))));
617 if(
mu[b_id].size() > 1)
619 unsigned int mu_size =
mu[b_id].size();
620 for(
unsigned int i = 0; i < mu_size - 1; ++i)
631 else if(
mu[b_id].size() == 1)
std::vector< unsigned int > lambda_q
std::vector< Math::SpatialMatrix > IA
The spatial inertia of the bodies.
std::vector< unsigned int > mJointUpdateOrder
bool IsFixedBodyId(unsigned int body_id) const
Checks whether the body is rigidly attached to another body.
std::vector< Joint > mJoints
All joints.
3 DoF joint that uses Euler ZYX convention (faster than emulated
SpatialVector SpatialVectorZero
Describes all properties of a single body.
Math::VectorNd u
Temporary variable u (RBDA p. 130)
std::vector< Math::SpatialVector > c_J
User defined joints of varying size.
std::vector< unsigned int > multdof3_w_index
boost::thread_group thread_pool
std::vector< Math::Matrix63 > multdof3_U
CustomJoint is a struct used to create a joint with user defined parameters. This is accomplished by ...
std::vector< FixedBody > mFixedBodies
All bodies that are attached to a body via a fixed joint.
std::vector< unsigned int > lambda
unsigned int num_branch_ends
Keeps the information of a body and how it is attached to another body.
Math::SpatialInertiaV Ib_c
SpatialTransform Xtrans(const Vector3d &r)
Get pure translation transform.
Fixed joint which causes the inertial properties to be merged with.
void join(const Math::SpatialTransform &transform, const Body &other_body)
Joins inertial parameters of two bodies to create a composite body.
void jcalc(Model &model, unsigned int joint_id, const Math::VectorNd &q, const Math::VectorNd &qdot)
Computes all variables for a joint model and updates the body frame as well as the body's center of m...
std::vector< boost::thread * > threads
static ReferenceFramePtr getWorldFrame()
Get a pointer to the world frame.
double mMass
The mass of the body.
Math::MotionVector gravity
the cartesian vector of the gravity
Math::Matrix3d mInertia
Inertia matrix at the center of mass.
unsigned int appendBody(const Math::SpatialTransform &joint_frame, const Joint &joint, const Body &body, std::string body_name="")
Adds a Body to the model such that the previously added Body is the Parent.
std::vector< std::vector< unsigned int > > mu
std::vector< ReferenceFramePtr > bodyFrames
unsigned int addBodyCustomJoint(const unsigned int parent_id, const Math::SpatialTransform &joint_frame, CustomJoint *custom_joint, const Body &body, std::string body_name="")
Math::VectorNd nbodies0_vec
ReferenceFramePtr worldFrame
std::map< std::string, unsigned int > mBodyNameMap
Human readable names for the bodies.
unsigned int addBody(const unsigned int parent_id, const Math::SpatialTransform &joint_frame, const Joint &joint, const Body &body, std::string body_name="")
Connects a given body to the model.
double mMass
The mass of the body.
std::vector< Math::SpatialTransform > X_lambda
Transformation from the parent body to the current body .
std::shared_ptr< ReferenceFrame > ReferenceFramePtr
boost::asio::io_service io_service
unsigned int q_size
The size of the -vector. For models without spherical joints the value is the same as Model::dof_coun...
std::vector< Math::Momentum > hc
Momentum is mass/inertia multiplied by velocity.
This class stores a bodies mass, center of mass, and inertia information. The inertia elements are st...
Math::SpatialForceV pA
The spatial bias force.
std::vector< Math::Matrix63 > multdof3_S_o
std::vector< Body > mBodies
All bodies 0 ... N_B, including the base.
A SpatialMotion vector is a MotionVector with a RobotDynamics::ReferenceFrame it is expressed in...
unsigned int custom_joint_index
Describes a joint relative to the predecessor body.
3 DoF joint that uses Euler XYZ convention (faster than emulated
ReferenceFrame object used to tell what frame objects are expressed in. Every ReferenceFrame has a po...
Math::VectorNd d
Temporary variable D_i (RBDA p. 130)
void crawlChainKinematics(unsigned int b_id, std::atomic< unsigned int > *branch_ends, const Math::VectorNd *Q, const Math::VectorNd *QDot, const Math::VectorNd *QDDot)
A Math::SpatialInertia is a RigidBodyInertia explicitly expressed in a RobotDynamics::ReferenceFrame...
unsigned int addBodyMultiDofJoint(Model &model, const unsigned int parent_id, const SpatialTransform &joint_frame, const Joint &joint, const Body &body, std::string body_name)
Math::SpatialAccelerationV a
The spatial velocity of the bodies.
std::vector< CustomJoint * > mCustomJoints
JointType
General types of joints.
std::map< std::string, ReferenceFramePtr > referenceFrameMap
std::vector< Math::Matrix3d > multdof3_Dinv
std::vector< ReferenceFramePtr > bodyCenteredFrames
unsigned int mDoFCount
Number of degrees of freedom of the joint. Note: CustomJoints.
Math::SpatialVector * mJointAxes
The spatial axes of the joint.
Model(unsigned int *n_threads=nullptr)
Constructor.
Contains all information about the rigid body model.
A 6-DoF joint for floating-base (or freeflyer) systems.
Math types such as vectors and matrices and utility functions.
std::vector< Math::SpatialVector > U
Temporary variable U_i (RBDA p. 130)
std::vector< Math::SpatialVector > c
The velocity dependent spatial acceleration.
unsigned int fixed_body_discriminator
Value that is used to discriminate between fixed and movable bodies.
SpatialMatrix SpatialMatrixIdentity
Math::Vector3d mCenterOfMass
The position of the center of mass in body coordinates.
Math::RigidBodyInertiaV Ic
SpatialAcceleration. For clarity, the ReferenceFrames are stated as follows. A spatial acceleration i...
A SpatialForce is a spatial vector with the angular part being three moments and the linear part bein...
bool validateRigidBodyInertia(const Body &body)
Math::MatrixNd three_x_qd0
std::vector< std::vector< unsigned int > > lambda_chain
std::vector< Math::Matrix63 > multdof3_S
Motion subspace for joints with 3 degrees of freedom.
std::vector< ReferenceFramePtr > fixedBodyFrames
3 DoF joint using Quaternions for joint positional variables and
unsigned int mMovableParent
Id of the movable body that this fixed body is attached to.
std::vector< Math::SpatialTransform > X_J
unsigned int addBodyFixedJoint(Model &model, const unsigned int parent_id, const SpatialTransform &joint_frame, const Joint &joint, const Body &body, std::string body_name)
std::vector< Math::Vector3d > multdof3_u
Math::SpatialTransform mParentTransform
Transforms spatial quantities expressed for the parent to the.
JointType mJointType
Type of joint.
Math::SpatialForceV f
Internal forces on the body (used only InverseDynamics())
unsigned int dof_count
number of degrees of freedoms of the model
Namespace for all structures of the RobotDynamics library.
ReferenceFramePtr comFrame
std::vector< Math::SpatialTransform > X_T
Transformations from the parent body to the frame of the joint.
unsigned int previously_added_body_id
Id of the previously added body, required for Model::appendBody()
unsigned int qdot_size
The size of the.
static FixedBody CreateFromBody(const Body &body)
static RigidBodyInertia createFromMassComInertiaC(double mass, const Vector3d &com, const Matrix3d &inertia_C)
3 DoF joint that uses Euler YXZ convention (faster than emulated