MengeCrowdSim / Menge

The source code for the Menge crowd simulation framework
Apache License 2.0
139 stars 64 forks source link

Debugging navmesh #145

Closed JulianKu closed 4 years ago

JulianKu commented 4 years ago

Hi :)

I am currently working on a python helper utility that can take an image of a 2D environment as an input and generate Menge compliant environment definition from this so that I can then use Menge to simulate pedestrian behavior in this custom map. I have already managed to generate the scene file (placing agents and obstacles at the correct positions) as well as the behavior file (placing goal regions correctly). With a VelComponent of type 'goal' for the "Walk" state, the simulation works as supposed.

However, as the environments, I'd to simulate, are rather complex I need a more sophisticated walking behavior and therefore, intend to create a navmesh for this map. Guided by the objToNavmesh.py from Menge Utils, I first triangulated my map to get all vertices, edges, and faces and then mapped this to match the NavMesh class so that I can use its write method. The process seems to work and taking a look at the generated .nav file, the structure and values seem reasonable. Unfortunately, trying to incorporate the navmesh only throws "Segmentation fault (core dumped)".

Is there any way to debug the navmesh or how do I find out what's wrong? I intend to use Menge for my Master Thesis project on Reinforcement Learning for navigating through pedestrian crowds and hope there is a way to solve this. I've attached the project files. If required, I can also provide my code, although it is currently only in a private repository. MW.zip

curds01 commented 4 years ago

Hi :)

Sorry for the pain. Your best shot is to build everything in debug build and then attach a debugger. That'll give you insight into where the segfault is occurring. I'd definitely like to get that ironed out -- segfaults are the worst kind of bug and wholly inexcusable.

I ran your project file and did not get a segfault. How long does it run before it happens. But, more importantly, I selected one of your agents to see the navigation mesh and it clearly is not a good navigation mesh (see the image below).

You've got lots of overlapping triangles and you've got one whose vertex is probably at some negative infinity value (it's the one that disappears off the bottom of the image). So, we should start with making sure you have a clean navigation mesh.

You might find your workflow is better if, instead of going straight to a nav mesh, you instead created an obj mesh. There are lots of good online visualizers where you could introspect your mesh. Then once you believe the mesh is clean, you can simply use objToNavMesh.py to convert it.

image

JulianKu commented 4 years ago

Thank you very much for your quick response :)

First, for me, the segfault happens immediately after starting the simulation. But I have to say that I am using `this ROS binding for Menge. As the simulation will be one component of a larger system, I thought that this ROS integration will make things easier. But it is probably not using the most recent Menge version so that this could be causing issues as well. I will need to figure out what to do about this.

As for the navmesh, you're probably right that it would be better to first go to obj mesh, verify it and then map to navmesh from there. So I will continue with this and let you know if there are further issues.

EDIT Segfault is also immediately thrown when building Menge from the official repo.

JulianKu commented 4 years ago

So thank you very much for the tip with going to obj mesh first. This was a lot easier, implemented really fast and after updating your objToNavmesh to python3 syntax it works like a charm. Triangles look clean now as well and no more segfaults occurring.

map

curds01 commented 4 years ago

Could I persuade you to submit a PR to the utils with the Python3 upgrade? I need to do that across the project and every little bit would help.

I'm going to go ahead and close this issue as "solved". Feel free to re-open it if you feel it isn't done.