1. 实现了到指定点各个关节的转角计算(多解性),并且所求解满足各个关节的最大角和最小角的限制条件。

2. 对方向向量进行了单位化,保证任意大小的向量都行

 #include<iostream>
 #include <Eigen/Dense>
 #include "Robot.h"

  int main(){
      ,l2 =;
      Vector2d JF_vx(,),JF_vy(,);
      Vector2d WF_vx(,),WF_vy(,);
      POINT jf_origin(,),wf_origin(,);
      Joint jt1(,,,-,,),jt2(l1,,,-,,);
      Frame JF("jf",JF_vx,JF_vy,jf_origin),WF("jf",WF_vx,WF_vy,wf_origin);
      Robot myRobot(l1,l2,jt1,jt2,JF,WF);
      POINT tf1_origin(,),tf2_origin(,),tf3_origin(,);
      Vector2d TF1_vx(,),TF1_vy(-,),TF2_vx(-,),TF2_vy(,-),TF3_vx(,-),TF3_vy(,);
      Frame TF1("tf1",TF1_vx,TF1_vy,tf1_origin),TF2("tf2",TF2_vx,TF2_vy,tf2_origin),TF3("tf3",TF3_vx,TF3_vy,tf3_origin);
      myRobot.TaskFrameCreate(TF1);
      myRobot.TaskFrameCreate(TF2);
      myRobot.TaskFrameCreate(TF3);
      POINT P1(,),P2(,),P3(,),P4(,),P5(,);
      myRobot.PTPMove(JF,P1);
  //    myRobot.RobotShow();
      myRobot.PTPMove(WF,P2);
  //    myRobot.RobotShow();
      myRobot.PTPMove(TF1,P3);
  //    myRobot.RobotShow();
      myRobot.PTPMove(TF2,P4);
  //    myRobot.RobotShow();
      myRobot.PTPMove(TF3,P5);
  //    myRobot.RobotShow();
      ;
  }

main.cpp

 #include<iostream>
 #include <Eigen/Dense>
 #include<vector>
 using namespace Eigen;
 using namespace std;
 #define PI 3.141592653
  class POINT
 {
     public:
         double x, y;
         string name;
         POINT(){
         };
         POINT(double xx,double yy){
             x=xx;
             y=yy;
         };
         POINT(string nam,double xx,double yy){
             name=nam;
             x=xx;
             y=yy;
         }
         POINT(const POINT &p){
             name=p.name;
             x=p.x;
             y=p.y;
         }
         POINT operator =(const POINT &pt)
         {
             POINT ptt(pt);
             return ptt;
         }
         void copyto(POINT &p);
         void get_cin_point(void);
         void display();
         void rotate(double &angle);
         void move(Vector2d &vec);
 };
 class Frame
 {
     public:
         string name;
         Vector2d vector_X;
         Vector2d vector_Y;
         POINT origin;
         Frame(){
         }
         Frame(string nam,Vector2d &vx,Vector2d &vy,POINT &oripoint)
         {
             name=nam;
             ],)+pow(vx[],));  //化为单位方向向量
             vx[]=vx[]/a;
             vx[]=vx[]/a;
             ],)+pow(vy[],));  //化为单位方向向量
             vy[]=vy[]/a;
             vy[]=vy[]/a;
             vector_X=vx;
             vector_Y=vy;
             //origin=oripoint;
             oripoint.copyto(origin);
         }
         Frame(const Frame &fr)
         {
             name=fr.name;
             vector_X=fr.vector_X;
             vector_Y=fr.vector_Y;
             origin=fr.origin;
         }
         Frame operator =(const Frame &fr)
         {
             Frame fra(fr);
             return fra;
         }
 };
 class Joint
 {
     public:
     double x,y,theta;
     double thetamin,thetamax,thetazero;
     Joint(){
     }
     Joint(double xx,double yy,double thetaa,double thetaminn,double thetamaxx,double thetazeroo)
     {
         x=xx;
         y=yy;
         theta=thetaa;
         thetamin=thetaminn;
         thetamax=thetamaxx;
         thetazero=thetazeroo;
     }
     CopyTo(Joint &jt)
     {
         jt.x=x;
         jt.y=y;
         jt.theta=theta;
         jt.thetamin=thetamin;
         jt.thetamax=thetamax;
         jt.thetazero=thetazero;
     }
 };
 class Robot
 {
    public:
         double length1,length2;
         Joint joint1,joint2;
         Frame JointFrame,WorldFrame;
         vector<Frame> fv;
         Robot(){
         }
         Robot(double l1,double l2,Joint jt1,Joint jt2,Frame JF,Frame WF)
         {
               length1=l1;
               length2=l2;
             jt1.CopyTo(joint1);
             jt2.CopyTo(joint2);
             JointFrame=JF;
             WorldFrame=WF;
         }
         void TaskFrameCreate(const Frame &tf);
         void PTPMove(const Frame &fr,const POINT &pt);
         void RobotShow(void);
         void ToJoint();
          void JointTo();
  };
 // class Solver
 // {
 //     public:
 //         //friend void PTPMove(Frame &fr,POINT &pt);
 //         void ToJoint(Robot &myrobot);
 //         void JointTo(Robot &myrobot);
 // };

Robot.h

 #include "Robot.h"
 #include "math.h"
 void Robot::TaskFrameCreate(const Frame &tf)
 {
     fv.push_back(tf);
 }
 void Robot::PTPMove(const Frame &fr,const POINT &pt)
 {
  ],fr.vector_X[]);
  joint2.x=fr.origin.x+pt.x*cos(theta)-pt.y*sin(theta);
  joint2.y=fr.origin.y+pt.x*sin(theta)+pt.y*cos(theta);
  cout<<"末端关节坐标("<<joint2.x<<","<<joint2.y<<")"<<endl;
  ToJoint();
 }
 void Robot::ToJoint()
 {
     double t1,t2;
     ]={false};
     bool flag1=false;
     ][];
     ;
     )+pow(joint2.y,))+(pow(length1,)-pow(length2,)))/(*length1*sqrt(pow(joint2.x,)+pow(joint2.y,)));
     |a>) flag1=false;
     else{                               //多解性
         t1=acos(a);//acos默认取值 0~PI
         t2=atan2(joint2.y,joint2.x);
         theta[][]=t1+t2;
         ][]*/PI<joint1.thetamax&theta[][]*/PI>joint1.thetamin){
             theta[][]=atan2(joint2.y-length1*sin(theta[][]),joint2.x-length1*cos(theta[][]));
             ][]*/PI<joint2.thetamax&theta[][]*/PI>joint2.thetamin){
                 ][])-length2*cos(theta[][]))<][])-length2*sin(theta[][]))<0.01)
                 {
                   flag[]=true;
                 }
             }
         }
         theta[][]=-t1+t2;
         ][]*/PI<joint1.thetamax&theta[][]*/PI>joint1.thetamin){
             theta[][]=atan2(joint2.y-length1*sin(theta[][]),joint2.x-length1*cos(theta[][]));
             ][]*/PI<joint2.thetamax&theta[][]*/PI>joint2.thetamin){
                 ][])-length2*cos(theta[][]))<][])-length2*sin(theta[][]))<0.01)
                 {
                     flag[]=true;
                 }
             }
         }
         theta[][]=t1-t2;
         ][]*/PI<joint1.thetamax&theta[][]*/PI>joint1.thetamin){
             theta[][]=atan2(joint2.y-length1*sin(theta[][]),joint2.x-length1*cos(theta[][]));
             ][]*/PI<joint2.thetamax&theta[][]*/PI>joint2.thetamin){
                 ][])-length2*cos(theta[][]))<][])-length2*sin(theta[][]))<0.01)
                 {
                   flag[]=true;
                 }
             }
         }
         theta[][]=-t1-t2;
         ][]*/PI<joint1.thetamax&theta[][]*/PI>joint1.thetamin){
             theta[][]=atan2(joint2.y-length1*sin(theta[][]),joint2.x-length1*cos(theta[][]));
             ][]*/PI<joint2.thetamax&theta[][]*/PI>joint2.thetamin){
                 ][])-length2*cos(theta[][]))<][])-length2*sin(theta[][]))<0.01)
                 {
                   flag[]=true;
                 }
             }
         }
         ;i<;i++)
         {
             if(flag[i]==true) {
                 flag1=true;
                 cnt++;
                 joint1.theta=theta[i][];
                 joint2.theta=theta[i][];
                 cout<<"第"<<cnt<<"种解为:";
                 cout<<]*/PI;
                 cout<<]*/PI<<endl;
             }
         }
     }

     if(flag1==false) cout<<"无法达到指定位置"<<endl;
 }

 void Robot::JointTo()
 {
    joint2.x=length1*cos(joint1.theta)+length2*cos(joint2.theta);
    joint2.y=length1*sin(joint1.theta)+length2*sin(joint2.theta);
 }
 void Robot::RobotShow(void){
 //    cout<<"关节1转角"<< joint1.theta*180/PI;
 //    cout<<"关节2转角"<< joint2.theta*180/PI;
 //    cout<<"末端关节坐标("<<joint2.x<<","<<joint2.y<<")"<<endl;
 }
 void POINT::copyto(POINT &p){
     p.name=name;
     p.x=x;
     p.y=y;
 }

Robot.cpp

Code for the Homework2 改进的更多相关文章

  1. Code alignment 代码对齐改进(VS2017)

    In mathematics you always keep your equals lined up directly underneath the one above. It keeps it c ...

  2. Code for the Homework2

    第二次作业,最近有点忙,一直没写,先发一下,关节角计算有点问题,后面抽时间改 #include<iostream> #include <Eigen/Dense> #includ ...

  3. Code for the Homework1 改进

    #include <iostream> #include <vector> #include "shape.h" //using namespace std ...

  4. PHP5.4最新特性

     PHP5.4最新特性   官网:ChangeLog-5.php#5.4.0 原文Oracle:LAMP 体系有了新的竞争,但此版本中的特性使 PHP 再次挑战极限. 稍微做了修改.: 概述总结:1. ...

  5. 《精通python网络爬虫》笔记

    <精通python网络爬虫>韦玮 著 目录结构 第一章 什么是网络爬虫 第二章 爬虫技能概览 第三章 爬虫实现原理与实现技术 第四章 Urllib库与URLError异常处理 第五章 正则 ...

  6. iOS开发 - 开发版+企业版无线发布一键打包

    背景:项目进入快速迭代期,需要快速地交付出AdHoc版本和企业无线发布版本.每次打包都要来回切换bundle identifier和code signing,浪费很多时间. 示例项目名称名称为Test ...

  7. 3D-camera结构光原理

    3D-camera结构光原理 目前主流的深度探测技术是结构光,TOF,和双目.具体的百度就有很详细的信息. 而结构光也有双目结构光和散斑结构光等,没错,Iphone X 的3D深度相机就用 散斑结构光 ...

  8. 算法所产生的性能改进已经超过了硬件所带来的性能提升 The future is algorithms, not code

    w 大数据的发展,伴随的将是软件工程师的渐退,算法工程师的崛起  http://mp.weixin.qq.com/s/XTz2HnzwlgTD3g5zU2u5Tg

  9. 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM

    刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...

随机推荐

  1. VM虚拟机下centos7 无法上网的问题解决办法

    博主本着学无止境的精神在虚拟机上安装了一个centos7 来敲敲命令行.刚开始就遇到了强大的阻力... ifconfig   vim  都没法用.这怎么行,安装呗.又学了圈安装,yum命令. 结果yu ...

  2. 通过Jquery中Ajax获取json文件数据

    1. JSON(JavaScript Object Notation): javaScript对象表示法: 是存储和交换文本信息的语法,比xml更小,更快,更易解析. 2. JSON基本书写格式 : ...

  3. Linux 命令 - arp: 操作系统的 ARP 缓存

    arp 命令可以查看 ARP 缓存或者手动添加.删除缓存中的条目. 命令格式 arp [-evn] [-H type] [-i if] -a [hostname] arp [-v] [-i if] - ...

  4. SQL中PERSISTED关键字

    PERSISTED 指定 SQL Server 数据库引擎将在表中物理存储计算值,而且,当计算列依赖的任何其他列发生更新时对这些计算值进行更新.将计算列标记为 PERSISTED,可允许您对具有确定性 ...

  5. 感受函数式编程-scala

    /** * Created by jx_luo on 2015/3/18. */object test03 { def main(Args:Array[String]): Unit ={ val st ...

  6. JS判断移动设备最佳方法

    最实用的还是下面这个: 方法一:纯JS判断 使用这方法既简单,又实用,不需要引入jQuery库,把以下代码加入到<head>里即可. <script type=”text/javas ...

  7. javascript 笔记——bind 用法小技巧

    $(function(){ //代码阅读能力 function speak(name){ return "Hello " + name; } //此处写代码 //方法一 //重点是 ...

  8. Java的导入与导出Excel

    使用Jakarta POI导入.导出Excel Jakarta POI 是一套用于访问微软格式文档的Java API.Jakarta POI有很多组件组成,其中有用于操作Excel格式文件的HSSF和 ...

  9. FKCL-OS——自主的操作系统

    我想搞一个操作系统,这是因为我对windows非常不满意,对linux非常讨厌,我想要开发一个真正自己的OS,然后让自己和别人使用它.得到方便.我将在这篇文章中写下我对操作系统的不满,然后构思出我的操 ...

  10. UVaOJ 120 - Stacks of Flapjacks

    120 - Stacks of Flapjacks 题目看了半天......英语啊!!! 好久没做题...循环输入数字都搞了半天...罪过啊!!! 还是C方便一点...其实C++应该更方便的...C+ ...