pyoscx / scenariogeneration

Python library to generate linked OpenDRIVE and OpenSCENARIO files
Mozilla Public License 2.0
256 stars 81 forks source link

Missing documentation for lane_offset in add_predecessor/successor() #84

Closed johschmitz closed 1 year ago

johschmitz commented 2 years ago

I am struggling a bit to implement the lane_offset for the direct junctions correctly for all cases. Now I found that it seems to be missing from the documentation. Could you explain how exactly the lane_offset is defined? Also does it include or exclude the center lane or how does it behave with respect to the center lane?

johschmitz commented 2 years ago

Any news on this topic? Any branch to test this out?

mander76 commented 2 years ago

I have been cramped these past week (and will probably not go down in one or two more), but the latest is pushed (and I have an intern testing it out). Hopefully I will have time in 2 weeks to merge it with main and document how it works

johschmitz commented 2 years ago

Could you rebase the new junction creator branch against main (or merge in the changes from main)?. Otherwise I can not try it out because I need the other patch from main as well..

mander76 commented 2 years ago

I hope I can do it today, I found a tricky bug with the direct junctions that I'm trying to solve.. After that one I hope I can merge with master aswell

mander76 commented 2 years ago

The branch is rebased and the bugs are hopefully fixed, Won't have time to merge it to master yet though.

johschmitz commented 2 years ago

Nice and no problem, just need something preliminary to develop against when I find time again.

johschmitz commented 2 years ago

One feedback: Why don't you call it JunctionCreatorCommon and JunctionCreatorDirect instead of CommonJunctionCreator and DirectJunctionCreator for alphabetic order similar to the example files? Also don't forget to move the example py files from the root directory to the examples directory.

johschmitz commented 2 years ago

Found there is a bug in add_connection()

        if (
            incoming_road.predecessor
            and incoming_road.predecessor.element_id == self.id
        ):
            incoming_road.pred_direct_junction[linked_road.id] = inc_lane_offset
        else:

            incoming_road.succ_direct_junction[linked_road.id] = inc_lane_offset

        if linked_road.predecessor and linked_road.predecessor.element_id == self.id:
            linked_road.pred_direct_junction[incoming_road.id] = linked_lane_offset
        else:
            linked_road.succ_direct_junction[incoming_road.id] = linked_lane_offset

You are trying to use the ID as an index of the list. I am providing a list lane IDs and it breaks..

Edit: Maybe you have to make it a dictionary instead of a list?

Edit2: The problem appears to be in opendrive.py in line 286:

        self.succ_direct_junction = {}
        if direct_junction is not None:
            self.succ_direct_junction = direct_junction

here direct_junction is a list and so the dictionary becomes a list. Maybe this is me mixing the old and the new API, need to check.

Edit3: Found my mistake, was indeed mixing old and new API. I believe though that you need to remove the direct_junction argument from add_successor() and add_predecessor().

mander76 commented 2 years ago

Yes, it's changed to a dict, couldn't make it work with list as we discussed earlier.

And yes, I should remove that input, good catch

johschmitz commented 2 years ago

Alright, I solved most of my bugs but now I am getting a "Direct junction with multiple offset lanes has not been implemented yet." That is a problem for me since I am trying to build Autobahn exits and there are lots of lanes. Seems to be working when I remove this check though. Will create a little pull request for that.

Edit: See https://github.com/pyoscx/scenariogeneration/pull/110

johschmitz commented 2 years ago

It works now with the patch above, very nice! See a working scenario build using this API attached: bdsc.zip

image

Would be cool if you could release this soon, then I can make a release as well. From my point of view you could first release only the junction creator for the direct junctions and then the one for common junctions later if that helps to reduce the workload.

mander76 commented 2 years ago

Well, the common "works" better as of now actually it's all the different cases with direct that's the problem :P

But I'll check your commit, I want to write some tests about these, I tried a couple of cases the other day and only a few worked.

mander76 commented 2 years ago

I managed to fix the offset for multi lane cases like above. Please try it out. Will look over the documentation then hopefully I can make a release.

johschmitz commented 2 years ago

Will have to try it out after my holidays in about 10 days when I get back to a computer. Meanwhile don't forget to move the examples from the root directory to the examples directory before merging.

mander76 commented 2 years ago

I have create new more documented examples already so the ones there should be removed.

johschmitz commented 2 years ago

Sorry, accidentally closed it with a wrong tap in the mobile browser 😱.

mander76 commented 2 years ago

V0.8.0 released

johschmitz commented 2 years ago

I just tried out your new release and it seems to be working. Very nice. See an example: example.zip

Need to test a bit more and then do a new release of the Blender add-on.

mander76 commented 2 years ago

Cool!

mander76 commented 1 year ago

Can I close this issue @johschmitz ?

johschmitz commented 1 year ago

Yes, so far looking good, will create new issues in case anything comes up.