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

Segmentation fault when using setState on empty Environment #54

Closed dave992 closed 1 year ago

dave992 commented 1 year ago

When I used the setState method of a newly constructed Environment I encountered a segmentation fault.

I am running Ubuntu 20.04 via WSL2 on Windows 11.

To reproduce the segmentation fault on my system:

import numpy as np
from tesseract_robotics.tesseract_environment import Environment

joint_names = ["joint_a1", "joint_a2", "joint_a3", "joint_a4", "joint_a5", "joint_a6"]
joint_position = np.array([-0.4, 0.2762, 0.0, -1.3348, 0.0, 1.4959, 0.0])

env = Environment()
env.setState(joint_names, joint_position)

Terminal output:

Segmentation fault

I understand that it does not make much sense to try to set the state of an empty environment, but I encountered this issue trying to recreate one of the C++ examples. Not having any meaningful error message in Python makes it hard to debug.

johnwason commented 1 year ago

Try

tesseract_common.setLogLevel(tesseract_common.CONSOLE_BRIDGE_LOG_DEBUG)
dave992 commented 1 year ago
Python Script

```python import numpy as np from tesseract_robotics import tesseract_common from tesseract_robotics.tesseract_environment import Environment tesseract_common.setLogLevel(tesseract_common.CONSOLE_BRIDGE_LOG_DEBUG) joint_names = ["joint_a1", "joint_a2", "joint_a3", "joint_a4", "joint_a5", "joint_a6"] joint_position = np.array([-0.4, 0.2762, 0.0, -1.3348, 0.0, 1.4959, 0.0]) env = Environment() env.setState(joint_names, joint_position) ```

I have tried adding the line you recommended but still get the exact same Segmentation fault message. No additional output is visible.

johnwason commented 1 year ago

You need to call some variant of "init" before using environment. The best option is probably an empty vector of commands.

env = Environment() cmds = Commands() env.init(cmds)

dave992 commented 1 year ago

I understand that I used it wrong. I would've expected to get a little more meaningful error in case the object is not initialized/ used as expected instead of just crashing the interpreter.

johnwason commented 1 year ago

The SWIG wrappers have the exact same behavior as the C++ classes. These wrappers are intended for use by experts or as building blocks for higher level libraries.

dave992 commented 1 year ago

Wrapper/low-level or not, this is a Python library. And even experts can make mistakes 😉

johnwason commented 1 year ago

Sure, there is a need for a high level interface like tesseract_robotics_easy or tesseract_robotics_commander. These can be easily built on top of the low-level wrappers. Attempts to make the interfaces more friendly using SWIG have only resulted in unmanageable spaghetti code.

Levi-Armstrong commented 1 year ago

Instead of making every method check if the environment is initialized which can have a performance impact, the environment has a method to check if it has been initialized properly which is the developers responsibility to check before using the environment object. env.isInitialized();