19 #ifndef __se3_model_hxx__ 20 #define __se3_model_hxx__ 22 #include "pinocchio/spatial/fwd.hpp" 23 #include "pinocchio/utils/string-generator.hpp" 24 #include "pinocchio/multibody/liegroup/liegroup-algo.hpp" 26 #include <boost/bind.hpp> 27 #include <boost/utility.hpp> 36 const std::string& name;
39 : name(name), typeMask(typeMask) {}
40 bool operator()(
const Frame& frame)
const 41 {
return (typeMask & frame.
type) && (name == frame.
name); }
45 inline std::ostream& operator<<(std::ostream & os,
const Model & model)
47 os <<
"Nb joints = " << model.
njoints <<
" (nq="<< model.
nq<<
",nv="<<model.
nv<<
")" << std::endl;
48 for(Model::Index i=0;i<(Model::Index)(model.
njoints);++i)
50 os <<
" Joint "<< model.
names[i] <<
": parent=" << model.
parents[i] << std::endl;
56 template<
typename Jo
intModelDerived>
59 const SE3 & joint_placement,
60 const std::string & joint_name,
61 const Eigen::VectorXd & max_effort,
62 const Eigen::VectorXd & max_velocity,
63 const Eigen::VectorXd & min_config,
64 const Eigen::VectorXd & max_config
67 assert( (njoints==(
int)joints.size())&&(njoints==(
int)inertias.size())
68 &&(njoints==(
int)parents.size())&&(njoints==(
int)jointPlacements.size()) );
69 assert((joint_model.nq()>=0) && (joint_model.nv()>=0));
71 assert(max_effort.size() == joint_model.nv()
72 && max_velocity.size() == joint_model.nv()
73 && min_config.size() == joint_model.nq()
74 && max_config.size() == joint_model.nq());
76 Model::JointIndex idx = (Model::JointIndex) (njoints++);
78 joints .push_back(
JointModel(joint_model.derived()));
79 JointModelDerived & jmodel = boost::get<JointModelDerived>(joints.back());
80 jmodel.setIndexes(idx,
nq,
nv);
82 inertias .push_back(Inertia::Zero());
83 parents .push_back(parent);
84 jointPlacements.push_back(joint_placement);
85 names .push_back(joint_name);
86 nq += joint_model.nq();
87 nv += joint_model.nv();
92 effortLimit.conservativeResize(
nv);
93 jmodel.jointVelocitySelector(effortLimit) = max_effort;
94 velocityLimit.conservativeResize(
nv);
95 jmodel.jointVelocitySelector(velocityLimit) = max_velocity;
96 lowerPositionLimit.conservativeResize(
nq);
97 jmodel.jointConfigSelector(lowerPositionLimit) = min_config;
98 upperPositionLimit.conservativeResize(
nq);
99 jmodel.jointConfigSelector(upperPositionLimit) = max_config;
101 neutralConfiguration.conservativeResize(
nq);
104 rotorInertia.conservativeResize(
nv);
105 jmodel.jointVelocitySelector(rotorInertia).setZero();
106 rotorGearRatio.conservativeResize(
nv);
107 jmodel.jointVelocitySelector(rotorGearRatio).setZero();
110 subtrees.push_back(IndexVector(1));
111 subtrees[idx][0] = idx;
112 addJointIndexToParentSubtrees(idx);
116 template<
typename Jo
intModelDerived>
119 const SE3 & joint_placement,
120 const std::string & joint_name
123 Eigen::VectorXd max_effort, max_velocity, min_config, max_config;
125 max_effort = Eigen::VectorXd::Constant(joint_model.nv(), std::numeric_limits<double>::max());
126 max_velocity = Eigen::VectorXd::Constant(joint_model.nv(), std::numeric_limits<double>::max());
127 min_config = Eigen::VectorXd::Constant(joint_model.nq(), -std::numeric_limits<double>::max());
128 max_config = Eigen::VectorXd::Constant(joint_model.nq(), std::numeric_limits<double>::max());
130 return addJoint(parent, joint_model, joint_placement, joint_name, max_effort, max_velocity, min_config, max_config);
139 fidx = (int)getFrameId(names[parents[jidx]], (
FrameType)(JOINT | FIXED_JOINT));
141 assert((
size_t)fidx < frames.size() &&
"Frame index out of bound");
143 return addFrame(
Frame(names[jidx],jidx,(FrameIndex)fidx,SE3::Identity(),JOINT));
149 const SE3 & body_placement)
152 inertias[joint_index] += iYf;
157 const JointIndex & parentJoint,
158 const SE3 & body_placement,
161 if(previousFrame < 0) {
164 previousFrame = (int)getFrameId(names[parentJoint], (
FrameType)(JOINT | FIXED_JOINT));
166 assert((
size_t)previousFrame < frames.size() &&
"Frame index out of bound");
167 return addFrame(
Frame(body_name, parentJoint, (FrameIndex)previousFrame, body_placement, BODY));
172 return getFrameId(name, BODY);
177 return existFrame(name, BODY);
183 typedef std::vector<std::string>::iterator::difference_type it_diff_t;
184 it_diff_t res = std::find(names.begin(),names.end(),name) - names.begin();
185 assert((res<INT_MAX) &&
"Id superior to int range. Should never happen.");
186 return Model::JointIndex(res);
191 return (names.end() != std::find(names.begin(),names.end(),name));
196 assert( index < (Model::JointIndex)joints.size() );
206 assert(it != frames.end() &&
"Frame not found");
207 assert((std::find_if( boost::next(it), frames.end(),
details::FilterFrame(name, type)) == frames.end())
208 &&
"Several frames match the filter");
209 return Model::FrameIndex(it - frames.begin());
214 return std::find_if( frames.begin(), frames.end(),
221 if( !existFrame(frame.
name, frame.
type) )
223 frames.push_back(frame);
235 for(JointIndex parent = parents[joint_id]; parent>0; parent = parents[parent])
236 subtrees[parent].push_back(joint_id);
243 #endif // ifndef __se3_model_hxx__ PINOCCHIO_DEPRECATED const std::string & getJointName(const JointIndex index) const
Get the name of a joint given by its index.
bool existJointName(const std::string &name) const
Check if a joint given by its name exists.
int nq
Dimension of the configuration vector representation.
int nv
Dimension of the velocity vector space.
int addFrame(const Frame &frame)
Adds a frame to the kinematic tree.
FrameIndex getFrameId(const std::string &name, const FrameType &type=(FrameType)(JOINT|FIXED_JOINT|BODY|OP_FRAME|SENSOR)) const
Returns the index of a frame given by its name.
void addJointIndexToParentSubtrees(const JointIndex joint_id)
Add the joint_id to its parent subtrees.
void appendBodyToJoint(const JointIndex joint_index, const Inertia &Y, const SE3 &body_placement=SE3::Identity())
Append a body to a given joint of the kinematic tree.
FrameType type
Type of the frame.
int nq(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointNqVisitor to get the dimension of the joint configuration spac...
std::vector< JointIndex > parents
Joint parent of joint i, denoted li (li==parents[i]).
int nv(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointNvVisitor to get the dimension of the joint tangent space...
A Plucker coordinate frame attached to a parent joint inside a kinematic tree.
bool existBodyName(const std::string &name) const
Check if a body given by its name exists.
Specialization of an std::vector with an aligned allocator. This specialization might be used when th...
int addJointFrame(const JointIndex &jointIndex, int frameIndex=-1)
Add a joint to the frame tree.
bool existFrame(const std::string &name, const FrameType &type=(FrameType)(JOINT|FIXED_JOINT|BODY|OP_FRAME|SENSOR)) const
Checks if a frame given by its name exists.
FrameType
Enum on the possible types of frame.
int njoints
Number of joints.
std::vector< std::string > names
Name of joint i
JointIndex getJointId(const std::string &name) const
Return the index of a joint given by its name.
std::string name
Name of the frame.
Derived_t se3Action(const SE3 &M) const
aI = aXb.act(bI)
int addBodyFrame(const std::string &body_name, const JointIndex &parentJoint, const SE3 &body_placement=SE3::Identity(), int previousFrame=-1)
Add a body to the frame tree.
JointIndex addJoint(const JointIndex parent, const JointModelBase< JointModelDerived > &joint_model, const SE3 &joint_placement, const std::string &joint_name, const Eigen::VectorXd &max_effort, const Eigen::VectorXd &max_velocity, const Eigen::VectorXd &min_config, const Eigen::VectorXd &max_config)
Add a joint to the kinematic tree with given bounds.
JointIndex getBodyId(const std::string &name) const
Return the index of a body given by its name.