Chinaunix首页 | 论坛 | 博客
  • 博客访问: 200779
  • 博文数量: 67
  • 博客积分: 375
  • 博客等级: 一等列兵
  • 技术积分: 525
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-29 22:28
文章分类

全部博文(67)

文章存档

2021年(2)

2019年(1)

2018年(19)

2017年(23)

2016年(4)

2011年(18)

我的朋友
KDL

分类: C/C++

2017-12-12 22:38:07

1. 下载
git clone https://github.com/orocos/orocos_kinematics_dynamics.git
2.进入orocos_kdl目录,创建build目录,进入build目录
3.cmake ..
4.make
5.sudo make install

------------------------------------正解------------------------------------------

点击(此处)折叠或打开

  1. // Copyright (C) 2007 Francois Cauwe <francois at cauwe dot org>
  2.  
  3. // This library is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU Lesser General Public
  5. // License as published by the Free Software Foundation; either
  6. // version 2.1 of the License, or (at your option) any later version.
  7.  
  8. #include <kdl/chain.hpp>
  9. #include <kdl/chainfksolver.hpp>
  10. #include <kdl/chainfksolverpos_recursive.hpp>
  11. #include <kdl/frames_io.hpp>
  12. #include <stdio.h>
  13. #include <iostream>
  14.  
  15. using namespace KDL;
  16.  
  17.  
  18. int main( int argc, char** argv )
  19. {
  20.     //Definition of a kinematic chain & add segments to the chain
  21.     KDL::Chain chain;
  22.     chain.addSegment(Segment(Joint(Joint::RotZ),Frame(Vector(0.0,0.0,1.020))));
  23.     chain.addSegment(Segment(Joint(Joint::RotX),Frame(Vector(0.0,0.0,0.480))));
  24.     chain.addSegment(Segment(Joint(Joint::RotX),Frame(Vector(0.0,0.0,0.645))));
  25.     chain.addSegment(Segment(Joint(Joint::RotZ)));
  26.     chain.addSegment(Segment(Joint(Joint::RotX),Frame(Vector(0.0,0.0,0.120))));
  27.     chain.addSegment(Segment(Joint(Joint::RotZ)));
  28.  
  29.     // Create solver based on kinematic chain
  30.     ChainFkSolverPos_recursive fksolver = ChainFkSolverPos_recursive(chain);
  31.  
  32.     // Create joint array
  33.     unsigned int nj = chain.getNrOfJoints();
  34.     KDL::JntArray jointpositions = JntArray(nj);
  35.  
  36.     // Assign some values to the joint positions
  37.     for(unsigned int i=0;i<nj;i++){
  38.         float myinput;
  39.         printf ("Enter the position of joint %i: ",i);
  40.         scanf ("%e",&myinput);
  41.         jointpositions(i)=(double)myinput;
  42.     }
  43.  
  44.     // Create the frame that will contain the results
  45.     KDL::Frame cartpos;
  46.  
  47.     // Calculate forward position kinematics
  48.     bool kinematics_status;
  49.     kinematics_status = fksolver.JntToCart(jointpositions,cartpos);
  50.     if(kinematics_status>=0){
  51.         std::cout << cartpos <<std::endl;
  52.         printf("%s \n","Succes, thanks KDL!");
  53.     }else{
  54.         printf("%s \n","Error: could not calculate forward kinematics :(");
  55.     }
  56. }

-----------------------------------------逆解-------------------------------------------

点击(此处)折叠或打开

  1. //Creation of the chain:
  2. KDL::Chain chain;
  3. chain.addSegment(Segment(Joint(Joint::RotZ),Frame(Vector(0.0,0.0,1.020))));
  4. chain.addSegment(Segment(Joint(Joint::RotX),Frame(Vector(0.0,0.0,0.480))));
  5. chain.addSegment(Segment(Joint(Joint::RotX),Frame(Vector(0.0,0.0,0.645))));
  6. chain.addSegment(Segment(Joint(Joint::RotZ)));
  7. chain.addSegment(Segment(Joint(Joint::RotX),Frame(Vector(0.0,0.0,0.120))));
  8. chain.addSegment(Segment(Joint(Joint::RotZ)));
  9.  
  10. //Creation of the solvers:
  11. ChainFkSolverPos_recursive fksolver1(chain1);//Forward position solver
  12. ChainIkSolverVel_pinv iksolver1v(chain1);//Inverse velocity solver
  13. ChainIkSolverPos_NR iksolver1(chain1,fksolver1,iksolver1v,100,1e-6);//Maximum 100 iterations, stop at accuracy 1e-6
  14.  
  15. //Creation of jntarrays:
  16. JntArray q(chain.getNrOfJoints());
  17. JntArray q_init(chain.getNrOfJoints());
  18.  
  19. //Set destination frame
  20. Frame F_dest=...;
  21.  
  22. int ret = iksolverpos.CartToJnt(q_init,F_dest,q);

阅读(1309) | 评论(0) | 转发(0) |
0

上一篇:EXCEL异或操作

下一篇:FCL

给主人留下些什么吧!~~