本文整理汇总了C++中kdl::Chain::getNrOfSegments方法的典型用法代码示例。如果您正苦于以下问题:C++ Chain::getNrOfSegments方法的具体用法?C++ Chain::getNrOfSegments怎么用?C++ Chain::getNrOfSegments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kdl::Chain
的用法示例。
在下文中一共展示了Chain::getNrOfSegments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printKDLChain
void leatherman::printKDLChain(const KDL::Chain &c, std::string text)
{
ROS_INFO("[%s] # segments: %d # joints: %d", text.c_str(), c.getNrOfSegments(), c.getNrOfJoints());
double r,p,y,jnt_pos = 0;
for(size_t j = 0; j < c.getNrOfSegments(); ++j)
{
c.getSegment(j).pose(jnt_pos).M.GetRPY(r,p,y);
ROS_INFO("[%s] [%2d] segment: %21s xyz: %0.3f %0.3f %0.3f rpy: %0.3f %0.3f %0.3f",
text.c_str(), int(j),
c.getSegment(j).getName().c_str(),
c.getSegment(j).pose(jnt_pos).p.x(),
c.getSegment(j).pose(jnt_pos).p.y(),
c.getSegment(j).pose(jnt_pos).p.z(),
r,p,y);
c.getSegment(j).getJoint().pose(jnt_pos).M.GetRPY(r,p,y);
ROS_INFO("[%s] joint: %21s xyz: %0.3f %0.3f %0.3f rpy: %0.3f %0.3f %0.3f type: %s",
text.c_str(),
c.getSegment(j).getJoint().getName().c_str(),
c.getSegment(j).getJoint().pose(jnt_pos).p.x(),
c.getSegment(j).getJoint().pose(jnt_pos).p.y(),
c.getSegment(j).getJoint().pose(jnt_pos).p.z(),
r,p,y,
c.getSegment(j).getJoint().getTypeName().c_str());
}
}
示例2: main
int main()
{
KDLCollada kdlCollada;
vector <KDL::Chain> kinematicsModels;
const string filename = "puma.dae"; // loading collada kinematics model and converting it to kdl serial chain
if (!kdlCollada.load(COLLADA_MODELS_PATH + filename, kinematicsModels))
{
cout << "Failed to import " << filename;
return 0;
}
cout << "Imported " << kinematicsModels.size() << " kinematics chains" << endl;
for (unsigned int i = 0; i < kinematicsModels.size(); i++) // parsing output kdl serail chain
{
KDL::Chain chain = kinematicsModels[i];
cout << "Chain " << i << " has " << chain.getNrOfSegments() << " segments" << endl;
for (unsigned int u = 0; u < chain.getNrOfSegments(); u++)
{
KDL::Segment segment = chain.segments[u];
string segmentName = segment.getName();
cout << "Segment " << segmentName << " :" <<endl;
KDL::Frame f_tip = segment.getFrameToTip();
KDL::Vector rotAxis = f_tip.M.GetRot();
double rotAngle = f_tip.M.GetRotAngle(rotAxis);
KDL::Vector trans = f_tip.p;
cout << " frame: rotation " << rotAxis.x() << " " << rotAxis.y() << " " << rotAxis.z() << " " << rotAngle * 180 / M_PI << endl;
cout << " frame: translation " << trans.x() << " " << trans.y() << " " << trans.z() << endl;
KDL::RigidBodyInertia inertia = segment.getInertia();
KDL::Joint joint = segment.getJoint();
string jointName = joint.getName();
string jointType = joint.getTypeName();
KDL::Vector jointAxis = joint.JointAxis();
KDL::Vector jointOrigin = joint.JointOrigin();
cout << " joint name: " << jointName << endl;
cout << " type: " << jointType << endl;
cout << " axis: " << jointAxis.x() << " " <<jointAxis.y() << " " << jointAxis.z() << endl;
cout << " origin: " << jointOrigin.x() << " " << jointOrigin.y() << " " << jointOrigin.z() << endl;
}
}
return 0;
}
示例3: getKDLChainInfo
void getKDLChainInfo(kinematics_msgs::KinematicSolverInfo &chain_info)
{
unsigned int nj = chain.getNrOfJoints();
unsigned int nl = chain.getNrOfSegments();
ROS_DEBUG("nj: %d", nj);
ROS_DEBUG("nl: %d", nl);
//---setting up response
//joint_names
for(unsigned int i=0; i<nj; i++)
{
ROS_DEBUG("joint_name[%d]: %s", i, chain.getSegment(i).getJoint().getName().c_str());
chain_info.joint_names.push_back(chain.getSegment(i).getJoint().getName());
}
//limits
//joint limits are only saved in KDL::ChainIkSolverPos_NR_JL iksolverpos -> ik_solve().....but this is not visible here!
/*for(unsigned int i=0; i<nj; i++)
{
chain_info.limits[i].joint_name=chain.getSegment(i).getJoint().getName();
chain_info.limits[i].has_position_limits=
chain_info.limits[i].min_position=
chain_info.limits[i].max_position=
chain_info.limits[i].has_velocity_limits=
chain_info.limits[i].max_velocity=
chain_info.limits[i].has_acceleration_limits=
chain_info.limits[i].max_acceleration=
}*/
//link_names
for(unsigned int i=0; i<nl; i++)
{
chain_info.link_names.push_back(chain.getSegment(i).getName());
}
}
示例4: computeRNEDynamicsForChain
void computeRNEDynamicsForChain(KDL::Tree& a_tree, const std::string& rootLink, const std::string& tipLink, KDL::Vector& grav,
std::vector<kdle::JointState>& jointState, std::vector<kdle::SegmentState>& linkState)
{
KDL::Chain achain;
a_tree.getChain(rootLink, tipLink, achain);
KDL::JntArray q(achain.getNrOfJoints());
KDL::JntArray q_dot(achain.getNrOfJoints());
KDL::JntArray q_dotdot(achain.getNrOfJoints());
JntArray torques(achain.getNrOfJoints());
KDL::Wrenches f_ext;
f_ext.resize(achain.getNrOfSegments());
std::cout << endl << endl;
printf("RNE dynamics values \n");
KDL::ChainIdSolver_RNE *rneDynamics = new ChainIdSolver_RNE(achain, -grav);
for (unsigned int i = 0; i < achain.getNrOfJoints(); ++i)
{
q(i) = jointState[i].q;
q_dot(i) = jointState[i].qdot;
q_dotdot(i) = jointState[i].qdotdot;
printf("q, qdot %f, %f\n", q(i), q_dot(i));
}
rneDynamics->CartToJnt(q, q_dot, q_dotdot, f_ext, torques);
for (unsigned int i = 0; i < achain.getNrOfJoints(); ++i)
{
printf("index, q, qdot, torques %d, %f, %f, %f\n", i, q(i), q_dot(i), torques(i));
}
return;
}
示例5:
ChainKinematics::ChainKinematics(const KDL::Chain chain, const double lambda) :
kinChain_(chain),
Njnt_(chain.getNrOfJoints()),
Nsegment_(chain.getNrOfSegments()) {
initialize(lambda);
}
示例6: idynChainGet_usingKDL_aux
KDL::Wrenches idynChainGet_usingKDL_aux(iCub::iDyn::iDynChain & idynChain, iCub::iDyn::iDynInvSensor & idynSensor,yarp::sig::Vector & ddp0)
{
yarp::sig::Vector q,dq,ddq;
q = idynChain.getAng();
dq = idynChain.getDAng();
ddq = idynChain.getD2Ang();
KDL::Chain kdlChain;
std::vector<std::string> la_joints;
la_joints.push_back("left_shoulder_pitch");
la_joints.push_back("left_shoulder_roll");
la_joints.push_back("left_arm_ft_sensor");
la_joints.push_back("left_shoulder_yaw");
la_joints.push_back("left_elbow");
la_joints.push_back("left_wrist_prosup");
la_joints.push_back("left_wrist_pitch");
la_joints.push_back("left_wrist_yaw");
idynSensorChain2kdlChain(idynChain,idynSensor,kdlChain,la_joints,la_joints);
std::cout << kdlChain << std::endl;
int nj = idynChain.getN();
//cout << "idynChainGet_usingKDL_aux with sensor" << " nrJoints " << kdlChain.getNrOfJoints() << " nrsegments " << kdlChain.getNrOfSegments() << endl;
assert(nj==kdlChain.getNrOfJoints());
assert(nj+1==kdlChain.getNrOfSegments());
KDL::JntArray jointpositions = KDL::JntArray(nj);
KDL::JntArray jointvel = KDL::JntArray(nj);
KDL::JntArray jointacc = KDL::JntArray(nj);
KDL::JntArray torques = KDL::JntArray(nj);
for(unsigned int i=0;i<nj;i++){
jointpositions(i)=q[i];
jointvel(i) = dq[i];
jointacc(i) = ddq[i];
}
KDL::Wrenches f_ext(nj+1);
KDL::Wrenches f_int(nj+1);
KDL::Vector grav_kdl;
idynVector2kdlVector(idynChain.getH0().submatrix(0,2,0,2).transposed()*ddp0,grav_kdl);
KDL::ChainIdSolver_RNE_IW neSolver = KDL::ChainIdSolver_RNE_IW(kdlChain,-grav_kdl);
int ret = neSolver.CartToJnt_and_internal_wrenches(jointpositions,jointvel,jointacc,f_ext,torques,f_int);
assert(ret >= 0);
return f_int;
}
示例7: getKDLChainInfo
void getKDLChainInfo(const KDL::Chain &chain,
kinematics_msgs::KinematicSolverInfo &chain_info)
{
int i=0; // segment number
while(i < (int)chain.getNrOfSegments())
{
chain_info.link_names.push_back(chain.getSegment(i).getName());
i++;
}
}
示例8: getKDLSegmentIndex
int Kinematics::getKDLSegmentIndex(const std::string &name) {
int i=0;
while (i < (int)chain.getNrOfSegments()) {
if (chain.getSegment(i).getName() == name) {
return i+1;
}
i++;
}
return -1;
}
示例9: getKDLSegmentIndex
int ExcavaROBArmKinematics::getKDLSegmentIndex(const std::string &name) {
int i=0;
while (i < (int) arm_chain_.getNrOfSegments()) {
if (arm_chain_.getSegment(i).getName() == name) {
return i + 1;
}
i++;
}
return -1;
}
示例10: init_message
sensor_msgs::JointState init_message(const KDL::Chain &chain) {
sensor_msgs::JointState msg;
for (unsigned int i=0; i < chain.getNrOfSegments(); ++i) {
KDL::Segment segment = chain.getSegment(i);
KDL::Joint joint = segment.getJoint();
if (joint.getType() == KDL::Joint::JointType::None) continue;
msg.name.push_back(joint.getName());
msg.position.push_back(0);
}
return msg;
}
示例11:
FkLookup::ChainFK::ChainFK(const KDL::Tree& tree, const std::string& root, const std::string& tip):root_name(root),tip_name(tip){
KDL::Chain chain;
tree.getChain(root_name, tip_name, chain);
solver = new KDL::ChainFkSolverPos_recursive(chain);
unsigned int num = chain.getNrOfSegments();
for(unsigned int i = 0; i < num; ++i){
const KDL::Joint &joint = chain.getSegment(i).getJoint();
if (joint.getType() != KDL::Joint::None) joints.insert(std::make_pair(joint.getName(),joints.size()));
}
ROS_ASSERT(joints.size() == chain.getNrOfJoints());
}
示例12: getSegmentIndex
bool leatherman::getSegmentIndex(const KDL::Chain &c, std::string name, int &index)
{
for(size_t j = 0; j < c.getNrOfSegments(); ++j)
{
if(c.getSegment(j).getName().compare(name) == 0)
{
index = j;
return true;
}
}
return false;
}
示例13: getPositionFK
bool ExcavaROBArmKinematics::getPositionFK(excavaROB_arm_kinematics_msgs::GetPositionFK::Request &request,
excavaROB_arm_kinematics_msgs::GetPositionFK::Response &response) {
KDL::Frame p_out;
KDL::JntArray jnt_pos_in;
geometry_msgs::PoseStamped pose;
tf::Stamped<tf::Pose> tf_pose;
if (num_joints_arm_ != request.fk_link_names.size()) {
ROS_ERROR("The request has not the same dimension of the arm_chain joints.");
return false;
}
jnt_pos_in.resize(num_joints_arm_);
for (unsigned int i = 0; i < num_joints_arm_; i++) {
int jnt_index = getJointIndex(request.joint_state.name[i]);
if (jnt_index >= 0)
jnt_pos_in(jnt_index) = request.joint_state.position[i];
}
response.pose_stamped.resize(num_joints_arm_);
response.fk_link_names.resize(num_joints_arm_);
bool valid = true;
for (unsigned int i = 0; i < num_joints_arm_; i++) {
int segmentIndex = getKDLSegmentIndex(request.fk_link_names[i]);
ROS_DEBUG("End effector index: %d", segmentIndex);
ROS_DEBUG("Chain indices: %d", arm_chain_.getNrOfSegments());
if (fk_solver_->JntToCart(jnt_pos_in, p_out, segmentIndex) >= 0) {
tf_pose.frame_id_ = root_name_;
tf_pose.stamp_ = ros::Time();
tf::PoseKDLToTF(p_out, tf_pose);
try {
tf_listener_.transformPose(request.header.frame_id, tf_pose, tf_pose);
} catch (...) {
ROS_ERROR("ExcavaROB Kinematics: Could not transform FK pose to frame: %s", request.header.frame_id.c_str());
response.error_code.val = response.error_code.FRAME_TRANSFORM_FAILURE;
return false;
}
tf::poseStampedTFToMsg(tf_pose, pose);
response.pose_stamped[i] = pose;
response.fk_link_names[i] = request.fk_link_names[i];
response.error_code.val = response.error_code.SUCCESS;
} else {
ROS_ERROR("ExcavaROB Kinematics: Could not compute FK for %s", request.fk_link_names[i].c_str());
response.error_code.val = response.error_code.NO_FK_SOLUTION;
valid = false;
}
}
return true;
}
示例14: getKDLSegmentIndex
int getKDLSegmentIndex(const KDL::Chain &chain,
const std::string &name)
{
int i=0; // segment number
while(i < (int)chain.getNrOfSegments())
{
if(chain.getSegment(i).getName() == name)
{
return i+1;
}
i++;
}
return -1;
}
示例15: initialize
bool OrientationConstraint::initialize(const arm_navigation_msgs::OrientationConstraint& constraint,
const KDL::Chain& chain)
{
constraint_ = constraint;
link_id_ = -1;
for (unsigned int i=0; i<chain.getNrOfSegments(); ++i)
{
if (constraint_.link_name == chain.getSegment(i).getName())
{
link_id_ = i;
break;
}
}
if (link_id_ == -1)
{
ROS_ERROR("OrientationConstraint: couldn't find link %s in chain.", constraint_.link_name.c_str());
return false;
}
return true;
}