Skip to content

Constraint Planning Segfault #2103

Open

Description

@MarqRazz

Description

I have been working on a problem where I need orientation constraints to be held when transporting an object and have been observing segmentation faults in MoveIt. In my setup I'm also trying to build databases to speed up planning but when I enable multi_query_planning_enabled motion planning crashes.

Your environment

  • ROS Distro: [Humble & Rolling]
  • OS Version: e.g. Ubuntu 22.04
  • Source build
  • Cyclone DDS

Steps to reproduce

I have made a working docker container with instructions that includes some details on where I have been seeing the faults. In this container I have modified ompl_constrained_planning_tutorial to include some collision objects around the robot and to attempt to find motion plans forever because the fault happens on the second or third attempt. I'm asking for multiple plans because in my actual application I'm using MTC and this happens when my constraint stage has a parent with multiple solutions.

Expected behaviour

I should be able to run the modified tutorial example without MoveIt crashing.

Actual behaviour

Program crashes with a segfault.

Backtrace or Console output

segfault backtrace after failed motion plan
segfault backtrace after successful motion plan

Activity

  1. added
    bug
    on Apr 12, 2023
  2. henningkayser commented on Apr 26, 2023

    @henningkayser
    Member

    @MarqRazz I think I've found what is broken in OMPL. However, I don't have a great suggestion for a fix but maybe a better workaround.

    multi-query planners don't support being run in multiple threads that share the same planner data (I don't recall why). The answer to your question here is that planning attempts directly translate to planning threads internally (all attempts at the same time) which OMPL implements in the solve function. Do you see the tiny comment in this line? I think that's the problem. Please try setting planning attempts to 1. If that works, we should enforce this setting for multi-query planners.

    Edit: Parallel plan doesn't work since it's clearing the planner instance and creating new ones with the same config. I don't think there is an easy way to enable multi-query planning with OMPL's parallel planning interface.

  3. MarqRazz commented on Apr 26, 2023

    @MarqRazz
    ContributorAuthor

    Please try setting planning attempts to 1. If that works, we should enforce this setting for multi-query planners.

    No that does not fix the problem. Sorry I left that line in the example but as you noted the if statement with the tiny comment in this line forces it to solve in a single thread.

    Edit: Parallel plan doesn't work since it's clearing the planner instance and creating new ones with the same config.

    The problem is that it's trying to reuse the same planning object between requests when the multi_query_planning_enabled flag is enable.

  4. henningkayser commented on Apr 26, 2023

    @henningkayser
    Member

    Please try setting planning attempts to 1. If that works, we should enforce this setting for multi-query planners.

    No that does not fix the problem. Sorry I left that line in the example but as you noted the if statement with the tiny comment in this line forces it to solve in a single thread.

    Well, you're obviously right with that.

    Edit: Parallel plan doesn't work since it's clearing the planner instance and creating new ones with the same config.

    The problem is that it's trying to reuse the same planning object between requests when the multi_query_planning_enabled flag is enable.

    That's the purpose of that flag, no? The problem is that the instance is being wiped somewhere which to me means that there is something specific to how planner instances are handled by the context. I'll have to dig a bit deeper for that, though. Reusing the instance should work. If not, storing and reusing the planner data only should be implemented instead.

  5. MarqRazz commented on Apr 26, 2023

    @MarqRazz
    ContributorAuthor

    Andy and I think it might have to do with the robot_state that is used to construct the objects inside the planner (see this comment).

  6. henningkayser commented on May 23, 2023

    @henningkayser
    Member

    I have been looking into this a bit more. Running a recent version of main (with #2130 reverted) and a rebased version of your tutorial example, I'm getting the same stack trace. It looks like we are trying to access a pure virtual function in the cleanup code inside PlannerInputStates::clear() I would include OMPL next to figure out what exactly it is trying to access, but my gut feeling is that it's ProblemDefinition->SpaceInformation, possibly also the included StateSpace or StateValidityChecker. However, SimpleSetup (which includes SpaceInformation->StateSpace) seems to be inaccessible here and the StateSpace is inaccessible here in the originally reported stack traces.

  7. henningkayser commented on May 23, 2023

    @henningkayser
    Member

    Allowing to cache constrained planning contexts fixes the segfault for me. Obviously, this is not a good solution for documented reasons.

  8. henningkayser commented on May 23, 2023

    @henningkayser
    Member

    ok, I think I've figured it out...

    With constrained planning, we are not caching planning contexts. The reason is that each request can have a different mix of constraints which would require building a new StateValidityChecker which is in turn owned by the StateInformation. Planners have the StateInformation as member and only provide const access to the pointer (no way to change the instance). Problem is, the StateValidityChecker has a raw pointer to the PlanningContext it was created with, and eventually runs into a segfault when that one goes out of scope. Multi-query-planning with the same planner instance would basically depend on caching planning contexts which we don't do for the described reason.

    There are different ways to approach this:

    1. Simply recreate planner instances with each call and live with the performance implications (current solution), possibly find out ways to reduce the time overhead
    2. Update the members of StateValidityChecker and ProblemDefinition of the cached planner instance (there is some API for this), hoping that this is sufficient (could work, needs to be investigated, maybe not worth the effort)
    3. Implement PlanningContext caching for constrained planning, requiring us to basically parse and keep track of constraint groups
    4. Expose an API for updating the SpaceInformation etc of a planner

    However, if we have to construct and configure constrained planning requests anew each time anyway, there is probably not a great reason to keep the planner instance alive. Caching SpaceInformation, StateValidityChecker etc (basically the PlanningContext) is really what speeds up multi-query planning, so option 3 would be the only proper fix to me.

    A short improvement for now could be to simply disable multi-query-planning for all constrained planning requests, but still allow it for others.

  9. github-actions commented on Aug 17, 2023

    @github-actions

    This issue is being labeled as stale because it has been open 45 days with no activity. It will be automatically closed after another 45 days without follow-ups.

  10. radhen commented on May 20, 2024

    @radhen

    @henningkayser @MarqRazz @sjahr are there any updates on this issue? Any concrete solution that has worked for you?

    I'm having a similar problem with my setup. I'm using OMPL, MoveIt, and ROS Humble on Ubuntu 22.04. I'm trying to save a roadmap using the PersistentLazyPRMstar planner in a constraint setting, so I can use it later for planning. In my setup, I use different planners for different types of motion.

    I'm new to digging into the MoveIt and OMPL code, but I think I kinda understand what's going wrong, based on what's been discussed here and the call stack that is linked up. But I need help putting one of @henningkayser's suggestions into action.

    Here's the link to the text file (ompl_moveit_seg_fault_call_stack.txt) with the call stack for the segmentation fault I'm getting. Any assistance or insights you could offer would be greatly appreciated. Thank you in advance for your help!

  11. radhen commented on May 23, 2024

    @radhen

    The fix mentioned in the issue #2130 helped we clear the segmentation fault. Call trace linked in the above comment. Here is the link to the Files Changed.

  12. MarqRazz commented on May 23, 2024

    @MarqRazz
    ContributorAuthor

    Sorry for the slow reply @radhen.

    Yes I was able to remove the segfault with that fix and save/load the roadmap but it didn't reduce planning time or increase the success rate in my case. My application was a 6DOF robot mounted to a linear rail so it was redundant but I was not able to figure out if that was the reason it didn't help. If you do get it working I'd like to hear your results.

  13. radhen commented on May 24, 2024

    @radhen

    Hello @MarqRazz. Thank for the response. My setup also consists of a 6DOF robot mounted to a linear rail. I definitely saw an improvement in the planning time (reduced almost by a factor of 10) once the roadmap was build. I built the roadmap using the PresistentLazyPRMstar. Once it was built, I was using it with PresistentLazyPRM to test. Note my PRM goes through a constraint pipeline. The success rate rather saw a decrement, but I believe if I built a more denser roadmap then the success rate should go up. To summarize, the PRM works well, when it does, and brings the planning time considerably down. Please let me know if you have any other questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions