19 #include <boost/asio/io_service.hpp> 20 #include <boost/function.hpp> 21 #include <boost/thread/thread.hpp> 27 #include <type_traits> 128 explicit Model(
unsigned int* n_threads =
nullptr);
162 std::vector<std::vector<unsigned int>>
mu;
215 std::vector<Math::SpatialTransform>
X_J;
217 std::vector<Math::SpatialVector>
c_J;
225 std::vector<Math::SpatialTransform>
X_T;
248 std::vector<Math::SpatialVector>
c;
251 std::vector<Math::SpatialMatrix>
IA;
257 std::vector<Math::SpatialVector>
U;
275 std::vector<Math::Momentum>
hc;
334 std::unique_ptr<boost::asio::io_service::work>
work;
340 if (threads.size() > 0)
342 for (
unsigned int i = 0; i < threads.size(); ++i)
345 if ((retcode = pthread_setschedparam(threads[i]->native_handle(), policy, ¶m)) != 0)
347 if (retcode == EPERM)
349 std::cerr <<
"Model.setThreadParameters: Failed setting thread parameters. Invalid permissions" << std::endl;
351 else if (retcode == ESRCH)
353 std::cerr <<
"Model.setThreadParameters: Failed setting thread parameters. No thread with the ID could be found" << std::endl;
355 else if (retcode == EINVAL)
357 std::cerr <<
"Model.setThreadParameters: Failed setting thread parameters. policy is not a recognized policy, or param does not make sense for " 363 std::cerr <<
"Model.setThreadParameters: Failed setting thread parameters. pthread_setschedparam returned with unknown error code " << retcode
409 std::string body_name =
"");
420 std::string body_name =
"");
434 if (mBodyNameMap.count(body_name) == 0)
436 return std::numeric_limits<unsigned int>::max();
439 return mBodyNameMap.find(body_name)->second;
453 frame = referenceFrameMap.at(frameName);
455 catch (
const std::out_of_range& e)
466 std::map<std::string, unsigned int>::const_iterator iter = mBodyNameMap.begin();
468 while (iter != mBodyNameMap.end())
470 if (iter->second == body_id)
485 if ((body_id >= fixed_body_discriminator) && (body_id < std::numeric_limits<unsigned int>::max()) && (body_id - fixed_body_discriminator < mFixedBodies.size()))
494 if ((
id > 0) && (
id < mBodies.size()))
499 if ((
id >= fixed_body_discriminator) && (id < std::numeric_limits<unsigned int>::max()))
501 if (
id - fixed_body_discriminator < mFixedBodies.size())
518 if (
id >= fixed_body_discriminator)
523 unsigned int parent_id = lambda[id];
525 while (mBodies[parent_id].mIsVirtual)
527 parent_id = lambda[parent_id];
539 if (
id >= fixed_body_discriminator)
544 unsigned int child_id = id;
545 unsigned int parent_id = lambda[id];
547 if (mBodies[parent_id].mIsVirtual)
549 while (mBodies[parent_id].mIsVirtual)
551 child_id = parent_id;
552 parent_id = lambda[child_id];
554 return X_T[child_id];
567 if (
id >= fixed_body_discriminator)
569 throw RdlException(
"Error: setting of parent transform not supported for fixed bodies!");
572 unsigned int child_id = id;
573 unsigned int parent_id = lambda[id];
575 if (mBodies[parent_id].mIsVirtual)
577 while (mBodies[parent_id].mIsVirtual)
579 child_id = parent_id;
580 parent_id = lambda[child_id];
582 X_T[child_id] = transform;
599 unsigned int q_index = mJoints[i].q_index;
600 return Math::Quaternion(Q[q_index], Q[q_index + 1], Q[q_index + 2], Q[multdof3_w_index[i]]);
612 unsigned int q_index = mJoints[i].q_index;
614 Q[q_index] = quat[0];
615 Q[q_index + 1] = quat[1];
616 Q[q_index + 2] = quat[2];
617 Q[multdof3_w_index[i]] = quat[3];
637 if (id_1 == 0 || id_2 == 0)
642 unsigned int chain_1_size = lambda_chain[id_1].size();
643 unsigned int chain_2_size = lambda_chain[id_2].size();
645 if (chain_1_size <= chain_2_size)
648 for (
unsigned int i = 1; i < chain_1_size; i++)
650 if (lambda_chain[id_1][i] != lambda_chain[id_2][i])
652 return lambda_chain[id_1][i - 1];
656 return lambda_chain[id_1][chain_1_size - 1];
661 for (
unsigned int i = 1; i < chain_2_size; i++)
663 if (lambda_chain[id_1][i] != lambda_chain[id_2][i])
665 return lambda_chain[id_2][i - 1];
669 return lambda_chain[id_2][chain_2_size - 1];
686 if (rbi(0, 0) <= 0 || rbi(1, 1) <= 0 || rbi(2, 2) <= 0)
688 std::cerr <<
"\033[1;31m Invalid inertia: Each element of the trace must be > 0 \033[0m" << std::endl;
692 if (rbi(0, 0) >= (rbi(1, 1) + rbi(2, 2)))
694 std::cerr <<
"\033[1;31m Invalid inertia: Triangle inequality not satisfied \033[0m\n" << std::endl;
698 if (rbi(1, 1) >= (rbi(2, 2) + rbi(0, 0)))
700 std::cerr <<
"\033[1;31m Invalid inertia: Triangle inequality not satisfied \033[0m\n" << std::endl;
704 if (rbi(2, 2) >= (rbi(1, 1) + rbi(0, 0)))
706 std::cerr <<
"\033[1;31m Invalid inertia: Triangle inequality not satisfied \033[0m\n" << std::endl;
710 if (!(rbi - rbi.transpose()).isZero(1.e-8))
712 std::cerr <<
"\033[1;31m Invalid inertia: Inertia matrix is not symmetric \033[0m\n" << std::endl;
716 Eigen::EigenSolver<Eigen::Matrix3d> solver(rbi);
717 Eigen::EigenSolver<Eigen::Matrix3d>::EigenvalueType eivals = solver.eigenvalues();
719 for (
unsigned int i = 0; i < eivals.rows(); i++)
721 if (eivals[i].real() <= 0)
723 std::cerr <<
"\033[1;31m Invalid inertia: Inertia matrix is not positive definite \033[0m\n" << std::endl;
736 #endif // ifndef RDL_MODEL_H 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< SpatialForce, Eigen::aligned_allocator< SpatialForce > > SpatialForceV
std::vector< Joint > mJoints
All joints.
Describes all properties of a single body.
Math::VectorNd u
Temporary variable u (RBDA p. 130)
unsigned int GetParentBodyId(unsigned int id)
Determines id the actual parent body.
std::vector< Math::SpatialVector > c_J
Math::Quaternion GetQuaternion(unsigned int i, const Math::VectorNd &Q) const
Gets the quaternion for body i (only valid if body i is connected by a JointTypeSpherical joint) ...
std::vector< SpatialAcceleration, Eigen::aligned_allocator< SpatialAcceleration > > SpatialAccelerationV
std::vector< unsigned int > multdof3_w_index
EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(RobotDynamics::Joint)
std::unique_ptr< boost::asio::io_service::work > work
boost::thread_group thread_pool
std::vector< Math::Matrix63 > multdof3_U
void operator=(const Model &)=delete
CustomJoint is a struct used to create a joint with user defined parameters. This is accomplished by ...
std::shared_ptr< Model > ModelPtr
void SetQuaternion(unsigned int i, const Math::Quaternion &quat, Math::VectorNd &Q) const
Sets the quaternion for body i (only valid if body i is connected by a JointTypeSpherical joint) ...
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
std::vector< boost::thread * > threads
unsigned int addBodySphericalJoint(const unsigned int parent_id, const Math::SpatialTransform &joint_frame, const Joint &joint, const Body &body, std::string body_name="")
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.
std::vector< Math::SpatialTransform > X_lambda
Transformation from the parent body to the current body .
bool setThreadParameters(int policy, struct sched_param param)
ReferenceFramePtr getReferenceFrame(const std::string &frameName) const
Get a fixed or moveable body's reference frame.
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
bool IsBodyId(unsigned int id) const
Math::SpatialForceV pA
The spatial bias force.
std::vector< Math::Matrix63 > multdof3_S_o
void SetJointFrame(unsigned int id, const Math::SpatialTransform &transform)
Sets the joint frame transformtion, i.e. the second argument to Model::addBody(). ...
std::vector< Body > mBodies
All bodies 0 ... N_B, including the base.
Describes a joint relative to the predecessor body.
unsigned int GetBodyId(const char *body_name) const
Returns the id of a body that was passed to addBody()
Quaternion that are used for singularity free joints.
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)
Math::SpatialAccelerationV a
The spatial velocity of the bodies.
std::vector< CustomJoint * > mCustomJoints
std::vector< SpatialMotion, Eigen::aligned_allocator< SpatialMotion > > SpatialMotionV
std::map< std::string, ReferenceFramePtr > referenceFrameMap
std::vector< SpatialInertia, Eigen::aligned_allocator< SpatialInertia > > SpatialInertiaV
std::vector< Math::Matrix3d > multdof3_Dinv
std::vector< ReferenceFramePtr > bodyCenteredFrames
Model(unsigned int *n_threads=nullptr)
Constructor.
Contains all information about the rigid body model.
unsigned int getCommonMovableParentId(unsigned int id_1, unsigned int id_2) const
std::vector< Math::SpatialVector > U
Temporary variable U_i (RBDA p. 130)
std::vector< Math::SpatialVector > c
The velocity dependent spatial acceleration.
std::vector< unsigned int > mFixedJointCount
The number of fixed joints that have been declared before each joint.
unsigned int fixed_body_discriminator
Value that is used to discriminate between fixed and movable bodies.
Math::RigidBodyInertiaV Ic
Math::SpatialTransform GetJointFrame(unsigned int id)
Returns the joint frame transformtion, i.e. the second argument to Model::addBody().
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::string GetBodyName(unsigned int body_id) const
Returns the name of a body for a given body id.
std::vector< ReferenceFramePtr > fixedBodyFrames
3 DoF joint using Quaternions for joint positional variables and
std::vector< Math::SpatialTransform > X_J
std::vector< Math::Vector3d > multdof3_u
std::vector< MotionVector, Eigen::aligned_allocator< MotionVector > > MotionVectorV
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.
std::vector< RigidBodyInertia, Eigen::aligned_allocator< RigidBodyInertia > > RigidBodyInertiaV
unsigned int previously_added_body_id
Id of the previously added body, required for Model::appendBody()
unsigned int qdot_size
The size of the.