28 floating_base_ =
true;
61 explicit Model(
const std::string & urdf_filename)
74 const std::string & urdf_filename)
76 load(model_parameters, urdf_filename);
87 const std::string & urdf_filename)
89 model_parameters_ = model_parameters;
99 void load(
const std::string & urdf_filename)
103 bool rbdl_status = RigidBodyDynamics::Addons::URDFReadFromFile(
104 urdf_filename.c_str(),
108 if (
false == rbdl_status)
110 HUMOTO_THROW_MSG(std::string(
"Failed to load URDF model: ") + urdf_filename);
114 for (std::size_t i = 1; i < rbdl_model_.mBodies.size(); ++i)
116 total_mass_ += rbdl_model_.mBodies[i].mMass;
119 joint_data_.resize(rbdl_model_.mJoints.size());
128 void update(
const Eigen::VectorXd & joint_angles)
130 RigidBodyDynamics::UpdateKinematicsCustom(rbdl_model_, &joint_angles, NULL, NULL);
131 for (std::size_t i = 0; i < joint_data_.size(); ++i)
133 joint_data_[i].compute(rbdl_model_, i);
145 return(rbdl_model_.q_size);
160 boost::shared_ptr<TagLink> ptr(
new TagLink(getLinkId(link_string_id)));
174 const etools::Vector3 &position_local)
const 176 boost::shared_ptr<TagPoint> ptr(
new TagPoint( getLinkId(link_string_id),
191 LinkId id = getLinkId(link_string_id);
192 boost::shared_ptr<TagPoint> ptr(
new TagPoint(
id,
193 rbdl_model_.mBodies[
id].mCenterOfMass));
207 std::vector<LinkId> link_ids;
208 double total_mass = 0.0;
210 link_ids.resize(link_string_ids.size());
212 for (std::size_t i = 0; i < link_ids.size(); ++i)
214 link_ids[i] = getLinkId(link_string_ids[i]);
216 total_mass += rbdl_model_.mBodies[link_ids[i]].mMass;
219 boost::shared_ptr<TagPartialCoM> ptr(
new TagPartialCoM(link_ids, total_mass));
231 boost::shared_ptr<TagCoM> ptr(
new TagCoM());
246 etools::Vector3 com_position;
248 com_position.setZero(3);
250 for (std::size_t i = 0; i < tag->link_ids_.size(); ++i)
252 LinkId id = tag->link_ids_[i];
254 com_position.noalias() +=
255 rbdl_model_.mBodies[id].mMass
256 * getPointTagPosition(
id, rbdl_model_.mBodies[
id].mCenterOfMass);
264 com_position /= tag->mass_;
265 return (com_position);
278 return(getLinkTransform(tag->link_id_).r);
291 return(getPointTagPosition(tag->link_id_, tag->local_position_));
305 etools::Vector3 com_position;
307 com_position.setZero(3);
309 for (std::size_t i = 1; i < rbdl_model_.mBodies.size(); ++i)
311 com_position.noalias() +=
312 rbdl_model_.mBodies[i].mMass
313 * getPointTagPosition(i, rbdl_model_.mBodies[i].mCenterOfMass);
316 com_position /= total_mass_;
318 return (com_position);
333 return(getLinkTransform(tag->link_id_).E.transpose());
362 RigidBodyDynamics::Math::SpatialTransform mBaseTransform = getLinkTransform(tag->link_id_);
383 RigidBodyDynamics::Math::SpatialTransform mBaseTransform = getLinkTransform(tag->link_id_);
385 pose.
position_ = mBaseTransform.E.transpose() * tag->local_position_ + mBaseTransform.r;
403 return (total_mass_);
429 return (rbdl_model_.mBodies[tag->link_id_].mMass);
444 Eigen::MatrixXd jacobian_i;
447 for (std::size_t i = 0; i < tag->link_ids_.size(); ++i)
449 LinkId id = tag->link_ids_[i];
451 getTagJacobian<SpatialType::TRANSLATION>(jacobian_i, id, rbdl_model_.mBodies[id].mCenterOfMass);
455 jacobian.noalias() = jacobian_i * rbdl_model_.mBodies[id].mMass;
459 jacobian.noalias() += jacobian_i * rbdl_model_.mBodies[id].mMass;
463 jacobian /= tag->mass_;
475 template<SpatialType::Type t_jacobian_type>
479 getTagJacobian<t_jacobian_type>(jacobian, tag->link_id_, etools::Vector3::Zero());
491 template<SpatialType::Type t_jacobian_type>
495 getTagJacobian<t_jacobian_type>(jacobian, tag->link_id_, tag->local_position_);
509 Eigen::MatrixXd jacobian_i;
512 for (std::size_t i = 1; i < rbdl_model_.mBodies.size(); ++i)
514 getTagJacobian<SpatialType::TRANSLATION>(jacobian_i, i, rbdl_model_.mBodies[i].mCenterOfMass);
518 jacobian.noalias() = jacobian_i*rbdl_model_.mBodies[i].mMass;
522 jacobian.noalias() += jacobian_i*rbdl_model_.mBodies[i].mMass;
526 jacobian /= total_mass_;
531 #if defined(HUMOTO_BUILD_TESTS) || defined(HUMOTO_BUILD_REGRESSION_TESTS) 541 double getCoMRBDL(etools::Vector3 &com_position)
544 RigidBodyDynamics::Math::Vector3d com;
545 Eigen::VectorXd q, dq;
547 RigidBodyDynamics::Utils::CalcCenterOfMass(
569 void getCoMJacobianRBDL(Eigen::MatrixXd &jacobian)
572 Eigen::MatrixXd jacobian_i;
575 for (std::size_t i = 1; i < rbdl_model_.mBodies.size(); ++i)
577 jacobian_i.setZero(3, getDOFNumber());
578 RigidBodyDynamics::CalcPointJacobian (
582 rbdl_model_.mBodies[i].mCenterOfMass,
588 jacobian.noalias() = jacobian_i*rbdl_model_.mBodies[i].mMass;
592 jacobian.noalias() += jacobian_i*rbdl_model_.mBodies[i].mMass;
596 jacobian /= total_mass_;
609 void getCoMJacobianRBDL(Eigen::MatrixXd &jacobian,
612 double total_mass = 0;
614 Eigen::MatrixXd jacobian_i;
619 std::size_t
id = ids(i);
620 double mass = rbdl_model_.mBodies[id].mMass;
623 jacobian_i.setZero(3, getDOFNumber());
624 RigidBodyDynamics::CalcPointJacobian (
628 rbdl_model_.mBodies[
id].mCenterOfMass,
634 jacobian.noalias() = jacobian_i*mass;
638 jacobian.noalias() += jacobian_i*mass;
642 jacobian /= total_mass;
664 void compute(
const RigidBodyDynamics::Model & rbdl_model,
665 const unsigned int joint_id)
667 if(rbdl_model.mJoints[joint_id].mJointType != RigidBodyDynamics::JointTypeCustom)
669 dof_number_ = rbdl_model.mJoints[joint_id].mDoFCount;
674 transformed_joint_axis_ = rbdl_model.X_base[joint_id].inverse().apply(rbdl_model.S[joint_id]);
677 transformed_joint_axis_ = rbdl_model.X_base[joint_id].inverse().toMatrix()
678 * rbdl_model.multdof3_S[joint_id];
687 unsigned int k = rbdl_model.mJoints[joint_id].custom_joint_index;
689 dof_number_ = rbdl_model.mCustomJoints[k]->mDoFCount;
690 transformed_joint_axis_ = rbdl_model.X_base[joint_id].inverse().toMatrix()
691 * rbdl_model.mCustomJoints[k]->S;
721 if ( ( link_id >= rbdl_model_.fixed_body_discriminator )
722 && ( link_id < std::numeric_limits<unsigned int>::max() )
723 && ( link_id - rbdl_model_.fixed_body_discriminator < rbdl_model_.mFixedBodies.size() ) )
742 std::size_t
getLinkId(
const std::string &string_id)
const 744 return (rbdl_model_.GetBodyId(string_id.c_str()));
760 const std::size_t link_id,
761 const etools::Vector3 &point_body_coordinates)
const 763 if (isLinkFixed(link_id))
765 unsigned int flink_id = link_id - rbdl_model_.fixed_body_discriminator;
766 unsigned int parent_id = rbdl_model_.mFixedBodies[flink_id].mMovableParent;
768 etools::Matrix3 fixed_rotation = rbdl_model_.mFixedBodies[flink_id].mParentTransform.E.transpose();
769 etools::Vector3 fixed_position = rbdl_model_.mFixedBodies[flink_id].mParentTransform.r;
771 etools::Matrix3 parent_body_rotation = rbdl_model_.X_base[parent_id].E.transpose();
772 etools::Vector3 parent_body_position = rbdl_model_.X_base[parent_id].r;
774 return (parent_body_position
776 parent_body_rotation * (fixed_position + fixed_rotation * (point_body_coordinates)) );
780 etools::Matrix3 body_rotation = rbdl_model_.X_base[link_id].E.transpose();
781 etools::Vector3 body_position = rbdl_model_.X_base[link_id].r;
783 return (body_position + body_rotation * point_body_coordinates);
797 const etools::Vector3 &position_local)
const 799 RigidBodyDynamics::Math::SpatialTransform mBaseTransform = getLinkTransform(
id);
801 return (mBaseTransform.E.transpose() * position_local + mBaseTransform.r);
815 template<SpatialType::Type t_jacobian_type>
818 const etools::Vector3 tag_position)
const 820 unsigned int joint_id = link_id;
822 if (isLinkFixed(link_id))
824 unsigned int flink_id = link_id - rbdl_model_.fixed_body_discriminator;
825 joint_id = rbdl_model_.mFixedBodies[flink_id].mMovableParent;
832 while (joint_id != 0)
835 jacobian.middleCols(rbdl_model_.mJoints[joint_id].q_index,
836 joint_data_[joint_id].dof_number_),
837 joint_data_[joint_id].transformed_joint_axis_);
839 joint_id = rbdl_model_.lambda[joint_id];
855 unsigned int flink_id =
id - rbdl_model_.fixed_body_discriminator;
857 return(rbdl_model_.mFixedBodies[flink_id].mParentTransform
858 * rbdl_model_.X_base[rbdl_model_.mFixedBodies[flink_id].mMovableParent]);
862 return (rbdl_model_.X_base[
id]);
boost::shared_ptr< const TagLink > TagLinkPtr
void compute(const RigidBodyDynamics::Model &rbdl_model, const unsigned int joint_id)
Computes data for a given joint.
boost::shared_ptr< const TagPartialCoM > TagPartialCoMPtr
TagPointPtr getLinkCoMTag(const std::string &link_string_id) const
Tag for the CoM of a link.
static std::size_t getNumberOfElements(const Type &spatial_type)
Returns number of elements (dimensionality) for given spatial data type.
std::vector< JointData > joint_data_
void getTagJacobian(Eigen::MatrixXd &jacobian, const TagPointPtr tag) const
Get Jacobian for a specific tag.
RigidBodyDynamics::Math::SpatialTransform getLinkTransform(const LinkId id) const
Returns spatial transform for a link.
etools::Vector3 position_
TagPointPtr getPointTag(const std::string &link_string_id, const etools::Vector3 &position_local) const
Tag for a point on a link.
rigidbody::RigidBodyPose getTagPose(const TagLinkPtr tag) const
Get tag pose.
etools::Vector3 getTagPosition(const TagCoMPtr tag) const
Get CoM of the robot.
void setDefaults()
Initialization.
Eigen::MatrixXd transformed_joint_axis_
void update(const Eigen::VectorXd &joint_angles)
Update model.
TagLinkPtr getLinkTag(const std::string &link_string_id) const
Tag for a link.
TagCoMPtr getCoMTag() const
CoM tag.
#define HUMOTO_THROW_MSG(s)
HUMOTO_THROW_MSG throws an error message concatenated with the name of the function (if supported)...
etools::Vector3 getTagPosition(const TagPointPtr tag) const
Get position of a tag.
double getTagMass(const TagPartialCoMPtr tag) const
Get mass.
EIGEN_DEFAULT_DENSE_INDEX_TYPE EigenIndex
etools::Vector3 getTagPosition(const TagLinkPtr tag) const
Get position of a tag.
void load(const std::string &urdf_filename)
Load URDF model.
void getTagJacobian(Eigen::MatrixXd &jacobian, const LinkId link_id, const etools::Vector3 tag_position) const
Get Jacobian for a specific tag.
Eigen::Matrix< unsigned int, Eigen::Dynamic, 1 > IndexVector
TagPartialCoMPtr getCoMTag(const std::vector< std::string > &link_string_ids) const
CoM Tag for several bodies.
Model(const ModelParameters &model_parameters, const std::string &urdf_filename)
Construct using URDF model.
etools::Vector3 getTagPosition(const TagPartialCoMPtr tag) const
Get CoM of several bodies.
boost::shared_ptr< const TagCoM > TagCoMPtr
etools::Vector3 convertMatrixToEulerAngles(const etools::Matrix3 &rotation_matrix, const EulerAngles::Type euler_angles_type)
Convert rotation matrix to Euler angles.
etools::Vector3 getPointTagPosition(const std::size_t id, const etools::Vector3 &position_local) const
Get position of a tag.
RigidBodyDynamics::Model rbdl_model_
Stores precomputed data for each joint.
void getTagJacobian(Eigen::MatrixXd &jacobian, const TagCoMPtr tag) const
Compute CoM Jacobian of the robot.
void getTagJacobian(Eigen::MatrixXd &jacobian, const TagLinkPtr tag) const
Get Jacobian for a specific tag.
Model()
Default constructor. It is necesary to load() model before using.
Partial CoM tag (subset of links)
ModelParameters model_parameters_
void load(const ModelParameters &model_parameters, const std::string &urdf_filename)
Load URDF model.
The root namespace of HuMoTo.
bool isLinkFixed(const std::size_t link_id) const
True if a body is fixed to its parent.
std::size_t getLinkId(const std::string &string_id) const
Determines id of a body based on its string id.
std::size_t getDOFNumber() const
Return number of DoF.
etools::Vector3 expressInRootFrame(const std::size_t link_id, const etools::Vector3 &point_body_coordinates) const
Express local position in root frame.
Model(const std::string &urdf_filename)
Construct using URDF model.
etools::Matrix3 getTagOrientation(const TagLinkPtr tag) const
Get orientation of a tag.
etools::Matrix3 getTagOrientation(const TagPointPtr tag) const
Get orientation of a tag.
Wraps RBDL model and provides additional functionality.
double getTagMass(const TagCoMPtr tag) const
Get mass.
void getTagJacobian(Eigen::MatrixXd &jacobian, const TagPartialCoMPtr tag) const
Get CoM jacbian for a set of bodies.
rigidbody::RigidBodyPose getTagPose(const TagPointPtr tag) const
Get tag pose.
boost::shared_ptr< const TagPoint > TagPointPtr
double getTagMass(const TagLinkPtr tag) const
Get mass.