RoboDK Plug-In Interface
Loading...
Searching...
No Matches
robodktypes.h
1#ifndef ROBODKTYPES_H
2#define ROBODKTYPES_H
3
4
5#include <QString>
6#include <QtGui/QMatrix4x4>
7#include <QDebug>
8
9
10#ifndef M_PI
11#define M_PI 3.14159265358979323846264338327950288
12#endif
13
14
15class IItem;
16class IRoboDK;
17typedef IItem* Item;
18typedef 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
36typedef double tXYZWPR[6];
37
39typedef double tXYZ[3];
40
41
56typedef double tConfig[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 (out)[1] = (a)[2]*(b)[0] - (b)[2]*(a)[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
120struct 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
145struct tMatrix2D {
147 double *data;
148
150 int *size;
151
154
157
158 bool canFreeData;
159};
160
161
162
163
164// -------------------------------------------
165
166
169tMatrix2D* Matrix2D_Create();
170
173void Matrix2D_Delete(tMatrix2D **mat);
174
179void Matrix2D_Set_Size(tMatrix2D *mat, int rows, int cols);
180
184int Matrix2D_Size(const tMatrix2D *mat, int dim);
185
189int Matrix2D_Get_ncols(const tMatrix2D *var);
190
194int Matrix2D_Get_nrows(const tMatrix2D *var);
195
199double Matrix2D_Get_ij(const tMatrix2D *var, int i, int j);
200
206void Matrix2D_Set_ij(const tMatrix2D *var, int i, int j, double value);
207
213double* Matrix2D_Get_col(const tMatrix2D *var, int col);
214
216bool Matrix2D_Copy(const tMatrix2D *in, tMatrix2D *out);
217
220void Debug_Array(const double *array, int arraysize);
221
224void Debug_Matrix2D(const tMatrix2D *mat);
225
227void Matrix2D_Save(QDataStream *st, tMatrix2D *emx);
228
230void Matrix2D_Save(QTextStream *st, tMatrix2D *emx, bool csv=false);
231
233void Matrix2D_Load(QDataStream *st, tMatrix2D **emx);
234
235
236//--------------------- Joints class -----------------------
237
239class tJoints {
240
241public:
244 tJoints(int ndofs = 0);
245
249 tJoints(const double *joints, int ndofs = 0);
250
254 tJoints(const float *joints, int ndofs = 0);
255
258 tJoints(const tJoints &jnts);
259
264 tJoints(const tMatrix2D *mat2d, int column=0, int ndofs=-1);
265
268 tJoints(const QString &str);
269
271 operator QString() 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 double Compare(const tJoints &other) const;
294
297 double *Data();
298
301 int Length() const;
302
304 void setLength(int new_length);
305
309 bool Valid();
310
314 int GetValues(double *joints);
315
319 void SetValues(const double *joints, int ndofs = -1);
320
324 void SetValues(const float *joints, int ndofs = -1);
325
330 QString ToString(const QString &separator=", ", int precision = 3) const ;
331
335 bool FromString(const QString &str);
336
337
338public:
341
343 double _Values[RDK_SIZE_JOINTS_MAX];
344
346 float _ValuesF[RDK_SIZE_JOINTS_MAX];
347};
348
349
350
351
361class Mat : public QMatrix4x4 {
362
363public:
364
366 Mat();
367
369 Mat(bool valid);
370
372 Mat(const QMatrix4x4 &matrix);
373
376 Mat(const Mat &matrix);
377
398 Mat(double nx, double ox, double ax, double tx, double ny, double oy, double ay, double ty, double nz, double oz, double az, double tz);
399
407 Mat(const double values[16]);
408
417 Mat(const float values[16]);
418
432 Mat(double x, double y, double z);
433
434 ~Mat();
435
437 operator QString() const { return ToString(); }
438
440 void setVX(double x, double y, double z);
441
443 void setVY(double x, double y, double z);
444
446 void setVZ(double x, double y, double z);
447
449 void setPos(double x, double y, double z);
450
452 void setVX(double xyz[3]);
453
455 void setVY(double xyz[3]);
456
458 void setVZ(double xyz[3]);
459
461 void setPos(double xyz[3]);
462
464 void setValues(double pose[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(int r, int c, double value);
483
488 double Get(int r, int c) 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
514 QString ToString(const QString &separator=", ", int precision = 3, bool xyzrpw_only = false) const;
515
517 bool FromString(const QString &str);
518
526 void FromXYZRPW(tXYZWPR xyzwpr);
527
535 static Mat XYZRPW_2_Mat(double x, double y, double z, double r, double p, double w);
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(double values[16]) const;
554
556 void Values(float values[16]) const;
557
559 bool Valid() const;
560
574 static Mat transl(double x, double y, double z);
575
587 static Mat rotx(double rx);
588
600 static Mat roty(double ry);
601
613 static Mat rotz(double rz);
614
615private:
617 double _valid;
618
619// this is a dummy variable to easily obtain a pointer to a 16-double-array for matrix multiplications
620private:
622 double _ddata16[16];
623
624};
625
627Mat transl(double x, double y, double z);
628
630Mat rotx(double rx);
631
633Mat roty(double ry);
634
636Mat rotz(double rz);
637
638//QDataStream &operator<<(QDataStream &data, const QMatrix4x4 &);
639inline QDebug operator<<(QDebug dbg, const Mat &m){ return dbg.noquote() << m.ToString(); }
640inline QDebug operator<<(QDebug dbg, const tJoints &jnts){ return dbg.noquote() << jnts.ToString(); }
641
642inline QDebug operator<<(QDebug dbg, const Mat *m){ return dbg.noquote() << (m == nullptr ? "Mat(null)" : m->ToString()); }
643inline QDebug operator<<(QDebug dbg, const tJoints *jnts){ return dbg.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
The Mat class represents a 4x4 pose matrix. The main purpose of this object is to represent a pose in...
QString ToString(const QString &separator=", ", int precision=3, bool xyzrpw_only=false) const
Retrieve a string representation of the pose.
Mat()
Create the identity matrix.
void VX(tXYZ xyz) const
Get the X vector (N vector)
void setVX(double x, double y, double z)
Set the X vector values (N vector)
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 ...
void VY(tXYZ xyz) const
Get the Y vector (O vector)
static Mat transl(double x, double y, double z)
Return a translation matrix.
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...
void setVZ(double x, double y, double z)
Set the Z vector values (A vector)
double Get(int r, int c) const
Get a matrix value.
bool Valid() const
Check if the matrix is valid.
void setVY(double x, double y, double z)
Set the Y vector values (O vector)
static Mat roty(double ry)
Return a Y-axis rotation matrix.
const double * Values() const
Get a pointer to the 16-digit array (doubles or floats if ROBODK_API_FLOATS is defined).
void setValues(double pose[16])
Set the pose values.
void Pos(tXYZ xyz) const
Get the position (T position), in mm.
bool MakeHomogeneous()
Forces 4x4 matrix to be homogeneous (vx,vy,vz must be unitary vectors and respect: vx x vy = vz)....
static Mat rotz(double rz)
Return a Z-axis rotation matrix.
const double * ValuesD() const
Get a pointer to the 16-digit double array.
double _ddata16[16]
Copy of the data as a double array.
bool FromString(const QString &str)
Set the matrix given a XYZRPW string array (6-values)
double _valid
Flags if a matrix is not valid.
Mat inv() const
Invert the pose (homogeneous matrix assumed)
void setPos(double x, double y, double z)
Set the position (T position) in mm.
void VZ(tXYZ xyz) const
Get the Z vector (A vector)
bool isHomogeneous() const
Returns true if the matrix is homogeneous, otherwise it returns false.
const float * ValuesF() const
Get a pointer to the 16-digit array as an array of floats.
void Set(int r, int c, double value)
Set a matrix value.
static Mat rotx(double rx)
Return the X-axis rotation matrix.
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 ...
The tJoints class represents a joint position of a robot (robot axes).
int GetValues(double *joints)
GetValues.
tJoints(int ndofs=0)
tJoints
QString ToString(const QString &separator=", ", int precision=3) const
Retrieve a string representation of the joint values.
int Length() const
Number of joint axes of the robot (or degrees of freedom)
const double * Values() const
Joint values.
bool Valid()
Check if the joints are valid. For example, when we request the Inverse kinematics and there is no so...
int _nDOFs
number of degrees of freedom
double * Data()
const double * ValuesD() const
Joint values.
double _Values[RDK_SIZE_JOINTS_MAX]
joint values (doubles, used to store the joint values)
bool FromString(const QString &str)
Set the joint values given a comma-separated string. Tabs and spaces are also allowed.
void setLength(int new_length)
Set the length of the array (only shrinking the array is allowed)
float _ValuesF[RDK_SIZE_JOINTS_MAX]
joint values (floats, used to return a copy as a float pointer)
const float * ValuesF() const
Joint values.
void SetValues(const double *joints, int ndofs=-1)
Set the joint values in deg or mm. You can also important provide the number of degrees of freedom (6...
The Color struct represents an RGBA color (each color component should be in the range [0-1])
float r
Red color.
float a
Alpha value (0 = transparent; 1 = opaque)
float b
Blue color.
float g
Green color.
The tMatrix2D struct represents a variable size 2d Matrix. Use the Matrix2D_... functions to oeprate ...
double * data
Pointer to the data.
int * size
Pointer to the size array.
int allocatedSize
Allocated size.
int numDimensions
Number of dimensions (usually 2)