pyoscx / scenariogeneration

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

How to make turns in junction #179

Closed GilgameshD closed 9 months ago

GilgameshD commented 10 months ago

Hi,

I am trying to design a right-turn scenario in a 4-way junction. However, I don't know how to select the right-turn lane when the vehicle enters the junctions. Is there any example I can refer to?Thanks.

eknabevcc commented 10 months ago

Routes are perfect for this use case. I think here's an example: examples/xosc/route_in_crossing.py

Without assigned route, the vehicle will choose randomly between options in intersections.

GilgameshD commented 10 months ago

thanks!

GilgameshD commented 10 months ago

Hi,

I tried the route method but I found that sometimes the vehicle still randomly selects lanes. My code for assigning a route is below. My goal is to make vehicle2 go straight so I select a route point on road2.

name_v2 = "Vehicle2"
speed_v2 = 8
entities.add_scenario_object(name_v2, xosc.CatalogReference("VehicleCatalog", "car_white"))
init.add_init_action(name_v2, xosc.TeleportAction(xosc.LanePosition(s=50, offset=0, lane_id=-1, road_id=0, orientation=xosc.Orientation(0, 0, 0))))
step_time_v2 = xosc.TransitionDynamics(shape=xosc.DynamicsShapes.step, dimension=xosc.DynamicsDimension.time, value=1)
init.add_init_action(name_v2, xosc.AbsoluteSpeedAction(speed_v2, step_time_v2))
route_v2 = xosc.Route("route_v2")
route_v2.add_waypoint(xosc.LanePosition(s=60, offset=0, lane_id=-1, road_id=0), xosc.RouteStrategy.shortest)
route_v2.add_waypoint(xosc.LanePosition(s=30, offset=0, lane_id=-1, road_id=2), xosc.RouteStrategy.shortest)
action_v2 = xosc.AssignRouteAction(route_v2)
event_v2 = xosc.Event("event_v2", xosc.Priority.override)
event_v2.add_action("route_v2", action_v2)
event_v2.add_trigger(xosc.ValueTrigger("target_start", 0, xosc.ConditionEdge.none, xosc.SimulationTimeCondition(1, xosc.Rule.greaterThan)))
man_v2 = xosc.Maneuver("man_v2")
man_v2.add_event(event_v2)

But I got the trajectory like this: road_traj

eknabevcc commented 10 months ago

Make sure the waypoints are exactly achievable from the initial position of the car.

Suggestion is to have the first waypoint identical to initial position, including same lane id. Next waypoint can be on the desired road and lane id after the intersection.

If still not working, please share the complete script and OpenDRIVE for our investigation.

GilgameshD commented 9 months ago

Thanks for helping. I think I finally found the cause of the problem. It seems that setting the fixed_timestep to a small number (in my case 0.05) would introduce some randomness. Increasing the fixed_timestep to 0.1 solves my problem. But I still wonder where the randomness comes from.

eknabevcc commented 9 months ago

Now you made me extremely curious :)

Smaller timesteps should definitely not make a difference. Would it be possible to share the script/scenario?

If not the complete, maybe you can share a reduced version including the necessary for reproducing the issue.

It might be that you encountered a bug, but it can also be some, not obvious, aspect of the scenario itself. I'd be glad to investigate.

One possibility is to send the scenario by mail. Find my mail address at bottom of this page: https://sites.google.com/view/simulationscenarios

eknabevcc commented 9 months ago

Thanks for providing the scenario via mail.

Indeed you found a bug in esmini. When entering an intersection, just on the edge between incoming and connecting road, there could arise confusion wrt road id. Actually, while investigating I found another bug related to route handling in intersections.

Both issues should now be solved by commit 4d93eaf. It's merged on dev branch. It will automatically be merged to master by next release.

Hopefully you can build esmini yourself if you need the fix immediately. Otherwise, let us know if you need a release asap.

GilgameshD commented 9 months ago

Thanks for solving this problem!