Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix std::function Python field assignment SWIG typemap #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tesseract_python/swig/tesseract_std_function.i
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@ public:
}
}

%typemap(in) Namespace::Name * (void *argp, int res = 0, std::shared_ptr< Name##Base > temp1, Namespace::Name temp2) {
// const tesseract_std_function& %typemap(in)
int newmem = 0;
res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(std::shared_ptr< Name##Base > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "$type", $symname, $argnum);
}
if (!argp) {
%argument_nullref("$type", $symname, $argnum);
} else {
temp1 = *(%reinterpret_cast(argp, std::shared_ptr< Name##Base > *));
temp2 = [temp1]( %formacro_2n(_tesseract_std_function_call_args,__VA_ARGS__) ) { return temp1->call( %formacro_2n(_tesseract_std_function_call_vars,__VA_ARGS__) ); };
$1 = &temp2;
if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, std::shared_ptr< Name##Base > *);
}
}

%typemap(out) Namespace::Name const & {
// tesseract_std_function & %typemap(out)
Py_INCREF(Py_None);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from tesseract_robotics.tesseract_motion_planners import PlannerRequest, PlannerResponse
from tesseract_robotics.tesseract_motion_planners_descartes import DescartesDefaultPlanProfileD, \
DescartesMotionPlannerD, DescartesPlanProfileD, \
ProfileDictionary_addProfile_DescartesPlanProfileD, cast_DescartesPlanProfileD
ProfileDictionary_addProfile_DescartesPlanProfileD, cast_DescartesPlanProfileD, PoseSamplerFn
from tesseract_robotics.tesseract_motion_planners_simple import generateInterpolatedProgram
from ..tesseract_support_resource_locator import TesseractSupportResourceLocator

Expand Down Expand Up @@ -89,3 +89,14 @@ def test_descartes_freespace_fixed_poses():
assert len(wp.getNames()) == 6
assert isinstance(wp.getPosition(),np.ndarray)
assert len(wp.getPosition()) == 6

def _sampler_fun(tool_pose):
return []

def test_sampler_std_fun():

plan_profile = DescartesDefaultPlanProfileD()
# DescartesDefaultPlanProfileD is not upcasting automatically, use helper function
plan_profile1 = cast_DescartesPlanProfileD(plan_profile)
pp = PoseSamplerFn(_sampler_fun)
plan_profile.target_pose_sampler = pp
Loading