6 #ifndef CNOID_BODY_LINK_H
7 #define CNOID_BODY_LINK_H
9 #include <cnoid/ClonableReferenced>
10 #include <cnoid/EigenTypes>
11 #include <cnoid/SceneUpdate>
13 #include "exportdecl.h"
29 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
40 return static_cast<Link*
>(doClone(
nullptr));
45 virtual void initializeState();
47 const std::string&
name()
const {
return name_; }
48 int index()
const {
return index_; }
49 bool isValid()
const {
return (index_ >= 0); }
50 bool isRoot()
const {
return !parent_; }
51 bool isStatic()
const;
52 bool isFixedToRoot()
const;
53 bool isOwnerOf(
const Link* link)
const;
68 template<
class Scalar,
int Mode,
int Options>
69 void setPosition(
const Eigen::Transform<Scalar, 3, Mode, Options>& T){
70 T_ = T.template cast<Isometry3::Scalar>();
72 template<
class Derived>
74 T_ = T.template cast<Isometry3::Scalar>();
76 template<
typename Derived1,
typename Derived2>
77 void setPosition(
const Eigen::MatrixBase<Derived1>& rotation,
const Eigen::MatrixBase<Derived2>& translation){
78 T_.linear() = rotation;
79 T_.translation() = translation;
82 Isometry3::TranslationPart
p() {
return T_.translation(); }
83 Isometry3::ConstTranslationPart
p()
const {
return T_.translation(); }
84 Isometry3::TranslationPart
translation() {
return T_.translation(); }
85 Isometry3::ConstTranslationPart
translation()
const {
return T_.translation(); }
87 template<
typename Derived>
89 T_.translation() = p.template cast<Isometry3::Scalar>();
92 Isometry3::LinearPart
R() {
return T_.linear(); }
93 Isometry3::ConstLinearPart
R()
const {
return T_.linear(); }
94 Isometry3::LinearPart
rotation() {
return T_.linear(); }
95 Isometry3::ConstLinearPart
rotation()
const {
return T_.linear(); }
97 template<
typename Derived>
99 T_.linear() = R.template cast<Isometry3::Scalar>();
103 T_.linear() = a.template cast<Isometry3::Scalar>().toRotationMatrix();
105 template<
typename Derived>
107 T_.linear() = q.template cast<Isometry3::Scalar>().toRotationMatrix();
114 Isometry3::ConstTranslationPart
b()
const {
return Tb_.translation(); }
117 Isometry3::ConstLinearPart
Rb()
const {
return Tb_.linear(); }
120 [[deprecated(
"This func. always returns the identity matrix")]]
137 PseudoContinuousTrackJoint = 4,
140 REVOLUTE_JOINT = RevoluteJoint,
141 ROTATIONAL_JOINT = RevoluteJoint,
142 PRISMATIC_JOINT = PrismaticJoint,
143 SLIDE_JOINT = PrismaticJoint,
144 FREE_JOINT = FreeJoint,
145 FIXED_JOINT = FixedJoint,
146 PSEUDO_CONTINUOUS_TRACK = PseudoContinuousTrackJoint
149 #if !defined(__GNUC__) || __GNUC__ > 5
150 [[deprecated(
"Use Link::PseudoContinuousTrack.")]]
152 static constexpr
int PseudoContinousTrack = PseudoContinuousTrackJoint;
155 const std::string& jointName()
const;
159 const char* jointTypeLabel()
const;
160 const char* jointTypeSymbol()
const;
161 [[deprecated(
"Use jointTypeLabel or jointTypeSymbol")]]
162 const char* jointTypeString(
bool useUnderscore =
false)
const;
179 double Jm2()
const {
return Jm2_; }
185 JointDisplacement = 1 << 0,
186 JointAngle = JointDisplacement,
187 JointVelocity = 1 << 1,
188 JointAcceleration = 1 << 2,
189 JointEffort = 1 << 3,
190 JointForce = JointEffort,
191 JointTorque = JointEffort,
192 LinkPosition = 1 << 4,
194 LinkExtWrench = 1 << 6,
195 LinkContactState = 1 << 7,
198 HighGainActuation = 1 << 8,
201 DeprecatedJointSurfaceVelocity = 1 << 9,
207 NO_ACTUATION = StateNone,
208 JOINT_TORQUE = JointTorque,
209 JOINT_FORCE = JointForce,
210 JOINT_EFFORT = JointEffort,
211 JOINT_ANGLE = JointAngle,
212 JOINT_DISPLACEMENT = JointDisplacement,
213 JOINT_VELOCITY = JointVelocity,
214 LINK_POSITION = LinkPosition
217 #if !defined(__GNUC__) || __GNUC__ > 5
218 [[deprecated(
"Use Link::JointVelocity as the actuation mode and Link::PseudoContinuousTrackJoint as the joint type.")]]
220 static constexpr
int JOINT_SURFACE_VELOCITY = DeprecatedJointSurfaceVelocity;
227 [[deprecated(
"Just use the link name as a prefix or use the int type as a variable.")]]
235 static constexpr
short AllStateHighGainActuationMode =
236 LinkPosition | LinkTwist | LinkExtWrench | JointDisplacement | JointVelocity | JointEffort | HighGainActuation;
244 static std::string getStateModeString(
short mode);
246 double q()
const {
return q_; }
247 double&
q() {
return q_; }
248 double dq()
const {
return dq_; }
249 double&
dq() {
return dq_; }
250 double ddq()
const {
return ddq_; }
251 double&
ddq() {
return ddq_; }
252 double u()
const {
return u_; }
253 double&
u() {
return u_; }
255 double q_target()
const {
return q_target_; }
256 double& q_target() {
return q_target_; }
257 double dq_target()
const {
return dq_target_; }
258 double& dq_target() {
return dq_target_; }
261 double q_upper()
const {
return q_upper_; }
262 double q_lower()
const {
return q_lower_; }
263 double dq_upper()
const {
return dq_upper_; }
264 double dq_lower()
const {
return dq_lower_; }
285 double m()
const {
return m_; }
286 double mass()
const {
return m_; }
293 Vector6::ConstFixedSegmentReturnType<3>::Type
externalForce()
const {
return F_ext_.head<3>(); }
294 Vector6::FixedSegmentReturnType<3>::Type
externalForce() {
return F_ext_.head<3>(); }
295 Vector6::ConstFixedSegmentReturnType<3>::Type
externalTorque()
const {
return F_ext_.tail<3>(); }
296 Vector6::FixedSegmentReturnType<3>::Type
externalTorque() {
return F_ext_.tail<3>(); }
300 Vector6::ConstFixedSegmentReturnType<3>::Type
f_ext()
const {
return F_ext_.head<3>(); }
301 Vector6::FixedSegmentReturnType<3>::Type
f_ext() {
return F_ext_.head<3>(); }
302 Vector6::ConstFixedSegmentReturnType<3>::Type
tau_ext()
const {
return F_ext_.tail<3>(); }
303 Vector6::FixedSegmentReturnType<3>::Type
tau_ext() {
return F_ext_.tail<3>(); }
307 tau_ext() += (T_ * p_local).cross(f_global);
312 tau_ext() += p_global.cross(f_global);
315 [[deprecated(
"Use addExternalForceAtLocalPosition.")]]
317 addExternalForceAtLocalPosition(f_global, p_local);
321 std::string materialName()
const;
328 : position_(position), normal_(normal), force_(force), velocity_(velocity), depth_(depth) { }
363 const std::vector<ContactPoint>&
contactPoints()
const {
return contactPoints_; }
368 bool hasDedicatedCollisionShape()
const;
371 void setBodyToSubTree(
Body* newBody);
374 void setName(
const std::string& name);
375 virtual void prependChild(
Link* link);
376 virtual void appendChild(
Link* link);
377 bool removeChild(
Link* link);
383 template<
typename Derived>
385 Tb_.translation() = offset;
387 template<
typename Derived>
389 Tb_.linear() = offset;
393 Tb_.linear() = a.template cast<Isometry3::Scalar>().toRotationMatrix();
396 template<
typename Derived>
397 [[deprecated(
"No need to use this function.")]]
403 void setJointName(
const std::string& name);
404 void resetJointSpecificName();
409 void setJointRange(
double lower,
double upper) { q_lower_ = lower; q_upper_ = upper; }
418 void setMaterial(
const std::string& name);
424 void clearShapeNodes(
SgUpdateRef update =
nullptr);
426 [[deprecated(
"You don't have to use this function.")]]
430 [[deprecated(
"Use T() instead.")]]
432 [[deprecated(
"Uuse R() instead.")]]
434 [[deprecated(
"Use setRotation(.) instead.")]]
438 [[deprecated(
"Use T() instead.")]]
443 template<
typename T> T info(
const std::string& key)
const;
444 template<
typename T> T info(
const std::string& key,
const T& defaultValue)
const;
445 template<
typename T>
void setInfo(
const std::string& key,
const T& value);
446 std::string info(
const std::string& key,
const char* defaultValue)
const;
449 #ifdef CNOID_BACKWARD_COMPATIBILITY
451 const double& ulimit()
const {
return q_upper_; }
452 const double& llimit()
const {
return q_lower_; }
453 const double& uvlimit()
const {
return dq_upper_; }
454 const double& lvlimit()
const {
return dq_lower_; }
456 Matrix3 segmentAttitude()
const {
return R(); }
457 void setSegmentAttitude(
const Matrix3& Ra) { R() = Ra; }
461 Referenced* doClone(CloneMap* cloneMap)
const override;
475 short actuationMode_;
506 std::vector<ContactPoint> contactPoints_;
509 std::string jointSpecificName_;
511 ref_ptr<SgGroup> visualShape_;
512 ref_ptr<SgGroup> collisionShape_;
514 ref_ptr<Mapping> info_;
516 void setBodyToSubTreeIter(Body* newBody);
519 template<> CNOID_EXPORT
double Link::info(
const std::string& key)
const;
520 template<> CNOID_EXPORT
double Link::info(
const std::string& key,
const double& defaultValue)
const;
521 template<> CNOID_EXPORT
bool Link::info(
const std::string& key,
const bool& defaultValue)
const;
522 template<> CNOID_EXPORT
void Link::setInfo(
const std::string& key,
const double& value);
523 template<> CNOID_EXPORT
void Link::setInfo(
const std::string& key,
const bool& value);