From f5bd78782094a04c5c0f9c678580e5f799a31c3d Mon Sep 17 00:00:00 2001 From: albertrdk Date: Thu, 12 Feb 2026 13:41:41 +0100 Subject: [PATCH 1/3] Added example to customize kinematics with RoboDK v6 --- robotextensions/samplekinematics/.gitignore | 82 ++++ .../samplekinematics/samplekinematics.cpp | 350 ++++++++++++++++++ .../samplekinematics/samplekinematics.h | 77 ++++ .../samplekinematics/samplekinematics.pro | 56 +++ 4 files changed, 565 insertions(+) create mode 100644 robotextensions/samplekinematics/.gitignore create mode 100644 robotextensions/samplekinematics/samplekinematics.cpp create mode 100644 robotextensions/samplekinematics/samplekinematics.h create mode 100644 robotextensions/samplekinematics/samplekinematics.pro diff --git a/robotextensions/samplekinematics/.gitignore b/robotextensions/samplekinematics/.gitignore new file mode 100644 index 0000000..aa3808c --- /dev/null +++ b/robotextensions/samplekinematics/.gitignore @@ -0,0 +1,82 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash + +# qtcreator generated files +*.pro.user* +*.qbs.user* +CMakeLists.txt.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + +# Directories with generated files +.moc/ +.obj/ +.pch/ +.rcc/ +.uic/ +/build*/ diff --git a/robotextensions/samplekinematics/samplekinematics.cpp b/robotextensions/samplekinematics/samplekinematics.cpp new file mode 100644 index 0000000..85cc65b --- /dev/null +++ b/robotextensions/samplekinematics/samplekinematics.cpp @@ -0,0 +1,350 @@ +#include "samplekinematics.h" + +#include +#include + +// Some compilers may require this define to expose M_PI +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +// You must remove the line "CONFIG -= qt" from the .pro file if you want to use Qt features like QDebug +// #include + +// #include // For memset or memcpy if needed + + +/*! + * \brief iRobot_BaseXYZWPR + * Get the pointer of the robot base adaptor robot base (not the active base frame) + * \param ptr_robot + * \return Pointer to a 6D array (mm and rad) + */ +const real_T* iRobot_BaseXYZWPR(const robot_T *ptr_robot){ + return ((const real_T*) ptr_robot) + 9*20; +} + +/*! + * \brief iRobot_ToolXYZWPR + * Get the pointer of the robot tool flange adaptor (pose that takes from the DHM calculation to the robot flange (not the active Tool) + * \param ptr_robot + * \return Pointer to a 6D array (mm and rad) + */ +const real_T* iRobot_ToolXYZWPR(const robot_T *ptr_robot){ + return ((const real_T*) ptr_robot) + 28*20; +} + +/*! + * \brief iRobot_JointLimLower + * \param ptr_robot + * \return Returns an array pointer to the lower joint limits (mm and deg) + */ +const real_T* iRobot_JointLimLower(const robot_T *ptr_robot){ + return ((const real_T*) ptr_robot) + 30*20; +} + +/*! + * \brief iRobot_JointLimUpper + * \param ptr_robot + * \return Returns an array pointer to the upper joint limits (mm and deg) + */ +const real_T* iRobot_JointLimUpper(const robot_T *ptr_robot){ + return ((const real_T*) ptr_robot) + 31*20; +} + +/*! + * \brief iRobot_JointSenses + * \param ptr_robot + * \return Returns a pointer to an array of joint senses (-1 or +1) + */ +const real_T* iRobot_JointSenses(const robot_T *ptr_robot){ + return ((const real_T*) ptr_robot) + 3*20+4; +} + +/*! + * \brief iRobot_DHM_JointId + * Retrieve the DHM parameters for the joint id. The Joint ID must be an index between 0 and joints_lim_upper[i]){ + return -2; // Return -1 to use RoboDK default, return 0 for success, return -2 for target out of reach + } + + // Calculate the transofrmation for joint i + const real_T *dhm_joint_i = iRobot_DHM_JointId(ptr_robot, i); + // Add the transformation applied by the movement of the joint + real_T rx_tx_rz_tz[4] = {dhm_joint_i[0], dhm_joint_i[1], dhm_joint_i[2], dhm_joint_i[3]}; + if (dhm_joint_i[4] == 0.0){ + // revolute joint + rx_tx_rz_tz[2] = rx_tx_rz_tz[2] + joint_i * M_PI / 180.0; + } else { // == 1.0 + // translation joint + rx_tx_rz_tz[3] = rx_tx_rz_tz[3] + joint_i; + } + + // Apply the pose of the joint i to the accumulated final pose + real_T pose_ji[16]; + DHM_2_Pose(rx_tx_rz_tz, pose_ji); + Pose_Mult(last_pose, pose_ji, next_pose); + last_pose = next_pose; + } + + Pose_Mult(last_pose, pose_tool, pose); + + return 1; // Return -1 to use RoboDK default, return 0 for target out of reach, return 1 for success +} + +int SolveFK_CAD(const real_T *joints, real_T *pose, real_T *joint_poses, int max_poses, const robot_T *ptr_robot) { + std::cout << "Using custom SolveFK_CAD" << std::endl; + // return -1; // Return -1 to use RoboDK default, return 0 for success + + // Below is RoboDK's default calculation: + + // Retrieve the number of axes (degrees of freedom) + int nDOFs = iRobot_nDOFs(ptr_robot); + if (max_poses < nDOFs + 1){ + // RoboDK Must provide with a buffer large enough for all joints (at least nDOFs + 1) + // If not, something went wrong, we could write past an allowed buffer + std::cout << "Something went wrong with SolveFK_CAD" << std::endl; + return -1; + } + + const real_T *joints_senses = iRobot_JointSenses(ptr_robot); + + // Retrieve the robot base and tool flange adaptors (part of the kinematics, not the active frame and tool) + real_T *pose_base = joint_poses + 16*0; // map the base pose to the origin + real_T pose_tool[16]; + XYZWPR_2_Pose(iRobot_BaseXYZWPR(ptr_robot), pose_base); + XYZWPR_2_Pose(iRobot_ToolXYZWPR(ptr_robot), pose_tool); + + // Matrices for operations + real_T *last_pose = pose_base; + //real_T *next_pose = joint_poses + 16*(joint_id+1); + + + // Iterate over all joints to calculate the forward kinematics as: + // pose = pose_base * pose_j[0] * pose_j[1] * ... * pose_tool + for (int i=0; i Date: Fri, 13 Feb 2026 09:35:31 +0100 Subject: [PATCH 2/3] Minor fixes --- .../samplekinematics/samplekinematics.cpp | 19 +++++++++++-------- .../samplekinematics/samplekinematics.h | 16 ++++++++++------ .../samplekinematics/samplekinematics.pro | 13 ++++--------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/robotextensions/samplekinematics/samplekinematics.cpp b/robotextensions/samplekinematics/samplekinematics.cpp index 85cc65b..22448a1 100644 --- a/robotextensions/samplekinematics/samplekinematics.cpp +++ b/robotextensions/samplekinematics/samplekinematics.cpp @@ -1,12 +1,15 @@ +/* + * Copyright (c) 2026 RoboDK Global. All rights reserved. + */ + +// This is required on top to have M_PI +#define _USE_MATH_DEFINES +#include + #include "samplekinematics.h" #include -#include -// Some compilers may require this define to expose M_PI -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif // You must remove the line "CONFIG -= qt" from the .pro file if you want to use Qt features like QDebug // #include @@ -190,7 +193,7 @@ void Pose_Inv(const real_T in[16], real_T out[16]){ -int SolveFK(const real_T *joints, real_T *pose, const robot_T *ptr_robot) { +int SolveFK(const real_T *joints, real_T pose[16], const robot_T *ptr_robot) { std::cout << "Using custom/default SolveFK" << std::endl; // return -1; // Return -1 to use RoboDK default, return 1 for success, return 0 for target out of reach @@ -251,7 +254,7 @@ int SolveFK(const real_T *joints, real_T *pose, const robot_T *ptr_robot) { return 1; // Return -1 to use RoboDK default, return 0 for target out of reach, return 1 for success } -int SolveFK_CAD(const real_T *joints, real_T *pose, real_T *joint_poses, int max_poses, const robot_T *ptr_robot) { +int SolveFK_CAD(const real_T *joints, real_T pose[16], real_T *joint_poses, int max_poses, const robot_T *ptr_robot) { std::cout << "Using custom SolveFK_CAD" << std::endl; // return -1; // Return -1 to use RoboDK default, return 0 for success @@ -314,7 +317,7 @@ int SolveFK_CAD(const real_T *joints, real_T *pose, real_T *joint_poses, int max // return -1; // return -1 to use RoboDK default } -int SolveIK(const real_T *pose, real_T *joints, real_T *joints_all, int max_solutions, const real_T *joints_approx, const robot_T *ptr_robot) { +int SolveIK(const real_T pose[16], real_T *joints, real_T *joints_all, int max_solutions, const real_T *joints_approx, const robot_T *ptr_robot) { std::cout << "Using custom SolveIK..." << std::endl; // Retrieve the number of axes (degrees of freedom) diff --git a/robotextensions/samplekinematics/samplekinematics.h b/robotextensions/samplekinematics/samplekinematics.h index 953ceea..a8f0a06 100644 --- a/robotextensions/samplekinematics/samplekinematics.h +++ b/robotextensions/samplekinematics/samplekinematics.h @@ -1,13 +1,17 @@ +/* + * Copyright (c) 2026 RoboDK Global. All rights reserved. + */ + #ifndef SAMPLEKINEMATICS_H #define SAMPLEKINEMATICS_H -#if defined(_MSC_VER) || defined(WIN64) || defined(_WIN64) || defined(__WIN64__) || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) +#if defined(_WIN32) #define MYLIB_EXPORT __declspec(dllexport) #define MYLIB_IMPORT __declspec(dllimport) #else -#define MYLIB_EXPORT __attribute__((visibility("default"))) -#define MYLIB_IMPORT __attribute__((visibility("default"))) +#define MYLIB_EXPORT +#define MYLIB_IMPORT #endif @@ -29,7 +33,7 @@ extern "C" { * pointer to the robot parameters, if any * \return returns 1 if the solution is valid, returns 0 if there is no solution (such as joints out of limits), return -1 if we want to use the default/generic forward kinematics of RoboDK */ -MYLIB_EXPORT int SolveFK(const real_T *joints, real_T *pose, const robot_T *ptr_robot); +MYLIB_EXPORT int SolveFK(const real_T *joints, real_T pose[16], const robot_T *ptr_robot); /*! @@ -47,7 +51,7 @@ MYLIB_EXPORT int SolveFK(const real_T *joints, real_T *pose, const robot_T *ptr_ * pointer to the robot parameters, if any. * \return Returns 1 if the solution is valid, returns 0 if there is no solution (such as joints out of limits), return -1 if we want to use the default/generic forward kinematics of RoboDK */ -MYLIB_EXPORT int SolveFK_CAD(const real_T *joints, real_T *pose, real_T *joint_poses, int max_poses, const robot_T *ptr_robot); +MYLIB_EXPORT int SolveFK_CAD(const real_T *joints, real_T pose[16], real_T *joint_poses, int max_poses, const robot_T *ptr_robot); @@ -67,7 +71,7 @@ MYLIB_EXPORT int SolveFK_CAD(const real_T *joints, real_T *pose, real_T *joint_p * pointer to the robot parameters, if any. * \return returns the number of valid solutions (equal or less than max_solutions), if any. Returns 0 if there is no solution (for example: target out of reach), return -1 if we want to use the default iterative solution provided by RoboDK */ -MYLIB_EXPORT int SolveIK(const real_T *pose, real_T *joints, real_T *joints_all, int max_solutions, const real_T *joints_approx, const robot_T *ptr_robot); +MYLIB_EXPORT int SolveIK(const real_T pose[16], real_T *joints, real_T *joints_all, int max_solutions, const real_T *joints_approx, const robot_T *ptr_robot); } diff --git a/robotextensions/samplekinematics/samplekinematics.pro b/robotextensions/samplekinematics/samplekinematics.pro index 0a8c972..9be4951 100644 --- a/robotextensions/samplekinematics/samplekinematics.pro +++ b/robotextensions/samplekinematics/samplekinematics.pro @@ -3,7 +3,10 @@ # To load your custom DLL: Double click on your robot, select Parameters, click on Options under Robot Kinematics, click on Select Library. # This is supported since RoboDK v6 #-------------------------------- -# CONFIG -= qt + +CONFIG -= qt +QT -= core +QT -= gui TEMPLATE = lib CONFIG += c++17 @@ -46,11 +49,3 @@ SOURCES += \ HEADERS += \ samplekinematics.h - - - - - - - - From f4687d529d17287fd0cc463a3d8b0cf2c65144ae Mon Sep 17 00:00:00 2001 From: albertrdk Date: Mon, 16 Feb 2026 08:57:27 +0100 Subject: [PATCH 3/3] Minor fixes --- robodk_interface/constants.h | 4 +-- robodk_interface/deprecated.h | 4 +-- robodk_interface/joints.h | 4 +-- robodk_interface/legacymatrix2d.h | 4 +-- robodk_interface/matrix4x4.h | 4 +-- robodk_interface/stationtreeeventmonitor.h | 4 +-- robodk_interface/vector3.h | 4 +-- .../samplekinematics/samplekinematics.cpp | 31 +++++++++++++++++-- .../samplekinematics/samplekinematics.h | 31 +++++++++++++++++-- 9 files changed, 70 insertions(+), 20 deletions(-) diff --git a/robodk_interface/constants.h b/robodk_interface/constants.h index 97331fe..9015700 100644 --- a/robodk_interface/constants.h +++ b/robodk_interface/constants.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (c) 2015-2025 RoboDK Inc. +** Copyright (c) 2015-2026 RoboDK Global. ** Contact: https://robodk.com/ ** ** This file is part of the RoboDK API. @@ -23,7 +23,7 @@ ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ** SOFTWARE. ** -** RoboDK is a registered trademark of RoboDK Inc. +** RoboDK is a registered trademark of RoboDK Global. ** ****************************************************************************/ diff --git a/robodk_interface/deprecated.h b/robodk_interface/deprecated.h index 6ea079b..3b2c6d9 100644 --- a/robodk_interface/deprecated.h +++ b/robodk_interface/deprecated.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (c) 2015-2025 RoboDK Inc. +** Copyright (c) 2015-2026 RoboDK Global. ** Contact: https://robodk.com/ ** ** This file is part of the RoboDK API. @@ -23,7 +23,7 @@ ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ** SOFTWARE. ** -** RoboDK is a registered trademark of RoboDK Inc. +** RoboDK is a registered trademark of RoboDK Global. ** ****************************************************************************/ diff --git a/robodk_interface/joints.h b/robodk_interface/joints.h index d433e97..8078959 100644 --- a/robodk_interface/joints.h +++ b/robodk_interface/joints.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (c) 2015-2025 RoboDK Inc. +** Copyright (c) 2015-2026 RoboDK Global. ** Contact: https://robodk.com/ ** ** This file is part of the RoboDK API. @@ -23,7 +23,7 @@ ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ** SOFTWARE. ** -** RoboDK is a registered trademark of RoboDK Inc. +** RoboDK is a registered trademark of RoboDK Global. ** ****************************************************************************/ diff --git a/robodk_interface/legacymatrix2d.h b/robodk_interface/legacymatrix2d.h index ad3a505..df592a4 100644 --- a/robodk_interface/legacymatrix2d.h +++ b/robodk_interface/legacymatrix2d.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (c) 2015-2025 RoboDK Inc. +** Copyright (c) 2015-2026 RoboDK Global. ** Contact: https://robodk.com/ ** ** This file is part of the RoboDK API. @@ -23,7 +23,7 @@ ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ** SOFTWARE. ** -** RoboDK is a registered trademark of RoboDK Inc. +** RoboDK is a registered trademark of RoboDK Global. ** ****************************************************************************/ diff --git a/robodk_interface/matrix4x4.h b/robodk_interface/matrix4x4.h index a9da6cc..8d7bdaa 100644 --- a/robodk_interface/matrix4x4.h +++ b/robodk_interface/matrix4x4.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (c) 2015-2025 RoboDK Inc. +** Copyright (c) 2015-2026 RoboDK Global. ** Contact: https://robodk.com/ ** ** This file is part of the RoboDK API. @@ -23,7 +23,7 @@ ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ** SOFTWARE. ** -** RoboDK is a registered trademark of RoboDK Inc. +** RoboDK is a registered trademark of RoboDK Global. ** ****************************************************************************/ diff --git a/robodk_interface/stationtreeeventmonitor.h b/robodk_interface/stationtreeeventmonitor.h index d820a35..d2a2fa6 100644 --- a/robodk_interface/stationtreeeventmonitor.h +++ b/robodk_interface/stationtreeeventmonitor.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (c) 2015-2025 RoboDK Inc. +** Copyright (c) 2015-2026 RoboDK Global. ** Contact: https://robodk.com/ ** ** This file is part of the RoboDK API. @@ -23,7 +23,7 @@ ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ** SOFTWARE. ** -** RoboDK is a registered trademark of RoboDK Inc. +** RoboDK is a registered trademark of RoboDK Global. ** ****************************************************************************/ diff --git a/robodk_interface/vector3.h b/robodk_interface/vector3.h index 0ca9ee9..2107909 100644 --- a/robodk_interface/vector3.h +++ b/robodk_interface/vector3.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (c) 2015-2025 RoboDK Inc. +** Copyright (c) 2015-2026 RoboDK Global. ** Contact: https://robodk.com/ ** ** This file is part of the RoboDK API. @@ -23,7 +23,7 @@ ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ** SOFTWARE. ** -** RoboDK is a registered trademark of RoboDK Inc. +** RoboDK is a registered trademark of RoboDK Global. ** ****************************************************************************/ diff --git a/robotextensions/samplekinematics/samplekinematics.cpp b/robotextensions/samplekinematics/samplekinematics.cpp index 22448a1..d8e48ff 100644 --- a/robotextensions/samplekinematics/samplekinematics.cpp +++ b/robotextensions/samplekinematics/samplekinematics.cpp @@ -1,6 +1,31 @@ -/* - * Copyright (c) 2026 RoboDK Global. All rights reserved. - */ +/**************************************************************************** +** +** Copyright (c) 2015-2026 RoboDK Global. +** Contact: https://robodk.com/ +** +** This file is part of the RoboDK API. +** +** Permission is hereby granted, free of charge, to any person obtaining a copy +** of this software and associated documentation files (the "Software"), to deal +** in the Software without restriction, including without limitation the rights +** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +** copies of the Software, and to permit persons to whom the Software is +** furnished to do so, subject to the following conditions: +** +** The above copyright notice and this permission notice shall be included in all +** copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +** SOFTWARE. +** +** RoboDK is a registered trademark of RoboDK Global. +** +****************************************************************************/ // This is required on top to have M_PI #define _USE_MATH_DEFINES diff --git a/robotextensions/samplekinematics/samplekinematics.h b/robotextensions/samplekinematics/samplekinematics.h index a8f0a06..7e94b78 100644 --- a/robotextensions/samplekinematics/samplekinematics.h +++ b/robotextensions/samplekinematics/samplekinematics.h @@ -1,6 +1,31 @@ -/* - * Copyright (c) 2026 RoboDK Global. All rights reserved. - */ +/**************************************************************************** +** +** Copyright (c) 2015-2026 RoboDK Global. +** Contact: https://robodk.com/ +** +** This file is part of the RoboDK API. +** +** Permission is hereby granted, free of charge, to any person obtaining a copy +** of this software and associated documentation files (the "Software"), to deal +** in the Software without restriction, including without limitation the rights +** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +** copies of the Software, and to permit persons to whom the Software is +** furnished to do so, subject to the following conditions: +** +** The above copyright notice and this permission notice shall be included in all +** copies or substantial portions of the Software. +** +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +** SOFTWARE. +** +** RoboDK is a registered trademark of RoboDK Global. +** +****************************************************************************/ #ifndef SAMPLEKINEMATICS_H #define SAMPLEKINEMATICS_H