The second programming exercise of real-time control software design

Source: Internet
Author: User
Tags acos

//point.h
1 #ifndef Point_h2 #definePoint_h3 class Point4 {5 Private :6 Doublepx,py;7 Public :8 9 Doublegetpx ()Ten { One returnpx; A } - Doublegetpy () - { the returnpy; - } - voidSETP (DoubleXDoubley) - { +px=x; -py=y; + } A }; at #endif
//solver.h
1 #ifndef Solver_h2 #defineSolver_h3#include <math.h>4#include <iostream>5#include"Point.h"6 using namespacestd;7 classSolver8 {9 Private:Ten Doubleang1,ang2; One Point p; A Public: - - voidSetp (point p1) the { -p=P1; - } - voidSetang (DoubleA1,DoubleA2) + { -ang1=a1/ the*3.1415926; +ang2=a2/ the*3.1416926; A } at voidOutang () - { -cout<<"the corner of the first manipulator is"<<ang1/3.1415926* the<<Endl; -cout<<"the corner of the second manipulator is"<<ang2/3.1415926* the<<Endl; - } - voidOutxy () in { -cout<<"The x-coordinate is"&LT;&LT;P.GETPX () <<Endl; tocout<<"the y-coordinate is"<<p.getpy () <<Endl; + } - voidAngtdik () the { *P.SETP ( -*cos (ANG1) + -*cos (ANG2), -*sin (ANG1) + -*sin (ang2)); $ Panax Notoginseng } - voidDiktang () the { + Doublesx=p.getpx (); A Doublesy=p.getpy (); the DoubleQ=atan (sy/SX); + DoubleL=SQRT (sx*sx+sy*sy); -Ang1=q+acos (-l/ $); $Ang2=acos ((l*l-20000)/20000)-3.1415926-ang1; $ } - }; - #endif
//robot.h
#ifndef Robot_h#defineRobot_h#include"Coord.h"#include"Trans.h"#include"Solver.h"classrobot{Private: Doublel1,l2,rang1,rang2; Public: Robot () {L1= -; L2= -; Rang1=0; Rang2=0; } voidptpmove (Coord c1,point p) {Trans T; Solver S; Point P1; P1=T.TTW (c1,p); S.setp (p1); S.diktang (); S.outang (); }};#endif
//coord.h
#ifndef Coord_h#defineCoord_h#include"Point.h"classcoord{Private: Point P1; Doubleang; Public : /*Coord (Point p,double ang1) {p1=p; Ang=ang1; }*/ voidSetcoord (Point P,Doubleang1) {P1=p; Ang=ang1; } point Getp1 () {returnP1; } DoubleGetang () {returnang/ the*3.1415926; }};#endif
//trans.h
#ifndef Trans_h
#define Trans_h
#include "Point.h"
#include "Coord.h"
#include <math.h>
Class Trans
{
Public:

Point TTW (Coord c1,point p3)
{
Point P1=C1.GETP1 ();
Point P2;
Double Ang=c1.getang ();
Double x,y,x1,y1;
X=P3.GETPX ();
Y=p3.getpy ();
X1=x*cos (ANG)-y*sin (ANG) +p1.getpx ();
Y1=x*sin (ANG) +y*cos (ANG) +p1.getpy ();
P2.SETP (X1,Y1);
return p2;
}

};
#endif
Main.cpp
#include <iostream>#include"Point.h"#include"Solver.h"#include"Robot.h"#include"Coord.h"#include"Trans.h" using namespacestd;intMain () {Robot R; Point P; Point P1; P.SETP ( -, -); P1.SETP ( +, -); Coord T; T.setcoord (P, $); R.ptpmove (T,P1); return 0;}

Operation Result:

The second programming exercise of real-time control software design

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.