第二次作业,最近有点忙,一直没写,先发一下,关节角计算有点问题,后面抽时间改

 #include<iostream>
 #include <Eigen/Dense>
 #include "Robot.h"
 using namespace Eigen;
 using namespace std;
  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();
      //cout<<180*atan2(sqrt(3),1)/PI<<endl;
      ;
  }

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;
             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<<"aa="<<fr.origin.x<<endl;
  ToJoint();
 }
 void Robot::ToJoint()
 {
    joint1.theta=acos(((pow(joint2.x,)+pow(joint2.y,))+(pow(length1,)-pow(length2,)))/(*length1*sqrt(pow(joint2.x,)+pow(joint2.y,))))+atan2(joint2.y,joint2.x);
    joint2.theta=acos(((pow(joint2.x,)+pow(joint2.y,))+(pow(length2,)-pow(length1,)))/(*length2*sqrt(pow(joint2.x,)+pow(joint2.y,))))+atan2(joint2.y,joint2.x);
 //   cout<<length1<<"  "<<length2<<endl;
 //   cout<<joint2.x<<"  "<<joint2.y<<endl;
 }

 void Robot::JointTo()
 {
    joint2.x=length1*cos(joint1.theta)+length2*cos(joint2.theta);
    joint2.x=length1*sin(joint1.theta)+length2*sin(joint2.theta);
 }
 void Robot::RobotShow(void){
     cout<</PI;
     cout<</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 for the Homework2 改进

    1. 实现了到指定点各个关节的转角计算(多解性),并且所求解满足各个关节的最大角和最小角的限制条件. 2. 对方向向量进行了单位化,保证任意大小的向量都行 #include<iostream&g ...

  2. Visual Studio Code 代理设置

    Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器,在十多年的编程经历中,我使用过非常多的的代码编辑器(包括 IDE),例如 Fron ...

  3. 我们是怎么做Code Review的

    前几天看了<Code Review 程序员的寄望与哀伤>,想到我们团队开展Code Review也有2年了,结果还算比较满意,有些经验应该可以和大家一起分享.探讨.我们为什么要推行Code ...

  4. Code Review 程序员的寄望与哀伤

    一个程序员,他写完了代码,在测试环境通过了测试,然后他把它发布到了线上生产环境,但很快就发现在生产环境上出了问题,有潜在的 bug. 事后分析,是生产环境的一些微妙差异,使得这种 bug 场景在线下测 ...

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

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

  6. 在Visual Studio Code中配置GO开发环境

    一.GO语言安装 详情查看:GO语言下载.安装.配置 二.GoLang插件介绍 对于Visual Studio Code开发工具,有一款优秀的GoLang插件,它的主页为:https://github ...

  7. 代码的坏味道(14)——重复代码(Duplicate Code)

    坏味道--重复代码(Duplicate Code) 重复代码堪称为代码坏味道之首.消除重复代码总是有利无害的. 特征 两个代码片段看上去几乎一样. 问题原因 重复代码通常发生在多个程序员同时在同一程序 ...

  8. http status code

    属于转载 http status code:200:成功,服务器已成功处理了请求,通常这表示服务器提供了请求的网页 404:未找到,服务器未找到 201-206都表示服务器成功处理了请求的状态代码,说 ...

  9. Visual Studio Code——Angular2 Hello World 之 2.0

    最近看到一篇用Visual Studio Code开发Angular2的文章,也是一篇入门教程,地址为:使用Visual Studio Code開發Angular 2專案.这里按部就班的做了一遍,感觉 ...

随机推荐

  1. [改善Java代码] 枚举项数量限定为64个以内

    建议89:枚举项的数量限制在64个以内 为了更好的使用枚举,java 提供了两个枚举集合:EnumSet和EnumMap,这两个集合的使用都比较简单,EnumSet表示其元素必须是某一枚举的枚举项,E ...

  2. java算法小知识练习(二)

    话不多说,直接上题: 题目:两个乒乓球队进行比赛,各出三人.甲队为a,b,c三人,乙队为x,y,z三人.已抽签决定比赛名单.   有人向队员打听比赛的名单.a说他不和x比,c说他不和x,z比,请编程序 ...

  3. Spring(3.2.3) - Beans(5): 集合属性的注入

    如果 Bean 的属性是个集合,则可以使用 <list/>.<set/>.<map/> 和 <props/> 元素向 List.Set.Map 和 Pr ...

  4. PetShop

    Microsoft .NET Pet Shop 4:将 ASP.NET 1.1 应用程序迁移到 2.0 发布日期: 2006-5-9 | 更新日期: 2006-5-9 适用于:Microsoft .N ...

  5. JSP之session

    index.jsp: <form id="form1" name="form1" method="post" action=" ...

  6. javascript笔记——点击按钮(或超链接)如何跳转到另外一个页面并执行目标页面的js函数

    页面跳转同时执行js代码$(function(){});url参数传递 标题的前半部分其实不必赘述,按钮也可以换成超链接.. 假设是需要在A页面上的一个按钮,点击后跳转到B页面,传一些参数后且并B页面 ...

  7. Js跳出循环

    break和 continue break 中断整个循环 continue 跳出当前循环,进入下一次循环 break示例: 例1: 例2: Continue:跳出当前循环,进入下一次循环 Break与 ...

  8. 第一节 Hibernate 基本配置

    1 新建maven工程 1)打开eclipse,依次点击File---->New---->Maven Project. 2)选择org.apache.maven.archetypes ma ...

  9. OCI下报出的数据库重账错

    [2014-01-09 19:43:45.469220][22347888] Level 0 COCITOOL: Error - OCI_ERROE - errcode[1],errmsg[ORA-0 ...

  10. centos7搭建NIS与NFS综合应用

    实验环境: centos7(服务端)        redhat enterprise linux 7.2(客户端) 实验目的:用centos7的账号,能在redhat enterprise linu ...