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

 #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. hdu 1358 KMP的next数据运用

    由于next[i]保存的是前i-1个字符中最大的重复子序列,那么i-next[i]就是循环节. #include<cstdio> #include<cstring> #incl ...

  2. hdu 2852 树状数组

    思路:加一个数e就用update(e,1).删除元素e就用update(e,-1).找比a大的第k大的元素就用二分查找. #include<iostream> #include<cs ...

  3. 蒋金楠How ASP.NET MVC Works?[持续更新中…]

    一.ASP.NET + MVC IIS与ASP.NET管道 MVC.MVP以及Model2[上篇]  MVC.MVP以及Model2[下篇] ASP.NET MVC是如何运行的[1]: 建立在“伪”M ...

  4. 导出Private API

    首先介绍下private API 它共分为两类: 1 在官方文档中没有呈现的API(在frameworks 下隐藏) 2 苹果明确申明不能使用的API ,在privateFrameworks 下 然后 ...

  5. Objective-C中一个方法如何传递多个参数的理解

    原来如此 Objective-C语法中多参数传递方法经常是初学者最容易犯困的地方.我自己也是刚刚悟出来与大家分享. 分析 由于我们已有的语言经验告诉我们定义方法都是: 一个类型匹配一个参数(动态语言甚 ...

  6. 【Android学习】尺寸单位 px in mm pt dp sp

    一.Android中支持的尺寸单位 下面用表格的方式将Android中支持的尺寸单位列举,供大家参考: Android的尺寸单位  单位表示  单位名称  单位说明  px  像素  屏幕上的真实像素 ...

  7. 搜索本地网络内所有可用的SQl实例

    '搜索本地网络内所有可用的SQl实例 Dim instance As SqlDataSourceEnumerator = SqlDataSourceEnumerator.Instance Dim dt ...

  8. Objective-C 【内存管理&手动内存管理 综述】

    ------------------------------------------- 内存管理 (1)Objective-C的内存管理 栈区    存放局部变量(由于基本数据类型占用的存储空间是固定 ...

  9. ATL一:CWindowImpl

    1,#ifdef _ATL_DISABLE_NO_VTABLE#define ATL_NO_VTABLE#else#define ATL_NO_VTABLE __declspec(novtable)# ...

  10. [转]C#发送Email邮件 (实例:QQ邮箱和Gmail邮箱)

    下面用到的邮件账号和密码都不是真实的,需要测试就换成自己的邮件账号. 需要引用:using System.Net.Mail;using System.Text;using System.Net; 程序 ...