RoboDK Plug-In Interface
robodktypes.h
1 #ifndef ROBODKTYPES_H
2 #define ROBODKTYPES_H
3
4
5 #include
6 #include
7 #include
8
9
10 #ifndef M_PI
11 #define M_PI 3.14159265358979323846264338327950288
12 #endif
13
14
15 class IItem;
16 class IRoboDK;
17 typedef IItem*Item;
18 typedef IRoboDK RoboDK;
19
20
21
22
24 #define RDK_SIZE_JOINTS_MAX 12
25 // IMPORTANT!! Do not change this value
26
28 #define RDK_SIZE_MAX_CONFIG 4
29 // IMPORTANT!! Do not change this value
30.
31
36 typedef doubletXYZWPR[6];
37
39 typedef doubletXYZ[3];
40
41
56 typedef doubletConfig[RDK_SIZE_MAX_CONFIG];
57
58
59
61 #define DOT(v,q) ((v)[0]*(q)[0] + (v)[1]*(q)[1] + (v)[2]*(q)[2])
62
64 #define NORM(v) (sqrt((v)[0]*(v)[0] + (v)[1]*(v)[1] + (v)[2]*(v)[2]))
65
67 #define NORMALIZE(inout){\
68 double norm;\
69 norm = sqrt((inout)[0]*(inout)[0] + (inout)[1]*(inout)[1] + (inout)[2]*(inout)[2]);\
70 (inout)[0] = (inout)[0]/norm;\
71 (inout)[1] = (inout)[1]/norm;\
72 (inout)[2] = (inout)[2]/norm;}
73
75 #define CROSS(out,a,b) \
76 (out)[0] = (a)[1]*(b)[2] - (b)[1]*(a)[2]; \
77 (出)[1]= (a) (b) [2] * [0] - (b)[2] *[0](一个);\
78 (out)[2] = (a)[0]*(b)[1] - (b)[0]*(a)[1];
79
81 #define COPY3(out,in)\
82 (out)[0]=(in)[0];\
83 (out)[1]=(in)[1];\
84 (out)[2]=(in)[2];
85
87 #define MULT_MAT(out,inA,inB)\
88 (out)[0] = (inA)[0]*(inB)[0] + (inA)[4]*(inB)[1] + (inA)[8]*(inB)[2];\
89 (out)[1] = (inA)[1]*(inB)[0] + (inA)[5]*(inB)[1] + (inA)[9]*(inB)[2];\
90 (out)[2] = (inA)[2]*(inB)[0] + (inA)[6]*(inB)[1] + (inA)[10]*(inB)[2];\
91 (out)[3] = 0;\
92 (out)[4] = (inA)[0]*(inB)[4] + (inA)[4]*(inB)[5] + (inA)[8]*(inB)[6];\
93 (out)[5] = (inA)[1]*(inB)[4] + (inA)[5]*(inB)[5] + (inA)[9]*(inB)[6];\
94 (out)[6] = (inA)[2]*(inB)[4] + (inA)[6]*(inB)[5] + (inA)[10]*(inB)[6];\
95 (out)[7] = 0;\
96 (out)[8] = (inA)[0]*(inB)[8] + (inA)[4]*(inB)[9] + (inA)[8]*(inB)[10];\
97 (out)[9] = (inA)[1]*(inB)[8] + (inA)[5]*(inB)[9] + (inA)[9]*(inB)[10];\
98 (out)[10] = (inA)[2]*(inB)[8] + (inA)[6]*(inB)[9] + (inA)[10]*(inB)[10];\
99 (out)[11] = 0;\
100 (out)[12] = (inA)[0]*(inB)[12] + (inA)[4]*(inB)[13] + (inA)[8]*(inB)[14] + (inA)[12];\
101 (out)[13] = (inA)[1]*(inB)[12] + (inA)[5]*(inB)[13] + (inA)[9]*(inB)[14] + (inA)[13];\
102 (out)[14] = (inA)[2]*(inB)[12] + (inA)[6]*(inB)[13] + (inA)[10]*(inB)[14] + (inA)[14];\
103 (out)[15] = 1;
104
106 #define MULT_MAT_VECTOR(out,H,p)\
107 (out)[0] = (H)[0]*(p)[0] + (H)[4]*(p)[1] + (H)[8]*(p)[2];\
108 (out)[1] = (H)[1]*(p)[0] + (H)[5]*(p)[1] + (H)[9]*(p)[2];\
109 (out)[2] = (H)[2]*(p)[0] + (H)[6]*(p)[1] + (H)[10]*(p)[2];
110
112 #define MULT_MAT_POINT(out,H,p)\
113 (out)[0] = (H)[0]*(p)[0] + (H)[4]*(p)[1] + (H)[8]*(p)[2] + (H)[12];\
114 (out)[1] = (H)[1]*(p)[0] + (H)[5]*(p)[1] + (H)[9]*(p)[2] + (H)[13];\
115 (out)[2] = (H)[2]*(p)[0] + (H)[6]*(p)[1] + (H)[10]*(p)[2] + (H)[14];
116
117
118
120 struct tColor{
122 float r;
123
125 float g;
126
128 float b;
129
131 float a;
132};
133
134
135
136
137
138
139 //------------------------------------------------------------------------------------------------------------
140
141
142
145 struct tMatrix2D{
147 double*data;
148
150 int*size;
151
154
157
158 boolcanFreeData;
159};
160
161
162
163
164 // -------------------------------------------
165
166
169 tMatrix2D* Matrix2D_Create();
170
173 voidMatrix2D_Delete(tMatrix2D**mat);
174
179 voidMatrix2D_Set_Size(tMatrix2D*mat,introws,intcols);
180
184 intMatrix2D_Size(const tMatrix2D*mat,intdim);
185
189 intMatrix2D_Get_ncols(const tMatrix2D*var);
190
194 intMatrix2D_Get_nrows(const tMatrix2D*var);
195
199 doubleMatrix2D_Get_ij(const tMatrix2D*var,inti,intj);
200
206 voidMatrix2D_Set_ij(const tMatrix2D*var,inti,intj,doublevalue);
207
213 double* Matrix2D_Get_col(const tMatrix2D*var,intcol);
214
216 boolMatrix2D_Copy(const tMatrix2D*in,tMatrix2D*out);
217
220 voidDebug_Array(const double*array,intarraysize);
221
224 voidDebug_Matrix2D(const tMatrix2D*mat);
225
227 voidMatrix2D_Save(QDataStream *st,tMatrix2D*emx);
228
230 voidMatrix2D_Save(QTextStream *st,tMatrix2D*emx,boolcsv=false);
231
233 voidMatrix2D_Load(QDataStream *st,tMatrix2D**emx);
234
235
236 //--------------------- Joints class -----------------------
237
239 class tJoints{
240
241 public:
244 tJoints(intndofs = 0);
245
249 tJoints(const double*joints,intndofs = 0);
250
254 tJoints(const float*joints,intndofs = 0);
255
258 tJoints(const tJoints&jnts);
259
264 tJoints(const tMatrix2D*mat2d,intcolumn=0,intndofs=-1);
265
268 tJoints(constQString &str);
269
271 operatorQString()const{return ToString(); }
272
275 const double*ValuesD()const;
276
279 const float*ValuesF()const;
280
281 #ifdef ROBODK_API_FLOATS
284 const float*Values()const;
285 #else
288 const double*Values()const;
289 #endif
290
291
292
293 doubleCompare(const tJoints&other)const;
294
297 double*Data();
298
30.1 int Length()const;
30.2
30.4 void setLength(intnew_length);
30.5
30.9 bool Valid();
310
314 int GetValues(double*joints);
315
319 void SetValues(const double*joints,intndofs = -1);
320
324 void SetValues(const float*joints,intndofs = -1);
325
330QStringToString(constQString &separator=", ",intprecision = 3)const;
331
335 bool FromString(constQString &str);
336
337
338 public:
340 int _nDOFs;
341
343 double _Values[RDK_SIZE_JOINTS_MAX];
344
346 float _ValuesF[RDK_SIZE_JOINTS_MAX];
347};
348
349
350
351
361 class Mat:publicQMatrix4x4 {
362
363 public:
364
366 Mat();
367
369 Mat(boolvalid);
370
372 Mat(constQMatrix4x4 &matrix);
373
376 Mat(const Mat&matrix);
377
398 Mat(doublenx,doubleox,doubleax,doubletx,doubleny,doubleoy,doubleay,doublety,doublenz,doubleoz,doubleaz,doubletz);
399
407 Mat(const doublevalues[16]);
408
417 Mat(const floatvalues[16]);
418
432 Mat(doublex,doubley,doublez);
433
434 ~Mat();
435
437 operatorQString()const{return ToString(); }
438
440 void setVX(doublex,doubley,doublez);
441
443 void setVY(doublex,doubley,doublez);
444
446 void setVZ(doublex,doubley,doublez);
447
449 void setPos(doublex,doubley,doublez);
450
452 void setVX(doublexyz[3]);
453
455 void setVY(doublexyz[3]);
456
458 void setVZ(doublexyz[3]);
459
461 void setPos(doublexyz[3]);
462
464 void setValues(doublepose[16]);
465
467 void VX(tXYZ xyz)const;
468
470 void VY(tXYZ xyz)const;
471
473 void VZ(tXYZ xyz)const;
474
476 void Pos(tXYZ xyz)const;
477
482 void Set(intr,intc,doublevalue);
483
488 double Get(intr,intc)const;
489
491 Mat inv()const;
492
494 bool isHomogeneous()const;
495
497 bool MakeHomogeneous();
498
499 //------ Pose to xyzrpw and xyzrpw to pose------------
500
507 void ToXYZRPW(tXYZWPR xyzwpr)const;
508
514QStringToString(constQString &separator=", ",intprecision = 3,boolxyzrpw_only =false)const;
515
517 bool FromString(constQString &str);
518
526 void FromXYZRPW(tXYZWPR xyzwpr);
527
535 static Mat XYZRPW_2_Mat(doublex,doubley,doublez,doubler,doublep,doublew);
536 static Mat XYZRPW_2_Mat(tXYZWPR xyzwpr);
537
539 const double*ValuesD()const;
540
542 const float*ValuesF()const;
543
544 #ifdef ROBODK_API_FLOATS
546 const float*Values()const;
547 #else
549 const double*Values()const;
550 #endif
551
553 void Values(doublevalues[16])const;
554
556 void Values(floatvalues[16])const;
557
559 bool Valid()const;
560
574 static Mat transl(doublex,doubley,doublez);
575
587 static Mat rotx(doublerx);
588
600 static Mat roty(doublery);
601
613 static Mat rotz(doublerz);
614
615 private:
617 double _valid;
618
619 // this is a dummy variable to easily obtain a pointer to a 16-double-array for matrix multiplications
620 private:
622 double _ddata16[16];
623
624};
625
627 Mattransl(doublex,doubley,doublez);
628
630 Matrotx(doublerx);
631
633 Matroty(doublery);
634
636 Matrotz(doublerz);
637
638 //QDataStream &operator<<(QDataStream &data, const QMatrix4x4 &);
639 inlineQDebug operator<<(QDebug dbg,const Mat&m){returndbg.noquote() << m.ToString(); }
640 inlineQDebug operator<<(QDebug dbg,const tJoints&jnts){returndbg.noquote() << jnts.ToString(); }
641
642 inlineQDebug operator<<(QDebug dbg,const Mat*m){returndbg.noquote() << (m ==nullptr?"Mat(null)": m->ToString()); }
643 inlineQDebug operator<<(QDebug dbg,const tJoints*jnts){returndbg.noquote() << (jnts ==nullptr?"tJoints(null)": jnts->ToString()); }
644
645
646
647 #endif // ROBODKTYPES_H
The Item class represents an item in RoboDK station. An item can be a robot, a frame,...
Definition: iitem.h:14
This class is the iterface to the RoboDK API. With the RoboDK API you can automate certain tasks and ...
Definition: irobodk.h:14
Mat
The Mat class represents a 4x4 pose matrix. The main purpose of this object is to represent a pose in...
Definition: robodktypes.h:361
QString ToString(const QString &separator=", ", int precision=3, bool xyzrpw_only=false) const
Retrieve a string representation of the pose.
Definition: robodktypes.cpp:405
Mat()
Create the identity matrix.
Definition: robodktypes.cpp:158
void VX(tXYZ xyz) const
Get the X vector (N vector)
Definition: robodktypes.cpp:203
void setVX(double x, double y, double z)
Set the X vector values (N vector)
Definition: robodktypes.cpp:224
void FromXYZRPW(tXYZWPR xyzwpr)
Calculates the pose from the position and euler angles ([x,y,z,r,p,w] vector) The result is the same ...
Definition: robodktypes.cpp:475
void VY(tXYZ xyz) const
Get the Y vector (O vector)
Definition: robodktypes.cpp:208
static Mat transl(double x, double y, double z)
Return a translation matrix.
Definition: robodktypes.cpp:522
void ToXYZRPW(tXYZWPR xyzwpr) const
Calculates the equivalent position and euler angles ([x,y,z,r,p,w] vector) of the given pose Note: tr...
Definition: robodktypes.cpp:380
void setVZ(double x, double y, double z)
Set the Z vector values (A vector)
Definition: robodktypes.cpp:234
double Get(int r, int c) const
Get a matrix value.
Definition: robodktypes.cpp:299
bool Valid() const
Check if the matrix is valid.
Definition: robodktypes.cpp:518
void setVY(double x, double y, double z)
Set the Y vector values (O vector)
Definition: robodktypes.cpp:229
static Mat roty(double ry)
Return a Y-axis rotation matrix
Definition: robodktypes.cpp:535
const double * Values() const
Get a pointer to the 16-digit array (doubles or floats if ROBODK_API_FLOATS is defined).
Definition: robodktypes.cpp:500
void setValues(double pose[16])
Set the pose values.
Definition: robodktypes.cpp:267
void Pos(tXYZ xyz) const
Get the position (T position), in mm.
Definition: robodktypes.cpp:218
bool MakeHomogeneous()
Forces 4x4 matrix to be homogeneous (vx,vy,vz must be unitary vectors and respect: vx x vy = vz)....
Definition: robodktypes.cpp:351
static Mat rotz(double rz)
Return a Z-axis rotation matrix.
Definition: robodktypes.cpp:541
const double * ValuesD() const
Get a pointer to the 16-digit double array.
Definition: robodktypes.cpp:484
double _ddata16[16]
Copy of the data as a double array.
Definition: robodktypes.h:622
bool FromString(const QString &str)
Set the matrix given a XYZRPW string array (6-values)
Definition: robodktypes.cpp:440
double _valid
Flags if a matrix is not valid.
Definition: robodktypes.h:617
Mat inv() const
Invert the pose (homogeneous matrix assumed)
Definition: robodktypes.cpp:305
void setPos(double x, double y, double z)
Set the position (T position) in mm.
Definition: robodktypes.cpp:239
void VZ(tXYZ xyz) const
Get the Z vector (A vector)
Definition: robodktypes.cpp:213
bool isHomogeneous() const
Returns true if the matrix is homogeneous, otherwise it returns false.
Definition: robodktypes.cpp:310
const float * ValuesF() const
Get a pointer to the 16-digit array as an array of floats.
Definition: robodktypes.cpp:491
void Set(int r, int c, double value)
Set a matrix value.
Definition: robodktypes.cpp:290
static Mat rotx(double rx)
Return the X-axis rotation matrix.
Definition: robodktypes.cpp:529
static Mat XYZRPW_2_Mat(double x, double y, double z, double r, double p, double w)
Calculates the pose from the position and euler angles ([x,y,z,r,p,w] vector) The result is the same ...
Definition: robodktypes.cpp:459
The tJoints class represents a joint position of a robot (robot axes).
Definition: robodktypes.h:239
int GetValues(double *joints)
GetValues.
Definition: robodktypes.cpp:95
tJoints(int ndofs=0)
tJoints
Definition: robodktypes.cpp:8
QString ToString(const QString &separator=", ", int precision=3) const
Retrieve a string representation of the joint values.
Definition: robodktypes.cpp:101
int Length() const
Number of joint axes of the robot (or degrees of freedom)
Definition: robodktypes.cpp:123
const double * Values() const
Joint values.
Definition: robodktypes.cpp:60
bool Valid()
Check if the joints are valid. For example, when we request the Inverse kinematics and there is no so...
Definition: robodktypes.cpp:131
int _nDOFs
number of degrees of freedom
Definition: robodktypes.h:340
double * Data()
Definition: robodktypes.cpp:73
const double * ValuesD() const
Joint values.
Definition: robodktypes.cpp:46
double _Values[RDK_SIZE_JOINTS_MAX]
joint values (doubles, used to store the joint values)
Definition: robodktypes.h:343
bool FromString(const QString &str)
Set the joint values given a comma-separated string. Tabs and spaces are also allowed.
Definition: robodktypes.cpp:113
void setLength(int new_length)
Set the length of the array (only shrinking the array is allowed)
Definition: robodktypes.cpp:126
float _ValuesF[RDK_SIZE_JOINTS_MAX]
joint values (floats, used to return a copy as a float pointer)
Definition: robodktypes.h:346
const float * ValuesF() const
Joint values.
Definition: robodktypes.cpp:49
无效的setvalue (const双*关节,int ndofs = 1)
Set the joint values in deg or mm. You can also important provide the number of degrees of freedom (6...
Definition: robodktypes.cpp:78
The Color struct represents an RGBA color (each color component should be in the range [0-1])
Definition: robodktypes.h:120
float r
Red color.
Definition: robodktypes.h:122
float a
Alpha value (0 = transparent; 1 = opaque)
Definition: robodktypes.h:131
float b
Blue color.
Definition: robodktypes.h:128
float g
Green color.
Definition: robodktypes.h:125
The tMatrix2D struct represents a variable size 2d Matrix. Use the Matrix2D_... functions to oeprate ...
Definition: robodktypes.h:145
double * data
Pointer to the data.
Definition: robodktypes.h:147
int * size
Pointer to the size array.
Definition: robodktypes.h:150
int allocatedSize
分配的大小。
Definition: robodktypes.h:153
int numDimensions
Number of dimensions (usually 2)
Definition: robodktypes.h:156