本文整理汇总了C++中kdl::Chain类的典型用法代码示例。如果您正苦于以下问题:C++ Chain类的具体用法?C++ Chain怎么用?C++ Chain使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Chain类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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());
}
}
示例2:
ChainKinematics::ChainKinematics(const KDL::Chain chain, const double lambda) :
kinChain_(chain),
Njnt_(chain.getNrOfJoints()),
Nsegment_(chain.getNrOfSegments()) {
initialize(lambda);
}
示例3: 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;
}
示例4: Test
void RobotAlgos::Test(void)
{
//Definition of a kinematic chain & add segments to the chain
KDL::Chain chain;
chain.addSegment(Segment(Joint(Joint::RotZ),Frame(Vector(0.0,0.0,1.020))));
chain.addSegment(Segment(Joint(Joint::RotX),Frame(Vector(0.0,0.0,0.480))));
chain.addSegment(Segment(Joint(Joint::RotX),Frame(Vector(0.0,0.0,0.645))));
chain.addSegment(Segment(Joint(Joint::RotZ)));
chain.addSegment(Segment(Joint(Joint::RotX),Frame(Vector(0.0,0.0,0.120))));
chain.addSegment(Segment(Joint(Joint::RotZ)));
// Create solver based on kinematic chain
ChainFkSolverPos_recursive fksolver = ChainFkSolverPos_recursive(chain);
// Create joint array
unsigned int nj = chain.getNrOfJoints();
KDL::JntArray jointpositions = JntArray(nj);
// Assign some values to the joint positions
for(unsigned int i=0;i<nj;i++){
float myinput;
printf ("Enter the position of joint %i: ",i);
scanf ("%e",&myinput);
jointpositions(i)=(double)myinput;
}
// Create the frame that will contain the results
KDL::Frame cartpos;
// Calculate forward position kinematics
int kinematics_status;
kinematics_status = fksolver.JntToCart(jointpositions,cartpos);
if(kinematics_status>=0){
std::cout << cartpos <<std::endl;
printf("%s \n","Succes, thanks KDL!");
}else{
printf("%s \n","Error: could not calculate forward kinematics :(");
}
//Creation of the solvers:
ChainFkSolverPos_recursive fksolver1(chain);//Forward position solver
ChainIkSolverVel_pinv iksolver1v(chain);//Inverse velocity solver
ChainIkSolverPos_NR iksolver1(chain,fksolver1,iksolver1v,100,1e-6);//Maximum 100 iterations, stop at accuracy 1e-6
//Creation of jntarrays:
JntArray result(chain.getNrOfJoints());
JntArray q_init(chain.getNrOfJoints());
//Set destination frame
Frame F_dest=cartpos;
iksolver1.CartToJnt(q_init,F_dest,result);
for(unsigned int i=0;i<nj;i++){
printf ("Axle %i: %f \n",i,result(i));
}
}
示例5: 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++;
}
}
示例6: 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;
}
示例7:
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());
}
示例8: 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;
}
示例9: LWR_knife
KDL::Chain kukaControl::LWR_knife() {
KDL::Chain chain;
// base
chain.addSegment(
// KDL::Segment(KDL::Joint(KDL::Joint::None),KDL::Frame::DH_Craig1989(0, 0, 0.33989, 0)));
KDL::Segment(KDL::Joint(KDL::Joint::None),
KDL::Frame::DH_Craig1989(0, 0, 0.34, 0)));
// joint 1
chain.addSegment(
KDL::Segment(KDL::Joint(KDL::Joint::RotZ),
KDL::Frame::DH_Craig1989(0, -M_PI_2, 0, 0)));
// joint 2
chain.addSegment(
// KDL::Segment(KDL::Joint(KDL::Joint::RotZ),KDL::Frame::DH_Craig1989(0, M_PI_2, 0.40011, 0)));
KDL::Segment(KDL::Joint(KDL::Joint::RotZ),
KDL::Frame::DH_Craig1989(0, M_PI_2, 0.40, 0)));
// joint 3
chain.addSegment(
KDL::Segment(KDL::Joint(KDL::Joint::RotZ),
KDL::Frame::DH_Craig1989(0, M_PI_2, 0, 0)));
// joint 4
chain.addSegment(
KDL::Segment(KDL::Joint(KDL::Joint::RotZ),
KDL::Frame::DH_Craig1989(0, -M_PI_2, 0.4000, 0)));
// joint 5
chain.addSegment(
KDL::Segment(KDL::Joint(KDL::Joint::RotZ),
KDL::Frame::DH_Craig1989(0, -M_PI_2, 0, 0)));
// joint 6
chain.addSegment(
KDL::Segment(KDL::Joint(KDL::Joint::RotZ),
KDL::Frame::DH_Craig1989(0, M_PI_2, 0, 0)));
// joint 7 (with flange adapter)
/* chain.addSegment(
KDL::Segment(KDL::Joint(KDL::Joint::RotZ),
KDL::Frame::DH_Craig1989(0, 0, 0.12597, 0)));*/
// for HSC
chain.addSegment(
KDL::Segment(KDL::Joint(KDL::Joint::RotZ),
KDL::Frame::DH_Craig1989(0, 0, 0.12597 + 0.41275, 0)));
KDL::Frame ee = KDL::Frame(KDL::Vector(0.0625, -0.0925, -0.07))
* KDL::Frame(
KDL::Rotation::EulerZYX(32.0 * M_PI / 180, 0.0,
54.18 * M_PI / 180));
chain.addSegment(KDL::Segment(KDL::Joint(KDL::Joint::None), ee));
return chain;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}
示例13: ChainJntToJacSolver
TEST_F(PR2IKTest, SingleRowRotation)
{
YAML::Node node = YAML::LoadFile("pr2_left_arm_scope.yaml");
ASSERT_NO_THROW(node.as< giskard_core::ScopeSpec >());
giskard_core::ScopeSpec scope_spec = node.as<giskard_core::ScopeSpec>();
ASSERT_NO_THROW(giskard_core::generate(scope_spec));
giskard_core::Scope scope = giskard_core::generate(scope_spec);
ASSERT_TRUE(scope.has_double_expression("pr2_rot_x"));
KDL::Expression<double>::Ptr exp = scope.find_double_expression("pr2_rot_x");
ASSERT_TRUE(exp.get());
std::string base = "base_link";
std::string tip = "l_wrist_roll_link";
KDL::Chain chain;
ASSERT_TRUE(tree.getChain(base, tip, chain));
ASSERT_EQ(chain.getNrOfJoints(), exp->number_of_derivatives());
boost::shared_ptr<KDL::ChainJntToJacSolver> jac_solver;
jac_solver = boost::shared_ptr<KDL::ChainJntToJacSolver>(
new KDL::ChainJntToJacSolver(chain));
for(int i=-11; i<12; ++i)
{
std::vector<double> exp_in;
KDL::JntArray solver_in(exp->number_of_derivatives());
for(size_t j=0; j<exp->number_of_derivatives(); ++j)
{
double value = 0.1*i;
exp_in.push_back(value);
solver_in(j) = value;
}
exp->setInputValues(exp_in);
exp->value();
KDL::Jacobian solver_jac(chain.getNrOfJoints());
ASSERT_GE(jac_solver->JntToJac(solver_in, solver_jac), 0.0);
for (size_t j=0; j<chain.getNrOfJoints(); ++j)
EXPECT_NEAR(solver_jac(3,j), exp->derivative(j), KDL::epsilon);
}
}
示例14: LWR_HSC_nozzle_RCM_used
KDL::Chain kukaControl::LWR_HSC_nozzle_RCM_used() {
KDL::Chain chain;
// base
chain.addSegment(
// KDL::Segment(KDL::Joint(KDL::Joint::None),KDL::Frame::DH_Craig1989(0, 0, 0.33989, 0)));
KDL::Segment(KDL::Joint(KDL::Joint::None),
KDL::Frame::DH_Craig1989(0, 0, 0.34, 0)));
//KDL::Frame::DH_Craig1989(0, M_PI_2, 0.36, 0)));
// joint 1
chain.addSegment(
KDL::Segment(KDL::Joint(KDL::Joint::RotZ),
KDL::Frame::DH_Craig1989(0, -M_PI_2, 0, 0)));
// joint 2
chain.addSegment(
// KDL::Segment(KDL::Joint(KDL::Joint::RotZ),KDL::Frame::DH_Craig1989(0, M_PI_2, 0.40011, 0)));
KDL::Segment(KDL::Joint(KDL::Joint::RotZ),
KDL::Frame::DH_Craig1989(0, M_PI_2, 0.40, 0)));
//KDL::Frame::DH_Craig1989(0, M_PI_2, 0.42, 0)));
// joint 3
chain.addSegment(
KDL::Segment(KDL::Joint(KDL::Joint::RotZ),
KDL::Frame::DH_Craig1989(0, M_PI_2, 0, 0)));
// joint 4
chain.addSegment(
KDL::Segment(KDL::Joint(KDL::Joint::RotZ),
KDL::Frame::DH_Craig1989(0, -M_PI_2, 0.4000, 0)));
// joint 5
chain.addSegment(
KDL::Segment(KDL::Joint(KDL::Joint::RotZ),
KDL::Frame::DH_Craig1989(0, -M_PI_2, 0, 0)));
// joint 6
chain.addSegment(
KDL::Segment(KDL::Joint(KDL::Joint::RotZ),
KDL::Frame::DH_Craig1989(0, M_PI_2, 0, 0)));
// joint 7 (with flange adapter)
/* chain.addSegment(
KDL::Segment(KDL::Joint(KDL::Joint::RotZ),
KDL::Frame::DH_Craig1989(0, 0, 0.12597, 0)));*/
// for HSC
chain.addSegment(
KDL::Segment(KDL::Joint(KDL::Joint::RotZ),
KDL::Frame::DH_Craig1989(0, 0,
0.12597 + Dist_from_EndeffectorToRcmPoint, 0)));
return chain;
}
示例15: initInternals
void ArmKinematics::initInternals(const KDL::Chain& chain)
{
dof_ = chain.getNrOfJoints();
q_tmp_.resize(dof_);
deleteInternals();
fk_solver_ = new KDL::ChainFkSolverPos_recursive(chain);
ik_solver_ = new KDL::ChainIkSolverVel_wdls(chain);
}