tesseract-robotics / tesseract_python

This contains python wrappers for both Tesseract and Tesseract Planning packages
https://tesseract-robotics.github.io/tesseract_python/
28 stars 13 forks source link

can't set a Descartes pose sampler on Profile #50

Open jf--- opened 1 year ago

jf--- commented 1 year ago

Hi,

First, what a formidable library, so stoked having access to tesseract from python!

I'd like to contribute by porting examples from tesseract-robotics/tesseract_planning/tree/master/tesseract_examples/src to python. Also its a nice way to find my way around ;)

I'm porting a Descartes tutorial from ROS-I training ,


from tesseract_robotics.tesseract_motion_planners_descartes import (
    cast_DescartesPlanProfileD,
    DescartesDefaultPlanProfileD,
    sampleToolZAxis,
    PoseSamplerFn,
)

def test_zaxis_descartes():
    """

    implement the ROS-I tutotial on descartes
    basically is akin to the `puzzle_piece_example.py`, but using the `descartes` lib over `trajopt`

    https://industrial-training-master.readthedocs.io/en/melodic/_source/session5/Advanced-Descartes-Path-Planning.html

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

#     plan_profile.target_pose_sampler = pp
#     Traceback (most recent call last):
#     File "C:\Program Files (x86)\JetBrains\PyCharm 2022.3.3\plugins\python\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
#     exec(exp, global_vars, local_vars)
# File "<input>", line 1, in <module>
# File "C:\Users\jelle\miniconda3\envs\compas\lib\site-packages\tesseract_robotics\tesseract_motion_planners_descartes\tesseract_motion_planners_descartes_python.py", line 34, in set_instance_attr
# set(self, name, value)
# TypeError: in method 'DescartesDefaultPlanProfileD_target_pose_sampler_set', argument 2 of type 'tesseract_planning::PoseSamplerFn *'
# pp
johnwason commented 1 year ago

Hi @jf---

First, what a formidable library, so stoked having access to tesseract from python!

I think there are over 4000 functions wrapped...

argument 2 of type 'tesseract_planning::PoseSamplerFn *'

Wrapping callback functions is very tricky. I will take a look when I have a chance to see what the issue is, but it may take some time before I have it fixed.

jf--- commented 1 year ago

Thanks @johnwason , I'm familiar with the limits of SWIG I've worked on pythonocc extensively, which is also SWIG based. The issue is mostly namespaces related, the set function doesn't really invoke much. pybind11 has an interesting approach to handling callbacks.

Any thoughts on how to move fwd regarding using the descartes planner?

johnwason commented 1 year ago

I use SWIG "directors" to handle the callbacks. There are some macros that generate a base class, and then the Python wrapper class extends the base class.

There is a SWIG file with the macro definitions that make it all work:

https://github.com/tesseract-robotics/tesseract_python/blob/master/tesseract_python/swig/tesseract_std_function.i

It looks like the customized typemap is not being applied for the field target_pose_sampler. It is likely that function parameters are using the correct typemap, but not the field assignment.

johnwason commented 1 year ago

@jf--- please send me a message on my website https://www.wasontech.com/contact-us

jf--- commented 1 year ago

✅ thx for the invite!

johnwason commented 11 months ago

@jf--- can you try the wheels in

https://github.com/tesseract-robotics/tesseract_python/suites/18704221744/artifacts/1088812345

This should have the sampling function fixed. You can install wheel files using pip by pointing to the file absolute location. Make sure you use the right file for your system and python version.

johnwason commented 11 months ago

I have tesseract running on Mac OSX arm64. See https://github.com/tesseract-robotics/tesseract/discussions/970

johnwason commented 11 months ago

Hi @jf--- have you had a chance to test these fixes? The macos packages should have the callback function working.