2#include <QtNetwork/QTcpSocket>
3#include <QtCore/QProcess>
11#define ROBODK_DEFAULT_PATH_BIN "C:/RoboDK/bin/RoboDK.exe"
15#define ROBODK_DEFAULT_PATH_BIN "~/RoboDK/Applications/RoboDK.app/Contents/MacOS/RoboDK"
20#define ROBODK_DEFAULT_PATH_BIN "~/RoboDK/bin/RoboDK"
24#define ROBODK_DEFAULT_PORT 20500
26#define ROBODK_API_TIMEOUT 1000
27#define ROBODK_API_START_STRING "CMD_START"
28#define ROBODK_API_READY_STRING "READY"
29#define ROBODK_API_LF "\n"
33#define M_PI 3.14159265358979323846264338327950288
36#ifndef RDK_SKIP_NAMESPACE
43 _nDOFs = qMin(ndofs, RDK_SIZE_JOINTS_MAX);
44 for (
int i=0; i<
_nDOFs; i++){
55 int ndofs_ok = qMin(ndofs, RDK_SIZE_JOINTS_MAX);
56 double jnts[RDK_SIZE_JOINTS_MAX];
57 for (
int i=0; i<ndofs_ok; i++){
66 qDebug()<<
"Warning: tMatrix2D column outside range when creating joints";
71 _nDOFs = qMin(ndofs, RDK_SIZE_JOINTS_MAX);
84 for (
int i=0; i<RDK_SIZE_JOINTS_MAX; i++){
89#ifdef ROBODK_API_FLOATS
106 _nDOFs = qMin(ndofs, RDK_SIZE_JOINTS_MAX);
108 for (
int i=0; i<
_nDOFs; i++){
115 _nDOFs = qMin(ndofs, RDK_SIZE_JOINTS_MAX);
117 for (
int i=0; i<
_nDOFs; i++){
122 for (
int i=0; i<
_nDOFs; i++){
129 return "tJoints(Invalid)";
135 values.append(QString::number(
_Values[0],
'f',precision));
136 for (
int i=1; i<
_nDOFs; i++){
137 values.append(separator);
138 values.append(QString::number(
_Values[i],
'f',precision));
144 QStringList jnts_list = QString(str).replace(
";",
",").replace(
"\t",
",").split(
",", Qt::SkipEmptyParts);
145 _nDOFs = qMin(jnts_list.length(), RDK_SIZE_JOINTS_MAX);
146 for (
int i=0; i<
_nDOFs; i++){
147 QString stri(jnts_list.at(i));
148 _Values[i] = stri.trimmed().toDouble();
158 if (new_length >= 0 && new_length <
_nDOFs){
198Mat::Mat(
const QMatrix4x4 &matrix) : QMatrix4x4(matrix) {
207Mat::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) :
208 QMatrix4x4(nx, ox, ax, tx, ny, oy, ay, ty, nz, oz, az, tz, 0,0,0,1)
213 QMatrix4x4(v[0], v[4], v[8], v[12], v[1], v[5], v[9], v[13], v[2], v[6], v[10], v[14], v[3], v[7], v[11], v[15])
218 QMatrix4x4(v[0], v[4], v[8], v[12], v[1], v[5], v[9], v[13], v[2], v[6], v[10], v[14], v[3], v[7], v[11], v[15])
294 QVector4D rw(this->row(i));
310 return this->inverted();
314 const bool debug_info =
false;
316 const double tol = 1e-7;
320 if (fabs((
double) DOT(vx,vy)) > tol){
322 qDebug() <<
"Vector X and Y are not perpendicular!";
325 }
else if (fabs((
double) DOT(vx,vz)) > tol){
327 qDebug() <<
"Vector X and Z are not perpendicular!";
330 }
else if (fabs((
double) DOT(vy,vz)) > tol){
332 qDebug() <<
"Vector Y and Z are not perpendicular!";
335 }
else if (fabs((
double) (NORM(vx)-1.0)) > tol){
337 qDebug() <<
"Vector X is not unitary! " << NORM(vx);
340 }
else if (fabs((
double) (NORM(vy)-1.0)) > tol){
342 qDebug() <<
"Vector Y is not unitary! " << NORM(vy);
345 }
else if (fabs((
double) (NORM(vz)-1.0)) > tol){
347 qDebug() <<
"Vector Z is not unitary! " << NORM(vz);
376 return !is_homogeneous;
387 if (
Get(2,0) > (1.0 - 1e-6)){
390 w = atan2(-
Get(1,2),
Get(1,1));
391 }
else if (
Get(2,0) < -1.0 + 1e-6){
394 w = atan2(
Get(1,2),
Get(1,1));
396 p = atan2(-
Get(2, 0), sqrt(
Get(0, 0) *
Get(0, 0) +
Get(1, 0) *
Get(1, 0)));
397 w = atan2(
Get(1, 0),
Get(0, 0));
398 r = atan2(
Get(2, 1),
Get(2, 2));
403 xyzwpr[3] = r*180.0/M_PI;
404 xyzwpr[4] = p*180.0/M_PI;
405 xyzwpr[5] = w*180.0/M_PI;
408QString
Mat::ToString(
const QString &separator,
int precision,
bool xyzwpr_only)
const {
410 return "Mat(Invalid)";
414 str.append(
"Warning!! Pose is not homogeneous! Use Mat::MakeHomogeneous() to make this matrix homogeneous\n");
420 str.append(QString::number(xyzwpr[0],
'f',precision));
421 for (
int i=1; i<6; i++){
422 str.append(separator);
423 str.append(QString::number(xyzwpr[i],
'f',precision));
431 for (
int i=0; i<4; i++){
433 for (
int j=0; j<4; j++){
434 str.append(QString::number(row(i)[j],
'f', precision));
436 str.append(separator);
445 QStringList values_list = QString(pose_str).replace(
";",
",").replace(
"\t",
",").split(
",", Qt::SkipEmptyParts);
446 int nvalues = qMin(values_list.length(), 6);
448 for (
int i=0; i<6; i++){
455 for (
int i=0; i<nvalues; i++){
456 QString stri(values_list.at(i));
457 xyzwpr[i] = stri.trimmed().toDouble();
465 double a = r * M_PI / 180.0;
466 double b = p * M_PI / 180.0;
467 double c = w * M_PI / 180.0;
474 return Mat(cb * cc, cc * sa * sb - ca * sc, sa * sc + ca * cc * sb, x, cb * sc, ca * cc + sa * sb * sc, ca * sb * sc - cc * sa, y, -sb, cb * sa, ca * cb, z);
477 return XYZRPW_2_Mat(xyzwpr[0], xyzwpr[1], xyzwpr[2], xyzwpr[3], xyzwpr[4], xyzwpr[5]);
481 Mat newmat =
Mat::XYZRPW_2_Mat(xyzwpr[0], xyzwpr[1], xyzwpr[2], xyzwpr[3], xyzwpr[4], xyzwpr[5]);
482 for (
int i=0; i<4; i++){
483 for (
int j=0; j<4; j++){
484 this->
Set(i,j, newmat.
Get(i,j));
490 double* _ddata16_non_const = (
double*)
_ddata16;
491 for(
int i=0; i<16; ++i){
492 _ddata16_non_const[i] = constData()[i];
500#ifdef ROBODK_API_FLOATS
514 for(
int i=0; i<16; ++i){
515 data[i] = constData()[i];
519 for(
int i=0; i<16; ++i){
520 data[i] = constData()[i];
537 return Mat(1, 0, 0, 0, 0, cx, -sx, 0, 0, sx, cx, 0);
543 return Mat(cy, 0, sy, 0, 0, 1, 0, 0, -sy, 0, cy, 0);
549 return Mat(cz, -sz, 0, 0, sz, cz, 0, 0, 0, 0, 1, 0);
560Item::Item(
RoboDK *rdk, quint64 ptr, qint32 type) {
565Item::Item(
const Item &other) {
574QString Item::ToString()
const {
576 return QString(
"Item(&RDK, %1, %2); // %3").arg(
_PTR).arg(
_TYPE).arg(
Name());
578 return "Item(Invalid)";
603 _RDK->_check_connection();
604 _RDK->_send_Line(
"G_Item_Type");
605 _RDK->_send_Item(
this);
606 int itemtype =
_RDK->_recv_Int();
607 _RDK->_check_status();
625 _RDK->_check_connection();
626 _RDK->_send_Line(
"Remove");
627 _RDK->_send_Item(
this);
628 _RDK->_check_status();
648 _RDK->_check_connection();
649 _RDK->_send_Line(
"S_Parent");
650 _RDK->_send_Item(
this);
651 _RDK->_send_Item(parent);
652 _RDK->_check_status();
661 _RDK->_check_connection();
662 _RDK->_send_Line(
"S_Parent_Static");
663 _RDK->_send_Item(
this);
664 _RDK->_send_Item(parent);
665 _RDK->_check_status();
673 _RDK->_check_connection();
674 _RDK->_send_Line(
"Attach_Closest");
675 _RDK->_send_Item(
this);
676 Item item_attached =
_RDK->_recv_Item();
677 _RDK->_check_status();
678 return item_attached;
686 _RDK->_check_connection();
687 _RDK->_send_Line(
"Detach_Closest");
688 _RDK->_send_Item(
this);
689 _RDK->_send_Item(parent);
690 Item item_detached =
_RDK->_recv_Item();
691 _RDK->_check_status();
692 return item_detached;
699 _RDK->_check_connection();
700 _RDK->_send_Line(
"Detach_All");
701 _RDK->_send_Item(
this);
702 _RDK->_send_Item(parent);
703 _RDK->_check_status();
712 _RDK->_check_connection();
713 _RDK->_send_Line(
"G_Parent");
714 _RDK->_send_Item(
this);
715 Item itm_parent =
_RDK->_recv_Item();
716 _RDK->_check_status();
727 _RDK->_check_connection();
728 _RDK->_send_Line(
"G_Childs");
729 _RDK->_send_Item(
this);
730 int nitems =
_RDK->_recv_Int();
731 QList<Item> itemlist;
732 for (
int i = 0; i < nitems; i++)
734 itemlist.append(
_RDK->_recv_Item());
736 _RDK->_check_status();
745 _RDK->_check_connection();
746 _RDK->_send_Line(
"G_Visible");
747 _RDK->_send_Item(
this);
748 int visible =
_RDK->_recv_Int();
749 _RDK->_check_status();
750 return (visible != 0);
758 if (visible_frame < 0)
760 visible_frame = visible ? 1 : 0;
762 _RDK->_check_connection();
763 _RDK->_send_Line(
"S_Visible");
764 _RDK->_send_Item(
this);
765 _RDK->_send_Int(visible ? 1 : 0);
766 _RDK->_send_Int(visible_frame);
767 _RDK->_check_status();
775 _RDK->_check_connection();
776 _RDK->_send_Line(
"G_Name");
777 _RDK->_send_Item(
this);
778 QString name =
_RDK->_recv_Line();
779 _RDK->_check_status();
788 _RDK->_check_connection();
789 _RDK->_send_Line(
"S_Name");
790 _RDK->_send_Item(
this);
791 _RDK->_send_Line(name);
792 _RDK->_check_status();
803 _RDK->_check_connection();
804 _RDK->_send_Line(
"S_Hlocal");
805 _RDK->_send_Item(
this);
806 _RDK->_send_Pose(pose);
807 _RDK->_check_status();
816 _RDK->_check_connection();
817 _RDK->_send_Line(
"G_Hlocal");
818 _RDK->_send_Item(
this);
820 _RDK->_check_status();
829 _RDK->_check_connection();
830 _RDK->_send_Line(
"S_Hgeom");
831 _RDK->_send_Item(
this);
832 _RDK->_send_Pose(pose);
833 _RDK->_check_status();
841 _RDK->_check_connection();
842 _RDK->_send_Line(
"G_Hgeom");
843 _RDK->_send_Item(
this);
845 _RDK->_check_status();
853void Item::setHtool(Mat pose){
854 _RDK->_check_connection();
855 _RDK->_send_Line("S_Htool");
856 _RDK->_send_Item(this);
857 _RDK->_send_Pose(pose);
858 _RDK->_check_status();
867 _RDK->_check_connection();
868 _RDK->_send_Line("G_Htool");
869 _RDK->_send_Item(this);
870 Mat pose = _RDK->_recv_Pose();
871 _RDK->_check_status();
880 _RDK->_check_connection();
881 _RDK->_send_Line(
"G_Tool");
882 _RDK->_send_Item(
this);
884 _RDK->_check_status();
893 _RDK->_check_connection();
894 _RDK->_send_Line(
"G_Frame");
895 _RDK->_send_Item(
this);
897 _RDK->_check_status();
907 _RDK->_check_connection();
908 _RDK->_send_Line(
"S_Frame");
909 _RDK->_send_Pose(frame_pose);
910 _RDK->_send_Item(
this);
911 _RDK->_check_status();
920 _RDK->_check_connection();
921 _RDK->_send_Line(
"S_Frame_ptr");
922 _RDK->_send_Item(frame_item);
923 _RDK->_send_Item(
this);
924 _RDK->_check_status();
933 _RDK->_check_connection();
934 _RDK->_send_Line(
"S_Tool");
935 _RDK->_send_Pose(tool_pose);
936 _RDK->_send_Item(
this);
937 _RDK->_check_status();
946 _RDK->_check_connection();
947 _RDK->_send_Line(
"S_Tool_ptr");
948 _RDK->_send_Item(tool_item);
949 _RDK->_send_Item(
this);
950 _RDK->_check_status();
958 _RDK->_check_connection();
959 _RDK->_send_Line(
"S_Hlocal_Abs");
960 _RDK->_send_Item(
this);
961 _RDK->_send_Pose(pose);
962 _RDK->_check_status();
971 _RDK->_check_connection();
972 _RDK->_send_Line(
"G_Hlocal_Abs");
973 _RDK->_send_Item(
this);
975 _RDK->_check_status();
984 _RDK->_check_connection();
985 _RDK->_send_Line(
"S_Color");
986 _RDK->_send_Item(
this);
987 _RDK->_send_Array(colorRGBA, 4);
988 _RDK->_check_status();
1004 double scale_xyz[3];
1005 scale_xyz[0] = scale;
1006 scale_xyz[1] = scale;
1007 scale_xyz[2] = scale;
1017 _RDK->_check_connection();
1018 _RDK->_send_Line(
"Scale");
1019 _RDK->_send_Item(
this);
1020 _RDK->_send_Array(scale_xyz, 3);
1021 _RDK->_check_status();
1027 result.featureId = 0;
1028 result.points =
nullptr;
1034 _RDK->_check_connection();
1035 _RDK->_send_Line(
"G_ObjPoint");
1036 _RDK->_send_Item(
this);
1037 _RDK->_send_Int(featureType);
1038 _RDK->_send_Int(featureId);
1039 _RDK->_recv_Matrix2D(&result.points);
1040 result.featureName =
_RDK->_recv_Line();
1041 result.featureType = featureType;
1042 result.featureId = featureId;
1043 _RDK->_check_status();
1049 _RDK->_check_connection();
1050 _RDK->_send_Line(
"G_ObjSelection");
1051 _RDK->_send_Item(
this);
1052 int isSelected =
_RDK->_recv_Int();
1053 featureType =
_RDK->_recv_Int();
1054 featureId =
_RDK->_recv_Int();
1055 _RDK->_check_status();
1056 return isSelected != 0;
1073 _RDK->_check_connection();
1074 _RDK->_send_Line(
"S_MachiningParams");
1075 _RDK->_send_Item(
this);
1076 _RDK->_send_Line(ncfile);
1077 _RDK->_send_Item(part_obj);
1078 _RDK->_send_Line(
"NO_UPDATE " + options);
1079 _RDK->_TIMEOUT = 3600 * 1000;
1081 _RDK->_TIMEOUT = ROBODK_API_TIMEOUT;
1082 double status =
_RDK->_recv_Int() / 1000.0;
1083 _RDK->_check_status();
1091 _RDK->_check_connection();
1092 _RDK->_send_Line(
"S_Target_As_RT");
1093 _RDK->_send_Item(
this);
1094 _RDK->_check_status();
1101 _RDK->_check_connection();
1102 _RDK->_send_Line(
"S_Target_As_JT");
1103 _RDK->_send_Item(
this);
1104 _RDK->_check_status();
1111 _RDK->_check_connection();
1112 _RDK->_send_Line(
"Target_Is_JT");
1113 _RDK->_send_Item(
this);
1114 int is_jt =
_RDK->_recv_Int();
1115 _RDK->_check_status();
1127 _RDK->_check_connection();
1128 _RDK->_send_Line(
"G_Thetas");
1129 _RDK->_send_Item(
this);
1130 _RDK->_recv_Array(&jnts);
1131 _RDK->_check_status();
1143 _RDK->_check_connection();
1144 _RDK->_send_Line(
"G_Home");
1145 _RDK->_send_Item(
this);
1146 _RDK->_recv_Array(&jnts);
1147 _RDK->_check_status();
1157 _RDK->_check_connection();
1158 _RDK->_send_Line(
"S_Home");
1159 _RDK->_send_Array(&jnts);
1160 _RDK->_send_Item(
this);
1161 _RDK->_check_status();
1170 _RDK->_check_connection();
1171 _RDK->_send_Line(
"G_LinkObjId");
1172 _RDK->_send_Item(
this);
1173 _RDK->_send_Int(link_id);
1175 _RDK->_check_status();
1185 _RDK->_check_connection();
1186 _RDK->_send_Line(
"G_LinkType");
1187 _RDK->_send_Item(
this);
1188 _RDK->_send_Int(type_linked);
1190 _RDK->_check_status();
1200 _RDK->_check_connection();
1201 _RDK->_send_Line(
"S_Thetas");
1202 _RDK->_send_Array(&jnts);
1203 _RDK->_send_Item(
this);
1204 _RDK->_check_status();
1213 _RDK->_check_connection();
1214 _RDK->_send_Line(
"G_RobLimits");
1215 _RDK->_send_Item(
this);
1216 _RDK->_recv_Array(lower_limits);
1217 _RDK->_recv_Array(upper_limits);
1218 double joints_type =
_RDK->_recv_Int() / 1000.0;
1219 _RDK->_check_status();
1228 _RDK->_check_connection();
1229 _RDK->_send_Line(
"S_RobLimits");
1230 _RDK->_send_Item(
this);
1231 _RDK->_send_Array(&lower_limits);
1232 _RDK->_send_Array(&upper_limits);
1234 _RDK->_check_status();
1243 _RDK->_check_connection();
1244 _RDK->_send_Line(
"S_Robot");
1245 _RDK->_send_Item(
this);
1246 _RDK->_send_Item(robot);
1247 _RDK->_check_status();
1258 _RDK->_check_connection();
1259 _RDK->_send_Line(
"AddToolEmpty");
1260 _RDK->_send_Item(
this);
1261 _RDK->_send_Pose(tool_pose);
1262 _RDK->_send_Line(tool_name);
1264 _RDK->_check_status();
1274 _RDK->_check_connection();
1275 _RDK->_send_Line(
"G_FK");
1276 _RDK->_send_Array(&joints);
1277 _RDK->_send_Item(
this);
1278 Mat pose =
_RDK->_recv_Pose();
1279 Mat base2flange(pose);
1280 if (tool !=
nullptr){
1281 base2flange = pose*(*tool);
1283 if (ref !=
nullptr){
1284 base2flange = ref->
inv() * base2flange;
1286 _RDK->_check_status();
1296 _RDK->_check_connection();
1297 _RDK->_send_Line(
"G_Thetas_Config");
1298 _RDK->_send_Array(&joints);
1299 _RDK->_send_Item(
this);
1300 int sz = RDK_SIZE_MAX_CONFIG;
1301 _RDK->_recv_Array(config, &sz);
1302 _RDK->_check_status();
1315 Mat base2flange(pose);
1316 if (tool !=
nullptr){
1317 base2flange = pose*tool->
inv();
1319 if (ref !=
nullptr){
1320 base2flange = (*ref) * base2flange;
1322 _RDK->_check_connection();
1323 _RDK->_send_Line(
"G_IK");
1324 _RDK->_send_Pose(base2flange);
1325 _RDK->_send_Item(
this);
1326 _RDK->_recv_Array(&jnts);
1327 _RDK->_check_status();
1342 Mat base2flange(pose);
1343 if (tool !=
nullptr){
1344 base2flange = pose*tool->
inv();
1346 if (ref !=
nullptr){
1347 base2flange = (*ref) * base2flange;
1349 _RDK->_check_connection();
1350 _RDK->_send_Line(
"G_IK_jnts");
1351 _RDK->_send_Pose(base2flange);
1352 _RDK->_send_Array(&joints_approx);
1353 _RDK->_send_Item(
this);
1355 _RDK->_recv_Array(&jnts);
1356 _RDK->_check_status();
1368 Mat base2flange(pose);
1369 if (tool !=
nullptr){
1370 base2flange = pose*tool->
inv();
1372 if (ref !=
nullptr){
1373 base2flange = (*ref) * base2flange;
1375 _RDK->_check_connection();
1376 _RDK->_send_Line(
"G_IK_cmpl");
1377 _RDK->_send_Pose(base2flange);
1378 _RDK->_send_Item(
this);
1379 _RDK->_recv_Matrix2D(&mat2d);
1380 _RDK->_check_status();
1385 QList<tJoints> jnts_list;
1388 for (
int i=0; i<nsol; i++){
1391 jnts_list.append(jnts);
1402 _RDK->_check_connection();
1403 _RDK->_send_Line(
"Connect");
1404 _RDK->_send_Item(
this);
1405 _RDK->_send_Line(robot_ip);
1406 int status =
_RDK->_recv_Int();
1407 _RDK->_check_status();
1416 _RDK->_check_connection();
1417 _RDK->_send_Line(
"Disconnect");
1418 _RDK->_send_Item(
this);
1419 int status =
_RDK->_recv_Int();
1420 _RDK->_check_status();
1431 _RDK->_check_connection();
1432 _RDK->_send_Line(
"Add_INSMOVE");
1433 _RDK->_send_Item(itemtarget);
1434 _RDK->_send_Item(
this);
1436 _RDK->_check_status();
1438 _RDK->_moveX(&itemtarget,
nullptr,
nullptr,
this, 1, blocking);
1448 _RDK->_moveX(
nullptr, &joints,
nullptr,
this, 1, blocking);
1457 _RDK->_moveX(
nullptr,
nullptr, &target,
this, 1, blocking);
1467 _RDK->_check_connection();
1468 _RDK->_send_Line(
"Add_INSMOVE");
1469 _RDK->_send_Item(itemtarget);
1470 _RDK->_send_Item(
this);
1472 _RDK->_check_status();
1474 _RDK->_moveX(&itemtarget,
nullptr,
nullptr,
this, 2, blocking);
1484 _RDK->_moveX(
nullptr, &joints,
nullptr,
this, 2, blocking);
1493 _RDK->_moveX(
nullptr,
nullptr, &target,
this, 2, blocking);
1503 _RDK->_moveC(&itemtarget1,
nullptr,
nullptr, &itemtarget2,
nullptr,
nullptr,
this, blocking);
1513 _RDK->_moveC(
nullptr, &joints1,
nullptr,
nullptr, &joints2,
nullptr,
this, blocking);
1523 _RDK->_moveC(
nullptr,
nullptr, &target1,
nullptr,
nullptr, &target2,
this, blocking);
1534 _RDK->_check_connection();
1535 _RDK->_send_Line(
"CollisionMove");
1536 _RDK->_send_Item(
this);
1537 _RDK->_send_Array(&j1);
1538 _RDK->_send_Array(&j2);
1539 _RDK->_send_Int((
int)(minstep_deg * 1000.0));
1540 _RDK->_TIMEOUT = 3600 * 1000;
1541 int collision =
_RDK->_recv_Int();
1542 _RDK->_TIMEOUT = ROBODK_API_TIMEOUT;
1543 _RDK->_check_status();
1555 _RDK->_check_connection();
1556 _RDK->_send_Line(
"CollisionMoveL");
1557 _RDK->_send_Item(
this);
1558 _RDK->_send_Array(&j1);
1559 _RDK->_send_Pose(pose2);
1560 _RDK->_send_Int((
int)(minstep_deg * 1000.0));
1561 _RDK->_TIMEOUT = 3600 * 1000;
1562 int collision =
_RDK->_recv_Int();
1563 _RDK->_TIMEOUT = ROBODK_API_TIMEOUT;
1564 _RDK->_check_status();
1576void Item::setSpeed(
double speed_linear,
double speed_joints,
double accel_linear,
double accel_joints){
1577 _RDK->_check_connection();
1578 _RDK->_send_Line(
"S_Speed4");
1579 _RDK->_send_Item(
this);
1580 double speed_accel[4];
1581 speed_accel[0] = speed_linear;
1582 speed_accel[1] = speed_joints;
1583 speed_accel[2] = accel_linear;
1584 speed_accel[3] = accel_joints;
1585 _RDK->_send_Array(speed_accel, 4);
1586 _RDK->_check_status();
1594 _RDK->_check_connection();
1595 _RDK->_send_Line(
"S_ZoneData");
1596 _RDK->_send_Int((
int)(zonedata * 1000.0));
1597 _RDK->_send_Item(
this);
1598 _RDK->_check_status();
1606 _RDK->_check_connection();
1607 _RDK->_send_Line(
"Show_Seq");
1608 _RDK->_send_Matrix2D(sequence);
1609 _RDK->_send_Item(
this);
1610 _RDK->_check_status();
1619 _RDK->_check_connection();
1620 _RDK->_send_Line(
"IsBusy");
1621 _RDK->_send_Item(
this);
1622 int busy =
_RDK->_recv_Int();
1623 _RDK->_check_status();
1632 _RDK->_check_connection();
1633 _RDK->_send_Line(
"Stop");
1634 _RDK->_send_Item(
this);
1635 _RDK->_check_status();
1643 _RDK->_check_connection();
1644 _RDK->_send_Line(
"WaitMove");
1645 _RDK->_send_Item(
this);
1646 _RDK->_check_status();
1647 _RDK->_TIMEOUT = (int)(timeout_sec * 1000.0);
1648 _RDK->_check_status();
1649 _RDK->_TIMEOUT = ROBODK_API_TIMEOUT;
1663 _RDK->_check_connection();
1664 _RDK->_send_Line(
"S_AbsAccOn");
1665 _RDK->_send_Item(
this);
1666 _RDK->_send_Int(accurate);
1667 _RDK->_check_status();
1681 _RDK->_check_connection();
1682 _RDK->_send_Line(
"MakeProg");
1683 _RDK->_send_Item(
this);
1684 _RDK->_send_Line(filename);
1685 int prog_status =
_RDK->_recv_Int();
1686 QString prog_log_str =
_RDK->_recv_Line();
1687 _RDK->_check_status();
1688 bool success =
false;
1689 if (prog_status > 1) {
1701 _RDK->_check_connection();
1702 _RDK->_send_Line(
"S_ProgRunType");
1703 _RDK->_send_Item(
this);
1704 _RDK->_send_Int(program_run_type);
1705 _RDK->_check_status();
1718 _RDK->_check_connection();
1719 _RDK->_send_Line(
"RunProg");
1720 _RDK->_send_Item(
this);
1721 int prog_status =
_RDK->_recv_Int();
1722 _RDK->_check_status();
1737 _RDK->_check_connection();
1738 if (parameters.isEmpty()){
1739 _RDK->_send_Line(
"RunProg");
1740 _RDK->_send_Item(
this);
1742 _RDK->_send_Line(
"RunProgParam");
1743 _RDK->_send_Item(
this);
1744 _RDK->_send_Line(parameters);
1746 int progstatus =
_RDK->_recv_Int();
1747 _RDK->_check_status();
1757 _RDK->_check_connection();
1758 _RDK->_send_Line(
"RunCode2");
1759 _RDK->_send_Item(
this);
1760 _RDK->_send_Line(QString(code).replace(
"\n\n",
"<br>").replace(
"\n",
"<br>"));
1761 _RDK->_send_Int(run_type);
1762 int progstatus =
_RDK->_recv_Int();
1763 _RDK->_check_status();
1772 _RDK->_check_connection();
1773 _RDK->_send_Line(
"RunPause");
1774 _RDK->_send_Item(
this);
1775 _RDK->_send_Int((
int)(time_ms * 1000.0));
1776 _RDK->_check_status();
1786 _RDK->_check_connection();
1787 _RDK->_send_Line(
"setDO");
1788 _RDK->_send_Item(
this);
1789 _RDK->_send_Line(io_var);
1790 _RDK->_send_Line(io_value);
1791 _RDK->_check_status();
1799 _RDK->_check_connection();
1800 _RDK->_send_Line(
"setAO");
1801 _RDK->_send_Item(
this);
1802 _RDK->_send_Line(io_var);
1803 _RDK->_send_Line(io_value);
1804 _RDK->_check_status();
1812 _RDK->_check_connection();
1813 _RDK->_send_Line(
"getDI");
1814 _RDK->_send_Item(
this);
1815 _RDK->_send_Line(io_var);
1816 QString io_value(
_RDK->_recv_Line());
1817 _RDK->_check_status();
1826 _RDK->_check_connection();
1827 _RDK->_send_Line(
"getAI");
1828 _RDK->_send_Item(
this);
1829 _RDK->_send_Line(io_var);
1830 QString di_value(
_RDK->_recv_Line());
1831 _RDK->_check_status();
1841void Item::waitDI(
const QString &io_var,
const QString &io_value,
double timeout_ms){
1842 _RDK->_check_connection();
1843 _RDK->_send_Line(
"waitDI");
1844 _RDK->_send_Item(
this);
1845 _RDK->_send_Line(io_var);
1846 _RDK->_send_Line(io_value);
1847 _RDK->_send_Int((
int)(timeout_ms * 1000.0));
1848 _RDK->_check_status();
1861void Item::customInstruction(
const QString &name,
const QString &path_run,
const QString &path_icon,
bool blocking,
const QString &cmd_run_on_robot){
1862 _RDK->_check_connection();
1863 _RDK->_send_Line(
"InsCustom2");
1864 _RDK->_send_Item(
this);
1865 _RDK->_send_Line(name);
1866 _RDK->_send_Line(path_run);
1867 _RDK->_send_Line(path_icon);
1868 _RDK->_send_Line(cmd_run_on_robot);
1869 _RDK->_send_Int(blocking ? 1 : 0);
1870 _RDK->_check_status();
1879void Item::addMoveJ(const Item &itemtarget){
1880 _RDK->_check_connection();
1881 _RDK->_send_Line("Add_INSMOVE");
1882 _RDK->_send_Item(itemtarget);
1883 _RDK->_send_Item(this);
1885 _RDK->_check_status();
1892void Item::addMoveL(const Item &itemtarget){
1893 _RDK->_check_connection();
1894 _RDK->_send_Line("Add_INSMOVE");
1895 _RDK->_send_Item(itemtarget);
1896 _RDK->_send_Item(this);
1898 _RDK->_check_status();
1907 _RDK->_check_connection();
1908 _RDK->_send_Line(
"Prog_ShowIns");
1909 _RDK->_send_Item(
this);
1910 _RDK->_send_Int(visible ? 1 : 0);
1911 _RDK->_check_status();
1919 _RDK->_check_connection();
1920 _RDK->_send_Line(
"Prog_ShowTargets");
1921 _RDK->_send_Item(
this);
1922 _RDK->_send_Int(visible ? 1 : 0);
1923 _RDK->_check_status();
1933 _RDK->_check_connection();
1934 _RDK->_send_Line(
"Prog_Nins");
1935 _RDK->_send_Item(
this);
1936 int nins =
_RDK->_recv_Int();
1937 _RDK->_check_status();
1952 _RDK->_check_connection();
1953 _RDK->_send_Line(
"Prog_GIns");
1954 _RDK->_send_Item(
this);
1955 _RDK->_send_Int(ins_id);
1956 name =
_RDK->_recv_Line();
1957 instype =
_RDK->_recv_Int();
1959 isjointtarget =
false;
1963 movetype =
_RDK->_recv_Int();
1964 isjointtarget =
_RDK->_recv_Int() > 0 ? true :
false;
1965 target =
_RDK->_recv_Pose();
1966 _RDK->_recv_Array(&joints);
1968 _RDK->_check_status();
1982 _RDK->_check_connection();
1983 _RDK->_send_Line(
"Prog_SIns");
1984 _RDK->_send_Item(
this);
1985 _RDK->_send_Int(ins_id);
1986 _RDK->_send_Line(name);
1987 _RDK->_send_Int(instype);
1990 _RDK->_send_Int(movetype);
1991 _RDK->_send_Int(isjointtarget ? 1 : 0);
1992 _RDK->_send_Pose(target);
1993 _RDK->_send_Array(&joints);
1995 _RDK->_check_status();
2005 _RDK->_check_connection();
2006 _RDK->_send_Line(
"G_ProgInsList");
2007 _RDK->_send_Item(
this);
2008 _RDK->_recv_Matrix2D(&instructions);
2009 int errors =
_RDK->_recv_Int();
2010 _RDK->_check_status();
2026double Item::Update(
int collision_check,
int timeout_sec,
double *out_nins_time_dist,
double mm_step,
double deg_step){
2027 _RDK->_check_connection();
2028 _RDK->_send_Line(
"Update2");
2029 _RDK->_send_Item(
this);
2031 values[0] = collision_check;
2032 values[1] = mm_step;
2033 values[2] = deg_step;
2034 _RDK->_send_Array(values, 3);
2035 _RDK->_TIMEOUT = timeout_sec * 1000;
2036 double return_values[10];
2038 _RDK->_recv_Array(return_values, &nvalues);
2039 _RDK->_TIMEOUT = ROBODK_API_TIMEOUT;
2040 QString readable_msg =
_RDK->_recv_Line();
2041 _RDK->_check_status();
2042 double ratio_ok = return_values[3];
2043 if (out_nins_time_dist !=
nullptr)
2045 out_nins_time_dist[0] = return_values[0];
2046 out_nins_time_dist[1] = return_values[1];
2047 out_nins_time_dist[2] = return_values[2];
2065int Item::InstructionListJoints(QString &error_msg,
tMatrix2D **joint_list,
double mm_step,
double deg_step,
const QString &save_to_file,
bool collision_check,
int result_flag,
double time_step_s){
2066 _RDK->_check_connection();
2067 _RDK->_send_Line(
"G_ProgJointList");
2068 _RDK->_send_Item(
this);
2069 double step_mm_deg[5] = { mm_step, deg_step, collision_check ? 1.0 : 0.0, (double) result_flag, time_step_s };
2070 _RDK->_send_Array(step_mm_deg, 5);
2071 _RDK->_TIMEOUT = 3600 * 1000;
2073 if (save_to_file.isEmpty()) {
2074 _RDK->_send_Line(
"");
2075 _RDK->_recv_Matrix2D(joint_list);
2077 _RDK->_send_Line(save_to_file);
2078 joint_list =
nullptr;
2080 int error_code =
_RDK->_recv_Int();
2081 _RDK->_TIMEOUT = ROBODK_API_TIMEOUT;
2082 error_msg =
_RDK->_recv_Line();
2083 _RDK->_check_status();
2096 _RDK->_check_connection();
2097 _RDK->_send_Line(
"ICMD");
2098 _RDK->_send_Item(
this);
2099 _RDK->_send_Line(param);
2100 _RDK->_send_Line(value);
2101 QString result =
_RDK->_recv_Line();
2102 _RDK->_check_status();
2107 _RDK->_check_connection();
2108 _RDK->_send_Line(
"S_ItmDataParam");
2109 _RDK->_send_Item(
this);
2110 _RDK->_send_Line(param);
2111 _RDK->_send_Bytes(value);
2112 _RDK->_check_status();
2116 _RDK->_check_connection();
2117 _RDK->_send_Line(
"G_ItmDataParam");
2118 _RDK->_send_Item(
this);
2119 _RDK->_send_Line(param);
2120 QByteArray result =
_RDK->_recv_Bytes();
2121 _RDK->_check_status();
2156RoboDK::RoboDK(QAbstractSocket* socket,
bool fUseExceptions) {
2158 _USE_EXCPETIONS = fUseExceptions;
2159 _OWN_SOCKET =
false;
2160 _TIMEOUT = ROBODK_API_TIMEOUT;
2162 _PORT = ROBODK_DEFAULT_PORT;
2163 _ROBODK_BIN = ROBODK_DEFAULT_PATH_BIN;
2167RoboDK::RoboDK(
const QString &robodk_ip,
int com_port,
const QString &args,
const QString &path,
bool fUseExceptions) {
2169 _USE_EXCPETIONS = fUseExceptions;
2172 _TIMEOUT = ROBODK_API_TIMEOUT;
2177 _PORT = ROBODK_DEFAULT_PORT;
2179 if (_ROBODK_BIN.isEmpty()){
2180 _ROBODK_BIN = ROBODK_DEFAULT_PATH_BIN;
2184 _ARGUMENTS.append(
" /PORT=" + QString::number(com_port));
2193quint64 RoboDK::ProcessID(){
2194 if (_PROCESS == 0) {
2195 QString response =
Command(
"MainProcess_ID");
2196 _PROCESS = response.toULongLong();
2201quint64 RoboDK::WindowID(){
2203 QString response =
Command(
"MainWindow_ID");
2204 window_id = response.toULongLong();
2208bool RoboDK::Connected(){
2209 return _connected();
2212bool RoboDK::Connect(){
2239 _check_connection();
2241 _send_Line(
"G_Item");
2244 _send_Line(
"G_Item2");
2246 _send_Int(itemtype);
2248 Item item = _recv_Item();
2260 _check_connection();
2262 _send_Line(
"G_List_Items");
2264 _send_Line(
"G_List_Items_Type");
2267 qint32 numitems = _recv_Int();
2268 QStringList listnames;
2269 for (
int i = 0; i < numitems; i++) {
2270 listnames.append(_recv_Line());
2283 _check_connection();
2285 _send_Line(
"G_List_Items_ptr");
2287 _send_Line(
"G_List_Items_Type_ptr");
2290 int numitems = _recv_Int();
2291 QList<Item> listitems;
2292 for (
int i = 0; i < numitems; i++) {
2293 listitems.append(_recv_Item());
2309 _check_connection();
2310 _send_Line(
"PickItem");
2311 _send_Line(message);
2312 _send_Int(itemtype);
2313 _TIMEOUT = 3600 * 1000;
2314 Item item = _recv_Item();
2315 _TIMEOUT = ROBODK_API_TIMEOUT;
2324 _check_connection();
2325 _send_Line(
"RAISE");
2333 _check_connection();
2342 _check_connection();
2351 _check_connection();
2352 _send_Line(
"Version");
2353 QString appName = _recv_Line();
2354 int bitArch = _recv_Int();
2355 QString ver4 = _recv_Line();
2356 QString dateBuild = _recv_Line();
2368 _check_connection();
2369 _send_Line(
"S_WindowState");
2370 _send_Int(windowstate);
2380 _check_connection();
2381 _send_Line(
"S_RoboDK_Rights");
2392 _check_connection();
2393 _send_Line(
"S_Item_Rights");
2405 _check_connection();
2406 _send_Line(
"S_Item_Rights");
2408 int flags = _recv_Int();
2419 _check_connection();
2422 _send_Line(
"ShowMessage");
2423 _send_Line(message);
2424 _TIMEOUT = 3600 * 1000;
2426 _TIMEOUT = ROBODK_API_TIMEOUT;
2430 _send_Line(
"ShowMessageStatus");
2431 _send_Line(message);
2442 _check_connection();
2454 _check_connection();
2455 _send_Line(
"Paste");
2456 _send_Item(paste_to);
2457 Item newitem = _recv_Item();
2469 _check_connection();
2471 _send_Line(filename);
2473 _TIMEOUT = 3600 * 1000;
2474 Item newitem = _recv_Item();
2475 _TIMEOUT = ROBODK_API_TIMEOUT;
2486 _check_connection();
2488 _send_Line(filename);
2489 _send_Item(itemsave);
2507 double colorArray[4] = {0.6,0.6,0.8,1.0};
2508 if (color !=
nullptr){
2509 colorArray[0] = color->
r;
2510 colorArray[1] = color->
g;
2511 colorArray[2] = color->
b;
2512 colorArray[3] = color->
a;
2514 _check_connection();
2515 _send_Line(
"AddShape3");
2516 _send_Matrix2D(trianglePoints);
2518 _send_Int(shapeOverride? 1 : 0);
2519 _send_Array(colorArray,4);
2520 Item newitem = _recv_Item();
2543 _check_connection();
2544 _send_Line(
"AddWire");
2545 _send_Matrix2D(curvePoints);
2546 _send_Item(referenceObject);
2547 _send_Int(addToRef ? 1:0);
2548 _send_Int(ProjectionType);
2549 Item newitem = _recv_Item();
2564 _check_connection();
2565 _send_Line(
"AddPoints");
2566 _send_Matrix2D(points);
2567 _send_Item(referenceObject);
2568 _send_Int(addToRef? 1 : 0);
2569 _send_Int(ProjectionType);
Item newitem = _recv_Item();
2576 _check_connection();
2577 _send_Line(
"ProjectPoints");
2578 _send_Matrix2D(points);
2579 _send_Item(objectProject);
2580 _send_Int(ProjectionType);
2581 _recv_Matrix2D(projected);
2592 _check_connection();
2593 _send_Line(
"NewStation");
2595 Item newitem = _recv_Item();
2607 _check_connection();
2608 _send_Line(
"RemoveStn");
2620 _check_connection();
2621 _send_Line(
"Add_TARGET");
2623 _send_Item(itemparent);
2624 _send_Item(itemrobot);
2625 Item newitem = _recv_Item();
2637 _check_connection();
2638 _send_Line(
"Add_FRAME");
2640 _send_Item(itemparent);
2641 Item newitem = _recv_Item();
2653 _check_connection();
2654 _send_Line(
"Add_PROG");
2656 _send_Item(itemrobot);
2657 Item newitem = _recv_Item();
2672 _check_connection();
2673 _send_Line(
"Add_MACHINING");
2675 _send_Item(itemrobot);
2676 Item newitem = _recv_Item();
2685 _check_connection();
2686 _send_Line(
"G_AllStn");
2687 int nstn = _recv_Int();
2688 QList<Item> *listStn =
new QList<Item>();
2689 for (
int i = 0;i < nstn;i++){
2690 Item station = _recv_Item();
2691 listStn->append(station);
2703 _check_connection();
2704 _send_Line(
"G_ActiveStn");
2705 Item station = _recv_Item();
2715 _check_connection();
2716 _send_Line(
"S_ActiveStn");
2717 _send_Item(station);
2729 return RunCode(function_w_params,
true);
2739 _check_connection();
2740 _send_Line(
"RunCode");
2741 _send_Int(code_is_fcn_call ? 1 : 0);
2743 int prog_status = _recv_Int();
2754 _check_connection();
2755 _send_Line(
"RunMessage");
2756 _send_Int(message_is_comment ? 1 : 0);
2757 _send_Line(message);
2766 bool auto_render = !always_render;
2767 _check_connection();
2768 _send_Line(
"Render");
2769 _send_Int(auto_render ? 1 : 0);
2779 _check_connection();
2780 _send_Line(
"Refresh");
2792 _check_connection();
2793 _send_Line(
"IsInside");
2794 _send_Item(object_inside);
2795 _send_Item(object_parent);
2796 int inside = _recv_Int();
2807 _check_connection();
2808 _send_Line(
"Collision_SetState");
2809 _send_Int(check_state);
2810 int ncollisions = _recv_Int();
2826 _check_connection();
2827 _send_Line(
"Collision_SetPair");
2832 _send_Int(check_state);
2833 int success = _recv_Int();
2843 _check_connection();
2844 _send_Line(
"Collisions");
2845 int ncollisions = _recv_Int();
2857 _check_connection();
2858 _send_Line(
"Collided");
2861 int ncollisions = _recv_Int();
2868 _check_connection();
2869 _send_Line(
"Collision Items");
2870 int nitems = _recv_Int();
2871 QList<Item> itemList = QList<Item>();
2872 if (!link_id_list.isEmpty()){
2873 link_id_list.clear();
2875 for (
int i = 0; i < nitems; i++){
2876 itemList.append(_recv_Item());
2877 int linkId = _recv_Int();
2878 if (!link_id_list.isEmpty()){
2879 link_id_list.append(linkId);
2881 int collisionTimes = _recv_Int();
2892 _check_connection();
2893 _send_Line(
"SimulateSpeed");
2894 _send_Int((
int)(speed * 1000.0));
2903 _check_connection();
2904 _send_Line(
"GetSimulateSpeed");
2905 double speed = ((double)_recv_Int()) / 1000.0;
2920 _check_connection();
2921 _send_Line(
"S_RunMode");
2922 _send_Int(run_mode);
2935 _check_connection();
2936 _send_Line(
"G_RunMode");
2937 int runmode = _recv_Int();
2948 _check_connection();
2949 _send_Line(
"G_Params");
2950 QList<QPair<QString,QString>> paramlist;
2951 int nparam = _recv_Int();
2952 for (
int i = 0; i < nparam; i++) {
2953 QString param = _recv_Line();
2954 QString value = _recv_Line();
2955 paramlist.append(qMakePair(param, value));
2973 _check_connection();
2974 _send_Line(
"G_Param");
2976 QString value = _recv_Line();
2977 if (value.startsWith(
"UNKNOWN ")) {
2992 _check_connection();
2993 _send_Line(
"S_Param");
3006 _check_connection();
3010 QString answer = _recv_Line();
3017 _check_connection();
3018 _send_Line(
"MeasLT");
3019 _send_XYZ(estimate);
3020 _send_Int(search ? 1 : 0);
3023 if (xyz[0]*xyz[0] + xyz[1]*xyz[1] + xyz[2]*xyz[2] < 0.0001){
3032 int nitems = qMin(itemList.length(),collidedList.length());
3033 if (robot_link_id !=
nullptr){
3034 nitems = qMin(nitems, robot_link_id->length());
3036 _check_connection();
3037 _send_Line(
"ShowAsCollidedList");
3039 for (
int i = 0; i < nitems; i++){
3040 _send_Item(itemList[i]);
3041 _send_Int(collidedList[i] ? 1 : 0);
3043 if (robot_link_id !=
nullptr){
3044 link_id = robot_link_id->at(i);
3065 _check_connection();
3066 _send_Line(
"CalibTCP2");
3067 _send_Matrix2D(poses_joints);
3069 _send_Int(algorithm);
3072 _recv_Array(tcp_xyz, &nxyz);
3073 if (error_stats !=
nullptr){
3074 _recv_Array(error_stats);
3076 double errors_ignored[20];
3077 _recv_Array(errors_ignored);
3080 _recv_Matrix2D(&error_graph);
3094 _check_connection();
3095 _send_Line(
"CalibFrame");
3096 _send_Matrix2D(poses_joints);
3097 _send_Int(use_joints ? -1 : 0);
3100 Mat reference_pose = _recv_Pose();
3101 double error_stats[20];
3102 _recv_Array(error_stats);
3104 return reference_pose;
3109 _check_connection();
3110 _send_Line(
"ProgramStart");
3111 _send_Line(progname);
3112 _send_Line(defaultfolder);
3113 _send_Line(postprocessor);
3115 int errors = _recv_Int();
3125 _check_connection();
3126 _send_Line(
"S_ViewPose");
3136 _check_connection();
3137 _send_Line(
"G_ViewPose");
3138 Mat pose = _recv_Pose();
3174 _check_connection();
3175 _send_Line(
"Cam2D_PtrAdd");
3176 _send_Item(item_object);
3177 _send_Item(cam_item);
3178 _send_Line(cam_params);
3179 Item cam_item_return = _recv_Item();
3181 return cam_item_return;
3184 _check_connection();
3185 _send_Line(
"Cam2D_PtrSnapshot");
3186 _send_Item(cam_item);
3187 _send_Line(file_save_img);
3189 _TIMEOUT = 3600 * 1000;
3190 int status = _recv_Int();
3191 _TIMEOUT = ROBODK_API_TIMEOUT;
3197 _check_connection();
3198 _send_Line(
"Cam2D_PtrSetParams");
3199 _send_Item(cam_item);
3201 int status = _recv_Int();
3208 _check_connection();
3209 _send_Line(
"Proj2d3d");
3212 int selection = _recv_Int();
3213 Item selectedItem = _recv_Item();
3216 if (xyzStation !=
nullptr){
3217 xyzStation[0] = xyz[0];
3218 xyzStation[1] = xyz[1];
3219 xyzStation[2] = xyz[2];
3222 return selectedItem;
3228 result.featureId = 0;
3229 result.points =
nullptr;
3235 _check_connection();
3236 _send_Line(
"G_ObjPoint");
3237 _send_Item(
nullptr);
3238 _send_Int(featureType);
3242 _recv_Matrix2D(&result.points);
3245 result.item = _recv_Item();
3247 result.featureType = _recv_Int();
3248 result.featureId = _recv_Int();
3249 result.featureName = _recv_Line();
3263 _check_connection();
3264 _send_Line(
"G_License");
3265 QString license = _recv_Line();
3275 _check_connection();
3276 _send_Line(
"G_Selection");
3277 int nitems = _recv_Int();
3278 QList<Item> list_items;
3279 for (
int i = 0; i < nitems; i++) {
3280 list_items.append(_recv_Item());
3291 _check_connection();
3292 _send_Line(
"S_Selection");
3293 _send_Int(list_items.length());
3294 for (
int i = 0; i < list_items.length(); i++) {
3295 _send_Item(list_items[i]);
3305 _check_connection();
3306 _send_Line(
"PluginLoad");
3307 _send_Line(pluginName);
3316 _check_connection();
3317 _send_Line(
"PluginCommand");
3318 _send_Line(pluginName);
3319 _send_Line(pluginCommand);
3320 _send_Line(pluginValue);
3321 QString result = _recv_Line();
3334 _check_connection();
3335 if (center ==
nullptr){
3336 _send_Line(
"Popup_ProgISO9283");
3338 _TIMEOUT = 3600 * 1000;
3339 iso_program = _recv_Item();
3340 _TIMEOUT = ROBODK_API_TIMEOUT;
3343 _send_Line(
"Popup_ProgISO9283_Param");
3346 values[0] = center[0];
3347 values[1] = center[1];
3348 values[2] = center[2];
3350 values[4] = blocking ? 1 : 0;
3351 _send_Array(values, 4);
3353 _TIMEOUT = 3600 * 1000;
3354 iso_program = _recv_Item();
3355 _TIMEOUT = ROBODK_API_TIMEOUT;
3365bool RoboDK::FileSet(
const QString &path_file_local,
const QString &file_remote,
bool load_file,
Item *attach_to){
3366 if (!_check_connection()){
return false; }
3367 if (!_send_Line(
"FileRecvBin")){
return false; }
3368 QFile file(path_file_local);
3369 if (!_send_Line(file_remote)){
return false; }
3370 int nbytes = file.size();
3371 if (!_send_Int(nbytes)){
return false; }
3372 if (!_send_Item(attach_to)){
return false; }
3373 if (!_send_Int(load_file ? 1 : 0)){
return false; }
3374 if (!_check_status()){
return false; }
3376 if (!file.open(QFile::ReadOnly)){
3380 QByteArray buffer(file.read(1024));
3381 if (buffer.size() == 0){
3385 sz_sent += _COM->write(buffer);
3386 qDebug() <<
"Sending file " << path_file_local << 100*sz_sent/nbytes;
3393 if (!_check_connection()){
return false; }
3394 if (!_send_Line(
"FileSendBin")){
return false; }
3395 if (!_send_Item(station)){
return false; }
3396 if (!_send_Line(path_file_remote)){
return false; }
3397 int nbytes = _recv_Int();
3398 int remaining = nbytes;
3399 QFile file(path_file_local);
3400 if (!file.open(QFile::WriteOnly)){
3401 qDebug() <<
"Can not open file for writting " << path_file_local;
3404 while (remaining > 0){
3405 QByteArray buffer(_COM->read(qMin(remaining, 1024)));
3406 remaining -= buffer.size();
3410 if (!_check_status()){
return false;}
3415bool RoboDK::EmbedWindow(QString window_name, QString docked_name,
int size_w,
int size_h, quint64 pid,
int area_add,
int area_allowed,
int timeout)
3417 if (!_check_connection()){
return false; }
3418 if (docked_name ==
"") {
3419 docked_name = window_name;
3421 _check_connection();
3422 _send_Line(
"WinProcDock");
3423 _send_Line(docked_name);
3424 _send_Line(window_name);
3425 double sizeArray[2] = {(double)size_w, (
double)size_h};
3426 _send_Array(sizeArray,2);
3427 _send_Line(QString::number(pid));
3428 _send_Int(area_allowed);
3429 _send_Int(area_add);
3431 int result = _recv_Int();
3437bool RoboDK::EventsListen()
3439 _COM_EVT =
new QTcpSocket();
3441 _COM_EVT->connectToHost(
"127.0.0.1", _PORT);
3443 _COM_EVT->connectToHost(_IP, _PORT);
3445 qDebug() << _COM_EVT->state();
3446 _COM_EVT->waitForConnected(_TIMEOUT);
3447 qDebug() << _COM_EVT->state();
3448 _send_Line(
"RDK_EVT", _COM_EVT);
3449 _send_Int(0, _COM_EVT);
3450 QString response = _recv_Line(_COM_EVT);
3451 qDebug() << response;
3452 int ver_evt = _recv_Int(_COM_EVT);
3453 int status = _recv_Int(_COM_EVT);
3454 if (response !=
"RDK_EVT" || status != 0)
3463bool RoboDK::WaitForEvent(
int &evt, Item &itm)
3465 evt = _recv_Int(_COM_EVT);
3466 itm = _recv_Item(_COM_EVT);
3471bool RoboDK::Event_Receive_3D_POS(
double *data,
int *valueCount) {
3472 return _recv_Array(data,valueCount,_COM_EVT);
3476bool RoboDK::Event_Receive_Mouse_data(
int *data) {
3477 data[0] = _recv_Int(_COM_EVT);
3478 data[1] = _recv_Int(_COM_EVT);
3479 data[2] = _recv_Int(_COM_EVT);
3484bool RoboDK::Event_Receive_Event_Moved(Mat *pose_rel_out) {
3485 int nvalues = _recv_Int(_COM_EVT);
3486 Mat pose_rel = _recv_Pose(_COM_EVT);
3487 *pose_rel_out = pose_rel;
3497bool RoboDK::Event_Connected()
3499 return _COM_EVT !=
nullptr && _COM_EVT->state() == QTcpSocket::ConnectedState;
3504bool RoboDK::_connected(){
3505 return _COM !=
nullptr && _COM->state() == QTcpSocket::ConnectedState;
3509bool RoboDK::_check_connection(){
3513 bool connection_ok = _connect_smart();
3517 return connection_ok;
3520bool RoboDK::_check_status(){
3521 qint32 status = _recv_Int();
3525 }
else if (status > 0 && status < 10) {
3526 QString strproblems(
"Unknown error");
3528 strproblems =
"Invalid item provided: The item identifier provided is not valid or it does not exist.";
3529 }
else if (status == 2) {
3530 strproblems = _recv_Line();
3531 qDebug() <<
"RoboDK API WARNING: " << strproblems;
3533 }
else if (status == 3){
3534 strproblems = _recv_Line();
3535 qDebug() <<
"RoboDK API ERROR: " << strproblems;
3536 }
else if (status == 9) {
3537 qDebug() <<
"Invalid RoboDK License";
3540 if (_USE_EXCPETIONS ==
true) {
3541 throw new std::exception(strproblems.toStdString().c_str(),status);
3543 }
else if (status < 100){
3544 QString strproblems = _recv_Line();
3545 qDebug() <<
"RoboDK API ERROR: " << strproblems;
3546 if (_USE_EXCPETIONS ==
true) {
3547 QString errorMessage = QString(
"RoboDK API ERROR: ") + strproblems;
3548 throw new std::exception(errorMessage.toStdString().c_str(),status);
3551 if (_USE_EXCPETIONS ==
true) {
3552 throw new std::exception(
"Communication problems with the RoboDK API",status);
3554 qDebug() <<
"Communication problems with the RoboDK API";
3561void RoboDK::_disconnect(){
3562 if (!_COM || !_OWN_SOCKET) {
3566 _COM->deleteLater();
3571bool RoboDK::_connect_smart(){
3574 qDebug() <<
"The RoboDK API is connected";
3583 qDebug() <<
"...Trying to start RoboDK: " << _ROBODK_BIN <<
" " << _ARGUMENTS;
3585 QProcess *p =
new QProcess();
3587 p->start(_ROBODK_BIN, _ARGUMENTS.split(
" ", Qt::SkipEmptyParts));
3588 p->setReadChannel(QProcess::StandardOutput);
3590 _PROCESS = p->processId();
3591 while (p->canReadLine() || p->waitForReadyRead(5000)){
3592 QString line = QString::fromUtf8(p->readLine().trimmed());
3594 if (line.contains(
"Running", Qt::CaseInsensitive)){
3595 qDebug() <<
"RoboDK is Running... Connecting API";
3596 bool is_connected = _connect();
3598 qDebug() <<
"The RoboDK API is connected";
3600 qDebug() <<
"The RoboDK API is NOT connected!";
3602 return is_connected;
3605 qDebug() <<
"Could not start RoboDK!";
3610bool RoboDK::_connect(){
3613 return _connected();
3617 _COM =
new QTcpSocket();
3619 _COM->connectToHost(
"127.0.0.1", _PORT);
3621 _COM->connectToHost(_IP, _PORT);
3624 if (!_COM->waitForConnected(_TIMEOUT)){
3625 _COM->deleteLater();
3631 _COM->write(ROBODK_API_START_STRING); _COM->write(ROBODK_API_LF, 1);
3632 _COM->write(
"1 0"); _COM->write(ROBODK_API_LF, 1);
3641 if (!_COM->canReadLine() && !_COM->waitForReadyRead(_TIMEOUT)){
3642 _COM->deleteLater();
3646 QString read(_COM->readAll());
3648 if (!read.startsWith(ROBODK_API_READY_STRING)){
3649 _COM->deleteLater();
3658bool RoboDK::_waitline(QAbstractSocket* com){
3659 if (com ==
nullptr) {
3662 if (com ==
nullptr){
return false; }
3663 while (!com->canReadLine()){
3664 if (!com->waitForReadyRead(_TIMEOUT)){
3670QString RoboDK::_recv_Line(QAbstractSocket* com){
3671 if (com ==
nullptr) {
3675 if (!_waitline(com)){
3676 if (com !=
nullptr){
3682 QByteArray line = _COM->readLine().trimmed();
3683 string.append(QString::fromUtf8(line));
3686bool RoboDK::_send_Line(
const QString&
string, QAbstractSocket* com){
3687 if (com ==
nullptr) {
3690 if (com ==
nullptr || !com->isOpen()){
return false; }
3691 com->write(
string.toUtf8());
3692 com->write(ROBODK_API_LF, 1);
3696int RoboDK::_recv_Int(QAbstractSocket* com){
3697 if (com ==
nullptr){
3701 if (com ==
nullptr){
return false; }
3702 if (com->bytesAvailable() <
sizeof(qint32)){
3703 com->waitForReadyRead(_TIMEOUT);
3704 if (com->bytesAvailable() <
sizeof(qint32)){
3708 QDataStream ds(com);
3712bool RoboDK::_send_Int(qint32 value, QAbstractSocket* com){
3713 if (com ==
nullptr) {
3716 if (com ==
nullptr || !com->isOpen()){
return false; }
3717 QDataStream ds(com);
3722Item RoboDK::_recv_Item(QAbstractSocket* com){
3723 if (com ==
nullptr) {
3727 if (com ==
nullptr){
return item; }
3730 if (com->bytesAvailable() <
sizeof(quint64)){
3731 com->waitForReadyRead(_TIMEOUT);
3732 if (com->bytesAvailable() <
sizeof(quint64)){
3736 QDataStream ds(com);
3741bool RoboDK::_send_Item(
const Item *item){
3742 if (_COM ==
nullptr || !_COM->isOpen()){
return false; }
3743 QDataStream ds(_COM);
3745 if (item !=
nullptr){
3751bool RoboDK::_send_Item(
const Item &item){
3752 return _send_Item(&item);
3755Mat RoboDK::_recv_Pose(QAbstractSocket* com){
3756 if (com ==
nullptr) {
3761 if (com ==
nullptr){
return pose; }
3762 int size = 16*
sizeof(double);
3763 if (com->bytesAvailable() < size){
3764 com->waitForReadyRead(_TIMEOUT);
3765 if (com->bytesAvailable() < size){
3769 QDataStream ds(com);
3770 ds.setFloatingPointPrecision(QDataStream::DoublePrecision);
3773 for (
int j=0; j<4; j++){
3774 for (
int i=0; i<4; i++){
3776 pose.Set(i,j,valuei);
3782bool RoboDK::_send_Pose(
const Mat &pose){
3783 if (_COM ==
nullptr || !_COM->isOpen()){
return false; }
3784 QDataStream ds(_COM);
3785 ds.setFloatingPointPrecision(QDataStream::DoublePrecision);
3788 for (
int j=0; j<4; j++){
3789 for (
int i=0; i<4; i++){
3790 valuei = pose.Get(i,j);
3796bool RoboDK::_recv_XYZ(
tXYZ pos){
3797 if (_COM ==
nullptr){
return false; }
3798 int size = 3*
sizeof(double);
3799 if (_COM->bytesAvailable() < size){
3800 _COM->waitForReadyRead(_TIMEOUT);
3801 if (_COM->bytesAvailable() < size){
3805 QDataStream ds(_COM);
3806 ds.setFloatingPointPrecision(QDataStream::DoublePrecision);
3809 for (
int i=0; i<3; i++){
3815bool RoboDK::_send_XYZ(
const tXYZ pos){
3816 if (_COM ==
nullptr || !_COM->isOpen()){
return false; }
3817 QDataStream ds(_COM);
3818 ds.setFloatingPointPrecision(QDataStream::DoublePrecision);
3821 for (
int i=0; i<3; i++){
3827bool RoboDK::_recv_Array(tJoints *jnts){
3828 return _recv_Array(jnts->_Values, &(jnts->_nDOFs));
3830bool RoboDK::_send_Array(
const tJoints *jnts){
3831 if (jnts ==
nullptr){
3832 return _send_Int(0);
3834 return _send_Array(jnts->_Values, jnts->_nDOFs);
3836bool RoboDK::_send_Array(
const Mat *mat){
3837 if (mat ==
nullptr){
3838 return _send_Int(0);
3841 for (
int c=0; c<4; c++){
3842 for (
int r=0; r<4; r++){
3843 m44[c*4+r] = mat->Get(r,c);
3846 return _send_Array(m44, 16);
3848bool RoboDK::_recv_Array(
double *values,
int *psize, QAbstractSocket* com){
3849 if (com ==
nullptr) {
3852 int nvalues = _recv_Int();
3853 if (com ==
nullptr || nvalues < 0) {
return false;}
3854 if (psize !=
nullptr){
3857 if (nvalues < 0 || nvalues > 50){
return false;}
3858 int size = nvalues*
sizeof(double);
3859 if (com->bytesAvailable() < size){
3860 com->waitForReadyRead(_TIMEOUT);
3861 if (com->bytesAvailable() < size){
3865 QDataStream ds(com);
3866 ds.setFloatingPointPrecision(QDataStream::DoublePrecision);
3869 for (
int i=0; i<nvalues; i++){
3876bool RoboDK::_send_Array(
const double *values,
int nvalues){
3877 if (_COM ==
nullptr || !_COM->isOpen()){
return false; }
3878 if (!_send_Int((qint32)nvalues)){
return false; }
3879 QDataStream ds(_COM);
3880 ds.setFloatingPointPrecision(QDataStream::DoublePrecision);
3883 for (
int i=0; i<nvalues; i++){
3890bool RoboDK::_recv_Matrix2D(tMatrix2D **mat){
3891 qint32 dim1 = _recv_Int();
3892 qint32 dim2 = _recv_Int();
3895 if (dim1 < 0 || dim2 < 0){
return false; }
3897 if (dim1*dim2 <= 0){
3904 int remaining = dim1*dim2 - count;
3905 if (remaining <= 0){
return true; }
3906 if (_COM->bytesAvailable() <= 0 && !_COM->waitForReadyRead(_TIMEOUT)){
3910 buffer.append(_COM->read(remaining *
sizeof(
double) - buffer.size()));
3911 int np = buffer.size() /
sizeof(double);
3912 QDataStream indata(buffer);
3913 indata.setFloatingPointPrecision(QDataStream::DoublePrecision);
3914 for (
int i=0; i<np; i++){
3916 (*mat)->data[count] = value;
3919 buffer = buffer.mid(np *
sizeof(
double));
3923bool RoboDK::_send_Matrix2D(tMatrix2D *mat){
3924 if (_COM ==
nullptr || !_COM->isOpen()){
return false; }
3925 QDataStream ds(_COM);
3926 ds.setFloatingPointPrecision(QDataStream::DoublePrecision);
3930 bool ok1 = _send_Int(dim1);
3931 bool ok2 = _send_Int(dim2);
3932 if (!ok1 || !ok2) {
return false; }
3934 for (
int j=0; j<dim2; j++){
3935 for (
int i=0; i<dim1; i++){
3943bool RoboDK::_send_Bytes(
const QByteArray &data, QAbstractSocket *com) {
3947 if (!com || !com->isOpen()) {
3952 QDataStream ds(com);
3959QByteArray RoboDK::_recv_Bytes(QAbstractSocket* com) {
3963 if (!com || !com->isOpen()) {
3964 return QByteArray();
3967 int size = _recv_Int(com);
3969 while (com->bytesAvailable() < size) {
3970 if (!com->waitForReadyRead(_TIMEOUT)) {
3971 return QByteArray();
3975 return com->read(size);
3979void RoboDK::_moveX(
const Item *target,
const tJoints *joints,
const Mat *mat_target,
const Item *itemrobot,
int movetype,
bool blocking){
3980 itemrobot->WaitMove();
3981 _send_Line(
"MoveX");
3982 _send_Int(movetype);
3983 if (target !=
nullptr){
3985 _send_Array((tJoints*)
nullptr);
3987 }
else if (joints !=
nullptr){
3989 _send_Array(joints);
3990 _send_Item(
nullptr);
3991 }
else if (mat_target !=
nullptr){
3993 _send_Array(mat_target);
3994 _send_Item(
nullptr);
3996 if (_USE_EXCPETIONS ==
true) {
3997 throw new std::exception(
"Invalid target type");
4001 _send_Item(itemrobot);
4004 itemrobot->WaitMove();
4008void RoboDK::_moveC(
const Item *target1,
const tJoints *joints1,
const Mat *mat_target1,
const Item *target2,
const tJoints *joints2,
const Mat *mat_target2,
const Item *itemrobot,
bool blocking){
4009 itemrobot->WaitMove();
4010 _send_Line(
"MoveC");
4012 if (target1 !=
nullptr){
4014 _send_Array((tJoints*)
nullptr);
4015 _send_Item(target1);
4016 }
else if (joints1 !=
nullptr) {
4018 _send_Array(joints1);
4019 _send_Item(
nullptr);
4020 }
else if (mat_target1 !=
nullptr){
4022 _send_Array(mat_target1);
4023 _send_Item(
nullptr);
4025 if (_USE_EXCPETIONS ==
true) {
4026 throw new std::exception(
"Invalid type of target 1");
4030 if (target2 !=
nullptr) {
4032 _send_Array((tJoints*)
nullptr);
4033 _send_Item(target2);
4034 }
else if (joints2 !=
nullptr) {
4036 _send_Array(joints2);
4037 _send_Item(
nullptr);
4038 }
else if (mat_target2 !=
nullptr){
4040 _send_Array(mat_target2);
4041 _send_Item(
nullptr);
4043 if (_USE_EXCPETIONS ==
true) {
4044 throw new std::exception(
"Invalid type of target 2");
4048 _send_Item(itemrobot);
4051 itemrobot->WaitMove();
4076void emxInit_real_T(tMatrix2D **pEmxArray,
int numDimensions)
4078 tMatrix2D *emxArray;
4080 *pEmxArray = (tMatrix2D *)malloc(
sizeof(tMatrix2D));
4081 emxArray = *pEmxArray;
4082 emxArray->data = (
double *)NULL;
4083 emxArray->numDimensions = numDimensions;
4084 emxArray->size = (
int *)malloc((
unsigned int)(
sizeof(int) * numDimensions));
4085 emxArray->allocatedSize = 0;
4086 emxArray->canFreeData =
true;
4087 for (i = 0; i < numDimensions; i++) {
4088 emxArray->size[i] = 0;
4094 emxInit_real_T((
tMatrix2D**)(&matrix), 2);
4099void emxFree_real_T(tMatrix2D **pEmxArray){
4100 if (*pEmxArray != (tMatrix2D *)NULL) {
4101 if (((*pEmxArray)->data != (
double *)NULL) && (*pEmxArray)->canFreeData) {
4102 free((
void *)(*pEmxArray)->data);
4104 free((
void *)(*pEmxArray)->size);
4105 free((
void *)*pEmxArray);
4106 *pEmxArray = (tMatrix2D *)NULL;
4116void emxEnsureCapacity(tMatrix2D *emxArray,
int oldNumel,
unsigned int elementSize){
4124 for (i = 0; i < emxArray->numDimensions; i++) {
4125 newNumel *= emxArray->size[i];
4127 if (newNumel > emxArray->allocatedSize) {
4128 i = emxArray->allocatedSize;
4132 while (i < newNumel) {
4133 if (i > 1073741823) {
4139 newData = (
double*) calloc((
unsigned int)i, elementSize);
4140 if (emxArray->data != NULL) {
4141 memcpy(newData, emxArray->data, elementSize * oldNumel);
4142 if (emxArray->canFreeData) {
4143 free(emxArray->data);
4146 emxArray->data = newData;
4147 emxArray->allocatedSize = i;
4148 emxArray->canFreeData =
true;
4155 old_numel = mat->
size[0] * mat->
size[1];
4156 mat->
size[0] = rows;
4157 mat->
size[1] = cols;
4159 emxEnsureCapacity(mat, old_numel,
sizeof(
double));
4167 return var->
size[dim - 1];
4180 return var->
data[var->
size[0] * j + i];
4182void Matrix2D_SET_ij(
const tMatrix2D *var,
int i,
int j,
double value) {
4183 var->data[var->size[0] * j + i] = value;
4187 return (var->
data + var->
size[0] * col);
4191void Matrix2D_Add(tMatrix2D *var,
const double *array,
int numel){
4193 int size1 = var->size[0];
4194 int size2 = var->size[1];
4195 oldnumel = size1*size2;
4196 var->size[1] = size2 + 1;
4197 emxEnsureCapacity(var, oldnumel, (
int)
sizeof(
double));
4198 numel = qMin(numel, size1);
4199 for (
int i=0; i<numel; i++){
4200 var->data[size1*size2 + i] = array[i];
4204void Matrix2D_Add(tMatrix2D *var,
const tMatrix2D *varadd){
4206 int size1 = var->size[0];
4207 int size2 = var->size[1];
4208 int size1_ap = varadd->size[0];
4209 int size2_ap = varadd->size[1];
4210 int numel = size1_ap*size2_ap;
4211 if (size1 != size1_ap){
4214 oldnumel = size1*size2;
4215 var->size[1] = size2 + size2_ap;
4216 emxEnsureCapacity(var, oldnumel, (
int)
sizeof(
double));
4217 for (
int i=0; i<numel; i++){
4218 var->data[size1*size2 + i] = varadd->data[i];
4224 for (i = 0; i < arraysize; i++) {
4228 printf(
"%.3f", array[i]);
4229 if (i < arraysize - 1) {
4243 printf(
"Matrix size = [%i, %i]\n", size1, size2);
4245 for (j = 0; j<size2; j++) {
4278#ifndef RDK_SKIP_NAMESPACE
The Item class represents an item in RoboDK station. An item can be a robot, a frame,...
Item ObjectLink(int link_id=0)
Returns an item pointer to the geometry of a robot link. This is useful to show/hide certain robot li...
int RunInstruction(const QString &code, int run_type=RoboDK::INSTRUCTION_CALL_PROGRAM)
Adds a program call, code, message or comment inside a program.
RoboDK * RDK()
Returns the RoboDK link Robolink().
Mat GeometryPose()
Returns the position (pose) the object geometry with respect to its own reference frame....
Item getLink(int type_linked=RoboDK::ITEM_TYPE_ROBOT)
Returns an item linked to a robot, object, tool, program or robot machining project....
Item setMachiningParameters(QString ncfile="", Item part_obj=nullptr, QString options="")
Update the robot milling path input and parameters. Parameter input can be an NC file (G-code or APT ...
void Stop()
Stops a program or a robot.
void MoveC(const Item &itemtarget1, const Item &itemtarget2, bool blocking=true)
Moves a robot to a specific target ("Move Circular" mode). By default, this function blocks until the...
tMatrix2D * SolveIK_All_Mat2D(const Mat &pose, const Mat *tool=nullptr, const Mat *ref=nullptr)
Computes the inverse kinematics for the specified robot and pose. The function returns all available ...
void setRunType(int program_run_type)
Sets if the program will be run in simulation mode or on the real robot. Use: "PROGRAM_RUN_ON_SIMULAT...
void setSpeed(double speed_linear, double accel_linear=-1, double speed_joints=-1, double accel_joints=-1)
Sets the speed and/or the acceleration of a robot.
int InstructionList(tMatrix2D *instructions)
Returns the list of program instructions as an MxN matrix, where N is the number of instructions and ...
void NewLink()
Create a new communication link for RoboDK. Use this for robots if you use a multithread application ...
Mat SolveFK(const tJoints &joints, const Mat *tool=nullptr, const Mat *ref=nullptr)
Computes the forward kinematics of the robot for the provided joints. The tool and the reference fram...
bool Connect(const QString &robot_ip="")
Connect to a real robot using the corresponding robot driver.
void setPoseTool(const Mat tool_pose)
Sets the tool of a robot or a tool object (Tool Center Point, or TCP). The tool pose can be either an...
void setJoints(const tJoints &jnts)
Set robot joints or the joints of a target.
bool Valid(bool check_pointer=false) const
Check if an item is valid (not null and available in the open station)
void Instruction(int ins_id, QString &name, int &instype, int &movetype, bool &isjointtarget, Mat &target, tJoints &joints)
Returns the program instruction at position id.
void setAccuracyActive(int accurate=1)
Sets the accuracy of the robot active or inactive. A robot must have been calibrated to properly use ...
Mat Pose() const
Returns the local position (pose) of an object, target or reference frame. For example,...
void setColor(double colorRGBA[4])
Changes the color of a robot/object/tool. A color must must in the format COLOR=[R,...
bool SelectedFeature(int &featureType, int &featureId)
Retrieve the currently selected feature for this object.
int Type() const
Item type (object, robot, tool, reference, robot machining project, ...)
void customInstruction(const QString &name, const QString &path_run, const QString &path_icon="", bool blocking=true, const QString &cmd_run_on_robot="")
Add a custom instruction. This instruction will execute a Python file or an executable file.
void setDO(const QString &io_var, const QString &io_value)
Sets a variable (output) to a given value. This can also be used to set any variables to a desired va...
void setPose(const Mat pose)
Sets the local position (pose) of an object, target or reference frame. For example,...
void setGeometryPose(const Mat pose)
Sets the position (pose) the object geometry with respect to its own reference frame....
bool Busy()
Checks if a robot or program is currently running (busy or moving)
void setAsJointTarget()
Sets a target as a joint target. A joint target moves to a joints position without regarding the cart...
int RunCode(const QString ¶meters)
Runs a program. It returns the number of instructions that can be executed successfully (a quick prog...
Mat PoseTool()
Returns the tool pose of an item. If a robot is provided it will get the tool pose of the active tool...
bool Disconnect()
Disconnect from a real robot (when the robot driver is used)
void setRobot(const Item &robot)
Sets the robot of a program or a target. You must set the robot linked to a program or a target every...
void setPoseAbs(const Mat pose)
Sets the global position (pose) of an item. For example, the position of an object/frame/target with ...
void setJointsHome(const tJoints &jnts)
Set robot joints for the home position.
void setParent(Item parent)
Attaches the item to a new parent while maintaining the relative position with its parent....
void setPoseFrame(const Mat frame_pose)
Sets the reference frame of a robot(user frame). The frame can be either an item or a pose....
void setRounding(double zonedata)
Sets the robot movement smoothing accuracy (also known as zone data value).
void JointsConfig(const tJoints &joints, tConfig config)
Returns the robot configuration state for a set of robot joints.
void setParentStatic(Item parent)
Attaches the item to another parent while maintaining the current absolute position in the station....
int InstructionListJoints(QString &error_msg, tMatrix2D **joint_list, double mm_step=10.0, double deg_step=5.0, const QString &save_to_file="", bool collision_check=false, int flags=0, double time_step_s=0.1)
Returns a list of joints an MxN matrix, where M is the number of robot axes plus 4 columns....
void ShowTargets(bool visible=true)
Show or hide targets of a program in the RoboDK tree.
tJoints Joints() const
Returns the current joints of a robot or the joints of a target. If the item is a cartesian target,...
void WaitMove(double timeout_sec=300) const
Waits (blocks) until the robot finishes its movement.
Mat PoseFrame()
Returns the reference frame pose of an item. If a robot is provided it will get the tool pose of the ...
Mat PoseAbs()
Returns the global position (pose) of an item. For example, the position of an object/frame/target wi...
QByteArray getParam(const QString ¶m)
Get a specific binary item parameter.
RoboDK * _RDK
Pointer to RoboDK link object.
QList< tJoints > SolveIK_All(const Mat &pose, const Mat *tool=nullptr, const Mat *ref=nullptr)
Computes the inverse kinematics for the specified robot and pose. The function returns all available ...
bool isJointTarget() const
Returns True if a target is a joint target (green icon). Otherwise, the target is a Cartesian target ...
quint64 _PTR
Pointer to the item inside RoboDK.
void MoveJ(const Item &itemtarget, bool blocking=true)
Moves a robot to a specific target ("Move Joint" mode). By default, this function blocks until the ro...
QList< Item > Childs() const
Returns a list of the item childs that are attached to the provided item.
int InstructionCount()
Returns the number of instructions of a program.
void setName(const QString &name)
Set the name of a RoboDK item.
double Update(int collision_check=RoboDK::COLLISION_OFF, int timeout_sec=3600, double *out_nins_time_dist=nullptr, double mm_step=-1, double deg_step=-1)
Updates a program and returns the estimated time and the number of valid instructions....
void Save(const QString &filename)
Save a station, a robot, a tool or an object to a file.
void Pause(double time_ms=-1)
Generates a pause instruction for a robot or a program when generating code. Set it to -1 (default) i...
tJoints JointsHome() const
Returns the home joints of a robot. These joints can be manually set in the robot "Parameters" menu,...
Item AttachClosest()
Attach the closest object to the tool. Returns the item that was attached.
void DetachAll(Item parent)
Detach any object attached to a tool.
void ShowInstructions(bool visible=true)
Show or hide instruction items of a program in the RoboDK tree.
void setAO(const QString &io_var, const QString &io_value)
Set an analog Output.
void JointLimits(tJoints *lower_limits, tJoints *upper_limits)
Retrieve the joint limits of a robot.
bool Visible() const
Returns 1 if the item is visible, otherwise, returns 0.
bool MakeProgram(const QString &filename)
Saves a program to a file.
void Delete()
Deletes an item and its childs from the station.
void waitDI(const QString &io_var, const QString &io_value, double timeout_ms=-1)
Waits for an input io_id to attain a given value io_value. Optionally, a timeout can be provided.
QString getDI(const QString &io_var)
Get a Digital Input (DI). This function is only useful when connected to a real robot using the robot...
void setVisible(bool visible, int visible_frame=-1)
Sets the item visiblity status.
void MoveL(const Item &itemtarget, bool blocking=true)
Moves a robot to a specific target ("Move Linear" mode). By default, this function blocks until the r...
QString setParam(const QString ¶m, const QString &value)
Set a specific item parameter. Select Tools-Run Script-Show Commands to see all available commands fo...
int RunProgram()
Runs a program. It returns the number of instructions that can be executed successfully (a quick prog...
GetPointsResult GetPoints(int featureType=RoboDK::FEATURE_SURFACE, int featureId=0)
Retrieves the point under the mouse cursor, a curve or the 3D points of an object....
void setAsCartesianTarget()
Sets a target as a cartesian target. A cartesian target moves to cartesian coordinates.
void ShowSequence(tMatrix2D *sequence)
Displays a sequence of joints.
int MoveL_Test(const tJoints &joints1, const Mat &pose2, double minstep_mm=-1)
Checks if a linear movement is free of issues and, optionally, collisions.
QString Name() const
Returns the name of an item. The name of the item is always displayed in the RoboDK station tree.
bool Finish()
Disconnect from the RoboDK API. This flushes any pending program generation.
Item AddTool(const Mat &tool_pose, const QString &tool_name="New TCP")
Adds an empty tool to the robot provided the tool pose (4x4 Matrix) and the tool name.
tJoints SolveIK(const Mat &pose, const Mat *tool=nullptr, const Mat *ref=nullptr)
Computes the inverse kinematics for the specified robot and pose. The joints returned are the closest...
quint64 GetID()
Get the item pointer.
void Scale(double scale)
Apply a scale to an object to make it bigger or smaller. The scale can be uniform (if scale is a floa...
int MoveJ_Test(const tJoints &j1, const tJoints &j2, double minstep_deg=-1)
Checks if a joint movement is possible and, optionally, free of collisions.
void setInstruction(int ins_id, const QString &name, int instype, int movetype, bool isjointtarget, const Mat &target, const tJoints &joints)
Sets the program instruction at position id.
QString getAI(const QString &io_var)
Get an Analog Input (AI). This function is only useful when connected to a real robot using the robot...
Item DetachClosest(Item parent)
Detach the closest object attached to the tool (see also setParentStatic).
void setJointLimits(const tJoints &lower_limits, const tJoints &upper_limits)
Set the joint limits of a robot.
Item Parent() const
Return the parent item of this item.
The Mat class represents a 4x4 pose matrix. The main purpose of this object is to represent a pose in...
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 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.
QString ToString(const QString &separator=", ", int precision=3, bool xyzwpr_only=false) const
Retrieve a string representation of the pose.
bool FromString(const QString &str)
Set the matrix given a XYZRPW string array (6-values)
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.
bool _valid
Flags if a matrix is not valid.
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 ...
This class is the iterface to the RoboDK API. With the RoboDK API you can automate certain tasks and ...
void setViewPose(const Mat &pose)
Set the pose of the wold reference frame with respect to the user view (camera/screen).
void setSimulationSpeed(double speed)
Sets the current simulation speed. Set the speed to 1 for a real-time simulation. The slowest speed a...
@ ITEM_TYPE_PROGRAM
Program item.
Item getItem(QString name, int itemtype=-1)
Returns an item by its name. If there is no exact match it will return the last closest match.
Item Paste(const Item *paste_to=nullptr)
Paste the copied item as a dependency of another item (same as Ctrl+V). Paste should be used after Co...
QList< Item > getCollisionItems(QList< int > link_id_list)
Return the list of items that are in a collision state. This function can be used after calling Colli...
void CloseRoboDK()
Closes RoboDK window and finishes RoboDK execution.
QString Command(const QString &cmd, const QString &value="")
Send a special command. These commands are meant to have a specific effect in RoboDK,...
void ShowMessage(const QString &message, bool popup=true)
Show a message in RoboDK (it can be blocking or non blocking in the status bar)
Item AddPoints(tMatrix2D *points, Item *referenceObject=nullptr, bool addToRef=false, int ProjectionType=PROJECTION_ALONG_NORMAL_RECALC)
Adds a list of points to an object. The provided points must be a list of vertices....
int RunCode(const QString &code, bool code_is_fcn_call=false)
Adds code to run in the program output. If the program exists it will also run the program in simulat...
bool LaserTrackerMeasure(tXYZ xyz, tXYZ estimate, bool search=false)
Takes a laser tracker measurement with respect to its own reference frame. If an estimate point is pr...
int Collision(Item item1, Item item2)
Returns 1 if item1 and item2 collided. Otherwise returns 0.
void Save(const QString &filename, const Item *itemsave=nullptr)
Save an item to a file. If no item is provided, the open station is saved.
bool IsInside(Item object_inside, Item object_parent)
Check if an object is fully inside another one.
QString License()
Returns the license as a readable string (same name shown in the RoboDK's title bar,...
void setRunMode(int run_mode=1)
Sets the behavior of the RoboDK API. By default, RoboDK shows the path simulation for movement instru...
void PluginLoad(const QString &pluginName, int load=1)
Load or unload the specified plugin (path to DLL, dylib or SO file). If the plugin is already loaded ...
QString Version()
Return the vesion of RoboDK as a 4 digit string: Major.Minor.Revision.Build.
Item AddFile(const QString &filename, const Item *parent=nullptr)
Loads a file and attaches it to parent. It can be any file supported by RoboDK.
Item AddStation(const QString &name)
Add a new empty station. It returns the station item added.
void ShowAsCollided(QList< Item > itemList, QList< bool > collidedList, QList< int > *robot_link_id=nullptr)
Show a list of items as collided.
bool setCollisionActivePair(int check_state, Item item1, Item item2, int id1=0, int id2=0)
Set collision checking ON or OFF (COLLISION_ON/COLLISION_OFF) for a specific pair of objects....
bool FileGet(const QString &path_file_local, Item *station=nullptr, const QString path_file_remote="")
Retrieve a file from the RoboDK running instance.
int RunMode()
Returns the behavior of the RoboDK API. By default, RoboDK shows the path simulation for movement ins...
Item getActiveStation()
Returns the active station item (station currently visible).
QList< QPair< QString, QString > > getParams()
Gets all the user parameters from the open RoboDK station. The parameters can also be modified by rig...
void ShowRoboDK()
Shows or raises the RoboDK window.
void CalibrateTool(tMatrix2D *poses_joints, tXYZ tcp_xyz, int format=EULER_RX_RY_RZ, int algorithm=CALIBRATE_TCP_BY_POINT, Item *robot=nullptr, double *error_stats=nullptr)
Calibrate a tool (TCP) given a number of points or calibration joints. Important: If the robot is cal...
void Disconnect()
Disconnect from the RoboDK API. This flushes any pending program generation.
Item Popup_ISO9283_CubeProgram(Item *robot=nullptr, tXYZ center=nullptr, double side=-1, bool blocking=true)
Show the popup menu to create the ISO9283 path for position accuracy, repeatability and path accuracy...
int setCollisionActive(int check_state=COLLISION_ON)
Turn collision checking ON or OFF (COLLISION_OFF/COLLISION_OFF) according to the collision map....
Item getCursorXYZ(int x=-1, int y=-1, tXYZ xyzStation=nullptr)
Returns the position of the cursor as XYZ coordinates (by default), or the 3D position of a given set...
Mat ViewPose()
Get the pose of the wold reference frame with respect to the user view (camera/screen).
Item ItemUserPick(const QString &message="Pick one item", int itemtype=-1)
Shows a RoboDK popup to select one object from the open RoboDK station. An item type can be specified...
Item AddTarget(const QString &name, Item *itemparent=nullptr, Item *itemrobot=nullptr)
Adds a new target that can be reached with a robot.
void setSelection(QList< Item > list_items)
Sets the selection in the tree (it can be one or more items).
QList< Item > Selection()
Returns the list of items selected (it can be one or more items).
Item AddMachiningProject(const QString &name="Curve follow settings", Item *itemrobot=nullptr)
Add a new robot machining project. Machining projects can also be used for 3D printing,...
Item AddCurve(tMatrix2D *curvePoints, Item *referenceObject=nullptr, bool addToRef=false, int ProjectionType=PROJECTION_ALONG_NORMAL_RECALC)
Adds a curve provided point coordinates. The provided points must be a list of vertices....
Item AddProgram(const QString &name, Item *itemrobot=nullptr)
Adds a new Frame that can be referenced by a robot.
int Cam2D_Snapshot(const QString &file_save_img, const Item &cam_item, const QString ¶ms="")
Take a snapshot of a simulated camera and save it as an image.
QList< Item > getOpenStation()
Returns the list of open stations in RoboDK.
int RunProgram(const QString &function_w_params)
Adds a function call in the program output. RoboDK will handle the syntax when the code is generated ...
int ProgramStart(const QString &progname, const QString &defaultfolder="", const QString &postprocessor="", Item *robot=nullptr)
Defines the name of the program when the program is generated. It is also possible to specify the nam...
QList< Item > getItemList(int filter=-1)
Returns a list of items (list of names or pointers) of all available items in the currently open stat...
int Cam2D_SetParams(const QString &cam_params, const Item &cam_item)
Set the camera parameters.
Mat CalibrateReference(tMatrix2D *poses_joints, int method=CALIBRATE_FRAME_3P_P1_ON_X, bool use_joints=false, Item *robot=nullptr)
Calibrate a Reference Frame given a list of points or joint values. Important: If the robot is calibr...
void RunMessage(const QString &message, bool message_is_comment=false)
Shows a message or a comment in the output robot program.
@ FEATURE_HOVER_OBJECT_MESH
Object mesh (under the mouse cursor) feature type flag.
@ FEATURE_NONE
No selection.
Item AddFrame(const QString &name, Item *itemparent=nullptr)
Adds a new Frame that can be referenced by a robot.
int getFlagsItem(Item item)
Retrieve current item flags. Item flags allow defining how much access the user has to item-specific ...
void setActiveStation(Item stn)
Set the active station (project currently visible).
Item AddShape(tMatrix2D *trianglePoints, Item *addTo=nullptr, bool shapeOverride=false, Color *color=nullptr)
Adds a shape provided triangle coordinates. Triangles must be provided as a list of vertices....
Item Cam2D_Add(const Item &item_object, const QString &cam_params, const Item *cam_item=nullptr)
Add a simulated 2D or depth camera as an item. Use Delete to delete it.
QStringList getItemListNames(int filter=-1)
Returns a list of items (list of names or Items) of all available items in the currently open station...
void setWindowState(int windowstate=WINDOWSTATE_NORMAL)
Set the state of the RoboDK window.
QString PluginCommand(const QString &pluginName, const QString &pluginCommand, const QString &pluginValue="")
Send a specific command to a RoboDK plugin. The command and value (optional) must be handled by your ...
void HideRoboDK()
Hides the RoboDK window. RoboDK will continue running in the background.
@ INS_TYPE_MOVE
Linear or joint movement instruction.
int Collisions()
Returns the number of pairs of objects that are currently in a collision state.
void Copy(const Item &tocopy)
Makes a copy of an item (same as Ctrl+C), which can be pasted (Ctrl+V) using Paste().
void CloseStation()
Close the current station without asking to save.
GetPointsResult GetPoints(int featureType=FEATURE_HOVER_OBJECT_MESH)
Retrieves the object under the mouse cursor.
void setParam(const QString ¶m, const QString &value)
Sets a global parameter from the RoboDK station. If the parameters exists, it will be modified....
void Update()
Update the screen. This updates the position of all robots and internal links according to previously...
QString getParam(const QString ¶m)
Gets a global or a user parameter from the open RoboDK station. The parameters can also be modified b...
void ProjectPoints(tMatrix2D *points, tMatrix2D **projected, Item objectProject, int ProjectionType=PROJECTION_ALONG_NORMAL_RECALC)
Projects a point given its coordinates. The provided points must be a list of [XYZ] coordinates....
void setFlagsRoboDK(int flags=FLAG_ROBODK_ALL)
Update the RoboDK flags. RoboDK flags allow defining how much access the user has to certain RoboDK f...
void Finish()
Disconnect from the RoboDK API. This flushes any pending program generation.
void setFlagsItem(Item item, int flags=FLAG_ITEM_ALL)
Update item flags. Item flags allow defining how much access the user has to item-specific features....
void Render(bool always_render=false)
Update the scene.
double SimulationSpeed()
Gets the current simulation speed. Set the speed to 1 for a real-time simulation.
bool FileSet(const QString &file_local, const QString &file_remote="", bool load_file=true, Item *attach_to=nullptr)
Send file from the current location to the RoboDK instance.
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.
bool Valid() const
Check if the joints are valid. For example, when we request the Inverse kinematics and there is no so...
int Length() const
Number of joint axes of the robot (or degrees of freedom)
const double * Values() const
Joint values.
int _nDOFs
number of degrees of freedom
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...
All RoboDK API functions are wrapped in the RoboDK_API namespace. If you prefer to forget about the R...
double * Matrix2D_Get_col(const tMatrix2D *var, int col)
Returns the pointer of a column of a tMatrix2D. A column has Matrix2D_Get_nrows values that can be ac...
tMatrix2D * Matrix2D_Create()
Creates a new 2D matrix tMatrix2D.. Use Matrix2D_Delete to delete the matrix (to free the memory)....
Mat roty(double ry)
Translation matrix class: Mat::roty.
int Matrix2D_Get_ncols(const tMatrix2D *var)
Returns the number of columns of a tMatrix2D.
double Matrix2D_Get_ij(const tMatrix2D *var, int i, int j)
Returns the value at location [i,j] of a tMatrix2D.
Mat rotz(double rz)
Translation matrix class: Mat::rotz.
double tConfig[RDK_SIZE_MAX_CONFIG]
The robot configuration defines a specific state of the robot without crossing any singularities....
Mat transl(double x, double y, double z)
Translation matrix class: Mat::transl.
void Matrix2D_Set_Size(tMatrix2D *mat, int rows, int cols)
Sets the size of a tMatrix2D.
int Matrix2D_Size(const tMatrix2D *var, int dim)
Sets the size of a tMatrix2D.
void Debug_Matrix2D(const tMatrix2D *emx)
Display the content of a tMatrix2D through STDOUT. This is only intended for debug purposes.
Mat rotx(double rx)
Translation matrix class: Mat::rotx.
double tXYZ[3]
tXYZ (mm) represents a position or a vector in mm
int Matrix2D_Get_nrows(const tMatrix2D *var)
Returns the number of rows of a tMatrix2D.
void Debug_Array(const double *array, int arraysize)
Show an array through STDOUT Given an array of doubles, it generates a string.
void Matrix2D_Delete(tMatrix2D **mat)
Deletes a tMatrix2D.
double tXYZWPR[6]
Six doubles that represent robot joints (usually in degrees)
The Color struct represents an RGBA color (each color component should be in the range [0-1])
float a
Alpha value (0 = transparent; 1 = opaque)
The GetPointsResult method represents the results of executing the GetPoints function.
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 numDimensions
Number of dimensions (usually 2)