Skip to content

Commit 45ec5cd

Browse files
authored
Fix swig wrapping of kinematic utils (#32)
* Fix swig wrapping of kinematic utils * Use ptrdiff_t for Eigen::Index, add redundant solutions test
1 parent 8caa3a7 commit 45ec5cd

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

tesseract_python/swig/eigen_types.i

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,22 @@ namespace Eigen
4040
%eigen_typemaps(Eigen::Vector3d);
4141
%eigen_typemaps(Eigen::Vector4d);
4242
%eigen_typemaps(Eigen::VectorXd);
43+
%eigen_typemaps(%arg(Eigen::VectorX<double>));
4344
%eigen_typemaps(Eigen::MatrixXd);
4445
%eigen_typemaps(%arg(Eigen::Matrix3Xd));
46+
%eigen_typemaps(%arg(Eigen::MatrixX2d));
4547
%eigen_typemaps(%arg(Eigen::Matrix<uint32_t,3,Eigen::Dynamic>));
4648
%eigen_typemaps(%arg(Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>));
4749
%eigen_typemaps(Eigen::VectorXi);
4850
%eigen_typemaps(Eigen::Matrix3d);
4951
%eigen_typemaps(Eigen::Matrix4d);
5052

53+
// Assume that Eigen::Index can be treated as int64_t
54+
namespace Eigen {
55+
typedef ptrdiff_t Index;
56+
}
57+
%template(vector_eigen_index) std::vector<Eigen::Index>;
58+
5159
/*
5260
//Workaround typemaps for Isometry3d
5361

tesseract_python/swig/tesseract_common_python.i

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,6 @@ namespace std
244244
%}
245245
}
246246

247-
247+
%template(isWithinPositionLimits) tesseract_common::isWithinPositionLimits<double>;
248+
%template(satisfiesPositionLimits) tesseract_common::satisfiesPositionLimits<double>;
249+
//%template(enforcePositionLimits) tesseract_common::enforcePositionLimits<double>;

tesseract_python/swig/tesseract_kinematics_python.i

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include <tesseract_kinematics/core/kinematics_plugin_factory.h>
6464
#include <tesseract_kinematics/core/rep_factory.h>
6565
#include <tesseract_kinematics/core/rop_factory.h>
66+
#include <tesseract_kinematics/core/utils.h>
6667

6768
#include <tesseract_kinematics/kdl/kdl_factories.h>
6869
#include <tesseract_kinematics/opw/opw_factory.h>
@@ -111,6 +112,8 @@ struct KinGroupIKInput;
111112
%shared_ptr(tesseract_kinematics::InvKinFactory)
112113
%include "tesseract_kinematics/core/kinematics_plugin_factory.h"
113114

115+
116+
114117
// TODO
115118
//%shared_ptr(tesseract_kinematics::RobotWithExternalPositionerInvKin)
116119
//%shared_ptr(tesseract_kinematics::RobotOnPositionerInvKin)
@@ -120,7 +123,9 @@ struct KinGroupIKInput;
120123
//%shared_ptr(tesseract_kinematics::KDLInvKinChainNR)
121124
//%shared_ptr(tesseract_kinematics::OPWInvKin)
122125

123-
126+
%eigen_typemaps(%arg(tesseract_kinematics::VectorX<double>));
127+
%include "tesseract_kinematics/core/utils.h"
128+
%template(getRedundantSolutions) tesseract_kinematics::getRedundantSolutions<double>;
124129

125130

126131

tesseract_python/tests/tesseract_environment/test_tesseract_environment_kingroup.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from tesseract_robotics.tesseract_environment import Environment
55
from tesseract_robotics.tesseract_common import FilesystemPath, ManipulatorInfo
6-
from tesseract_robotics.tesseract_kinematics import KinGroupIKInput, KinGroupIKInputs
6+
from tesseract_robotics.tesseract_kinematics import KinGroupIKInput, KinGroupIKInputs, getRedundantSolutions
77
from ..tesseract_support_resource_locator import TesseractSupportResourceLocator
88

99
def get_environment():
@@ -46,4 +46,23 @@ def test_kinematic_group():
4646

4747
np.testing.assert_allclose(invkin.flatten(),joint_vals)
4848

49+
def test_tesseract_redundant_solutions_tesseract_function():
50+
51+
env, manip_info, joint_names = get_environment()
52+
53+
kin_group = env.getKinematicGroup(manip_info.manipulator).release()
54+
55+
limits = kin_group.getLimits()
56+
redundancy_indices = list(kin_group.getRedundancyCapableJointIndices())
57+
58+
import tesseract_robotics.tesseract_kinematics as tes_com
59+
sol = np.ones((6,1))*np.deg2rad(5)
60+
redun_sol = tes_com.getRedundantSolutions(sol, limits.joint_limits, redundancy_indices)
61+
62+
assert len(redun_sol) == 2
63+
64+
assert np.allclose(redun_sol[0].flatten(),
65+
np.array([0.08726646, 0.08726646, 0.08726646, 0.08726646, 0.08726646, -6.19591884])) or \
66+
np.allclose(redun_sol[0].flatten(),
67+
np.array([0.08726646, 0.08726646, 0.08726646, 0.08726646, 0.08726646, 6.19591884]))
4968

0 commit comments

Comments
 (0)