Code for the Homework2
第二次作业,最近有点忙,一直没写,先发一下,关节角计算有点问题,后面抽时间改
#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的更多相关文章
- Code for the Homework2 改进
1. 实现了到指定点各个关节的转角计算(多解性),并且所求解满足各个关节的最大角和最小角的限制条件. 2. 对方向向量进行了单位化,保证任意大小的向量都行 #include<iostream&g ...
- Visual Studio Code 代理设置
Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器,在十多年的编程经历中,我使用过非常多的的代码编辑器(包括 IDE),例如 Fron ...
- 我们是怎么做Code Review的
前几天看了<Code Review 程序员的寄望与哀伤>,想到我们团队开展Code Review也有2年了,结果还算比较满意,有些经验应该可以和大家一起分享.探讨.我们为什么要推行Code ...
- Code Review 程序员的寄望与哀伤
一个程序员,他写完了代码,在测试环境通过了测试,然后他把它发布到了线上生产环境,但很快就发现在生产环境上出了问题,有潜在的 bug. 事后分析,是生产环境的一些微妙差异,使得这种 bug 场景在线下测 ...
- 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM
刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...
- 在Visual Studio Code中配置GO开发环境
一.GO语言安装 详情查看:GO语言下载.安装.配置 二.GoLang插件介绍 对于Visual Studio Code开发工具,有一款优秀的GoLang插件,它的主页为:https://github ...
- 代码的坏味道(14)——重复代码(Duplicate Code)
坏味道--重复代码(Duplicate Code) 重复代码堪称为代码坏味道之首.消除重复代码总是有利无害的. 特征 两个代码片段看上去几乎一样. 问题原因 重复代码通常发生在多个程序员同时在同一程序 ...
- http status code
属于转载 http status code:200:成功,服务器已成功处理了请求,通常这表示服务器提供了请求的网页 404:未找到,服务器未找到 201-206都表示服务器成功处理了请求的状态代码,说 ...
- Visual Studio Code——Angular2 Hello World 之 2.0
最近看到一篇用Visual Studio Code开发Angular2的文章,也是一篇入门教程,地址为:使用Visual Studio Code開發Angular 2專案.这里按部就班的做了一遍,感觉 ...
随机推荐
- [转]Ubuntu中无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用)
sudo apt-get install git E: 无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用) E: 无法锁定管理目录(/var/lib/dpkg/ ...
- Table of Contents - JAXB
Getting Started Hello World Hello World with Namespace xjc - 将 XML Schema 编译成 Java 类 wsimport: 编译 WS ...
- AIDL实现Android IPC
1.AIDL文本解释 在软件工程中,接口定义语言(IDL)已经成为通用术语,是用来描述软件组件接口的特定语言.在Android中,该IDL被称为Android接口定义语言(AIDL),它是纯文本文件, ...
- Android PullToRefresh下拉刷新控件的简单使用
PullToRefresh这个开源库早就听说了,不过一直没用过.作为一个经典的的开源库,我觉得还是有必要认识一下. 打开github上的网址:https://github.com/chrisbanes ...
- Android之布局
Android中的布局分为六种,分别是相对布局.线性布局.表格布局.网格布局.帧布局.绝对布局,良好的布局设计对UI界面至关重要,下面先来看看先相对布局. 相对布局(RelativeLayout): ...
- sqlserver2008 如何定时清理索引碎片
sqlserver2008 如何定时清理索引碎片 查询索引引起的表垃圾碎片sql脚本: SELECT object_name(a.object_id) [TableName] ,a.index_id ...
- NodeJs获取函数名称和函数操作整理
var aa = function () { log("xxxx"); }; aa(); var model = {}; model.test = function () { lo ...
- [zz] 使用ssh公钥密钥自动登陆linux服务器
目录 .生成密匙对 .拷贝公匙到远程机 .启动登陆代理 这种方法处理后每次需要运行命令:ssh-add ~/.ssh/id_dsa 作为一名 linux 管理员,在多台 Linux 服务器上登陆进行远 ...
- 09_rlCoachKin讲解
在Socket.cpp中Socket::readClient()函数中就是解析读取到的内容的. 对于我们发送的2 0 1.57 0.31 0 0 1.57 0,那么就会进入如下分支: 也就是进入2号处 ...
- nodejs remote链接mysql数据库总结
nodejs链接远端mysql,这个折腾了一个上午才搞定.本以为,直接使用就OK了,但是发现不行,后来查阅各种资料后,终于找到了方法. nodejs链接远端数据库主要分为几个步骤: 1)安装node- ...