Commit 6ca10bd 1 parent 9533343 commit 6ca10bd Copy full SHA for 6ca10bd
File tree 1 file changed +202
-0
lines changed
1 file changed +202
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Point.h
2
+ 1 #ifndef Point_h
3
+ 2 #define Point_h
4
+ 3 class Point
5
+ 4 {
6
+ 5 private :
7
+ 6 double px,py;
8
+ 7 public :
9
+ 8
10
+ 9 double getpx ()
11
+ 10 {
12
+ 11 return px;
13
+ 12 }
14
+ 13 double getpy ()
15
+ 14 {
16
+ 15 return py;
17
+ 16 }
18
+ 17 void setp (double x, double y)
19
+ 18 {
20
+ 19 px=x;
21
+ 20 py=y;
22
+ 21 }
23
+ 22 };
24
+ 23 #endif
25
+
26
+ 复制代码
27
+ 复制代码
28
+
29
+ // Solver.h
30
+ 1 #ifndef Solver_h
31
+ 2 #define Solver_h
32
+ 3 #include <math.h>
33
+ 4 #include <iostream>
34
+ 5 #include" Point.h"
35
+ 6 using namespace std ;
36
+ 7 class Solver
37
+ 8 {
38
+ 9 private:
39
+ 10 double ang1,ang2;
40
+ 11 Point p;
41
+ 12 public:
42
+ 13
43
+ 14 void setp (Point p1)
44
+ 15 {
45
+ 16 p=p1;
46
+ 17 }
47
+ 18 void setang (double a1, double a2)
48
+ 19 {
49
+ 20 ang1=a1/180 *3.1415926 ;
50
+ 21 ang2=a2/180 *3.1416926 ;
51
+ 22 }
52
+ 23 void outang ()
53
+ 24 {
54
+ 25 cout<<" 第一机械臂的转角是" <<ang1/3.1415926 *180 <<endl;
55
+ 26 cout<<" 第二机械臂的转角是" <<ang2/3.1415926 *180 <<endl;
56
+ 27 }
57
+ 28 void outxy ()
58
+ 29 {
59
+ 30 cout<<" x坐标是" <<p.getpx ()<<endl;
60
+ 31 cout<<" y坐标是" <<p.getpy ()<<endl;
61
+ 32 }
62
+ 33 void angtdik ()
63
+ 34 {
64
+ 35 p.setp (100 *cos (ang1)+100 *cos (ang2),100 *sin (ang1)+100 *sin (ang2));
65
+ 36
66
+ 37 }
67
+ 38 void diktang ()
68
+ 39 {
69
+ 40 double sx=p.getpx ();
70
+ 41 double sy=p.getpy ();
71
+ 42 double q=atan (sy/sx);
72
+ 43 double l=sqrt (sx*sx+sy*sy);
73
+ 44 ang1=q+acos (-l/200 );
74
+ 45 ang2=acos ((l*l-20000 )/20000 )-3.1415926 -ang1;
75
+ 46 }
76
+ 47 };
77
+ 48 #endif
78
+
79
+ 复制代码
80
+ 复制代码
81
+
82
+ // Robot.h
83
+ #ifndef Robot_h
84
+ #define Robot_h
85
+ #include " Coord.h"
86
+ #include " Trans.h"
87
+ #include " Solver.h"
88
+ class Robot
89
+ {
90
+ private:
91
+ double l1,l2,rang1,rang2;
92
+ public:
93
+ Robot ()
94
+ {
95
+ l1=100 ;
96
+ l2=100 ;
97
+ rang1=0 ;
98
+ rang2=0 ;
99
+ }
100
+ void PTPmove (Coord c1,Point p)
101
+ {
102
+ Trans T;
103
+ Solver S;
104
+ Point p1;
105
+ p1=T.TTW (c1,p);
106
+ S.setp (p1);
107
+ S.diktang ();
108
+ S.outang ();
109
+
110
+ }
111
+ };
112
+ #endif
113
+
114
+ 复制代码
115
+ 复制代码
116
+
117
+ // Coord.h
118
+ #ifndef Coord_h
119
+ #define Coord_h
120
+ #include " Point.h"
121
+ class Coord
122
+ {
123
+ private :
124
+ Point p1;
125
+ double ang;
126
+ public :
127
+ /* Coord(Point p,double ang1)
128
+ {
129
+ p1=p;
130
+ ang=ang1;
131
+ }*/
132
+ void setcoord (Point p,double ang1 )
133
+ {
134
+ p1=p;
135
+ ang=ang1;
136
+ }
137
+ Point getp1 ()
138
+ {
139
+ return p1;
140
+ }
141
+ double getang ()
142
+ {
143
+ return ang/180 *3.1415926 ;
144
+ }
145
+ };
146
+ #endif
147
+
148
+ 复制代码
149
+ 复制代码
150
+
151
+ // Trans.h
152
+ #ifndef Trans_h
153
+ #define Trans_h
154
+ #include " Point.h"
155
+ #include " Coord.h"
156
+ #include < math.h>
157
+ class Trans
158
+ {
159
+ public :
160
+
161
+ Point TTW (Coord c1,Point p3)
162
+ {
163
+ Point p1=c1.getp1 ();
164
+ Point p2;
165
+ double ang=c1.getang ();
166
+ double x,y,x1,y1 ;
167
+ x=p3.getpx ();
168
+ y=p3.getpy ();
169
+ x1=x*cos (ang)-y*sin (ang)+p1.getpx ();
170
+ y1 =x*sin (ang)+y*cos (ang)+p1.getpy ();
171
+ p2.setp (x1,y1 );
172
+ return p2;
173
+ }
174
+
175
+ };
176
+ #endif
177
+
178
+ 复制代码
179
+ 复制代码
180
+
181
+ // main.cpp
182
+ #include < iostream>
183
+ #include " Point.h"
184
+ #include " Solver.h"
185
+ #include " Robot.h"
186
+ #include " Coord.h"
187
+ #include " Trans.h"
188
+ using namespace std ;
189
+ int main ()
190
+ {
191
+ Robot r;
192
+ Point p;
193
+ Point p1;
194
+ p.setp (30 ,20 );
195
+ p1.setp (40 ,60 );
196
+ Coord t;
197
+ t.setcoord (p,45 );
198
+ r.PTPmove (t,p1);
199
+ return 0 ;
200
+ }
201
+
202
+ 复制代码
You can’t perform that action at this time.
0 commit comments