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/.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..d8e48ff --- /dev/null +++ b/robotextensions/samplekinematics/samplekinematics.cpp @@ -0,0 +1,378 @@ +/**************************************************************************** +** +** 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 +#include + +#include "samplekinematics.h" + +#include + + +// 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[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 + + // 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