Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Envision won't render custom scenario #1874

Closed
ajlangley opened this issue Feb 18, 2023 · 5 comments · Fixed by #1876
Closed

Envision won't render custom scenario #1874

ajlangley opened this issue Feb 18, 2023 · 5 comments · Fixed by #1876
Labels
help wanted Extra attention is needed

Comments

@ajlangley
Copy link
Contributor

ajlangley commented Feb 18, 2023

High Level Description
I have made a custom road network using SUMO. The issue is that Envision won't render the scenario (the whole browser window goes black the instant an ego vehicle enters the scene).

Desired SMARTS version
1.0.3

Operating System
Ubuntu 20.04

Problems
I have the following custom road network. In map.nod.xml, I have

<?xml version="1.0" encoding="UTF-8"?>

<nodes>
    <node id="J0" x="0.0" y="0.0" />
    <node id="J1" x="20.0" y="0.0" />
    <node id="J2" x="30.0" y="0.0" />
    <node id="J3" x="40.0" y="0.0" />
    <node id="J4" x="60.0" y="0.0" />
    <node id="J5" x="30.0" y="10.0" />
    <node id="J6" x="30.0" y="30.0" />
    <node id="J7" x="30.0" y="-10.0" />
    <node id="J8" x="30.0" y="-30.0" />
</nodes>

and in map.edg.xml I have

<?xml version="1.0" encoding="UTF-8"?>

<edges>
    <edge from="J0" to="J1" id="0to1" />
    <edge from="J1" to="J0" id="1to0" />
    <edge from="J1" to="J2" id="1to2" />
    <edge from="J2" to="J1" id="2to1" />
    <edge from="J2" to="J3" id="2to3" />
    <edge from="J3" to="J2" id="3to2" />
    <edge from="J3" to="J4" id="3to4" />
    <edge from="J4" to="J3" id="4to3" />
    <edge from="J2" to="J5" id="2to5" />
    <edge from="J5" to="J2" id="5to2" />
    <edge from="J5" to="J6" id="5to6" />
    <edge from ="J6" to="J5" id="6to5" />
    <edge from="J2" to="J7" id="2to7" />
    <edge from="J7" to="J2" id="7to2" />
    <edge from="J7" to="J8" id="7to8" />
    <edge from="J
8" to="J7" id="8to7" />
</edges>

I built the map file, map.net.xml using the command
netconvert --node-files=hello.nod.xml --edge-files=hello.edg.xml --output-file=map.net.xml
Finally, in my scenario file, scenario.py, I have

from pathlib import Path

from smarts.core import seed
from smarts.sstudio.genscenario import gen_scenario
import smarts.sstudio.types as t

routes = [
    t.Route(begin=('0to1', 0, 'random'), end=('2to3', 0, 'random'))
]
ego_missions = [t.Mission(route=route) for route in routes]

gen_scenario(
    scenario=t.Scenario(
        ego_missions=ego_missions),
    output_dir=Path(__file__).parent
)

Now, when I run Envision and attempt to visualize this scenario with a single ego vehicle, the road network pops up, but then the entire browser window (everything under the search bar) goes completely black as soon as the vehicle enters the scene. This has something to do with the choice of mission, as when I replace the route with
t.Route(begin=('1to2', 0, 'random'),end=('2to3', 0, 'random')
it renders as expected. Basically, the only missions is will render are
1to2 -> 2to3
3to2 -> 2to1
5to2 -> 2to7
7to2 -> 2to5

Is there any idea what's going on?

P.S.: Thanks for all of the assistance recently.

@ajlangley ajlangley added the help wanted Extra attention is needed label Feb 18, 2023
@ajlangley ajlangley changed the title Envision won't render scenario Envision won't render custom scenario Feb 18, 2023
@Gamenot
Copy link
Collaborator

Gamenot commented Feb 18, 2023

Thank you for the request @ajlangley, I am going to try this out to see what might be wrong.

@Gamenot
Copy link
Collaborator

Gamenot commented Feb 19, 2023

Error

The browser console notes the following issue:

Uncaught TypeError: Cannot read properties of undefined (reading 'equalsWithEpsilon')
    at Function.PolygonBuilder.CreatePolygon (polygonBuilder.js:116)
    at Function.MeshBuilder.CreatePolygon (meshBuilder.js:456)
    at mission_routes.js:64
    at Array.forEach (<anonymous>)
    at _loop (mission_routes.js:62)
    at mission_routes.js:61
    at commitHookEffectListMount (react-dom.development.js:19731)
    at commitPassiveHookEffects (react-dom.development.js:19769)
    at HTMLUnknownElement.callCallback (react-dom.development.js:188)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:237)

mission_routes.js:64

let polygon = MeshBuilder.CreatePolygon(
`mission-route-shape-${vehicle_id}-${shape_id}`,
{ shape: points },
scene
);

From that I note that somehow an empty array managed to make it into missionRoutes through mission_route_geometry.

image

And appears to come from:

SMARTS/smarts/core/smarts.py

Lines 1508 to 1515 in c2edd5d

if self._agent_manager.is_ego(agent_id):
actor_type = envision_types.TrafficActorType.Agent
if filter.actor_data_filter["mission_route_geometry"].enabled:
mission_route_geometry = (
self._vehicle_index.sensor_state_for_vehicle_id(
v.actor_id
).plan.route.geometry
)

It looks like one of the lanes generated is unexpectedly 0 length and thus would not have any geometry:

<smarts.core.sumo_road_network.SumoRoadNetwork.Road object at 0x7ff192c76fa0>
(Pdb) route.roads[1].lanes
[<smarts.core.sumo_road_network.SumoRoadNetwork.Lane object at 0x7ff192c76f70>]
(Pdb) route.roads[1].lanes[0].lane_id
':J1_1_0'
(Pdb) route.roads[1].lanes[0].length
0.0

The generated file gives the lane which means the conversion is somehow reducing the length of the lane. It is not large enough to be decimal error but enough that inaccuracy could cause it.

    <edge id=":J1_1" function="internal">
        <lane id=":J1_1_0" index="0" speed="13.89" length="0.10" shape="20.00,28.40 20.00,28.40"/>
    </edge>

Checking SUMO for underlying problems it appears that SUMO caused the issue because the sumo shape does not match the length both above and below:

(Pdb) route.roads[1].lanes[0].lane_id
':J1_1_0'
(Pdb) route.roads[1].lanes[0].length
0.0
(Pdb) route.roads[1].lanes[0]._sumo_lane.getShape()
[(20.0, 28.4), (20.0, 28.4)]
(Pdb) route.roads[1].lanes[0]._sumo_lane.getLength()
0.1

It may be a rounding error within SUMO's shape generation.

netconvert options do not seem to help. I think the netconvert behavior can be filed as an issue against the https://github.com/eclipse/sumo repository.

@Gamenot
Copy link
Collaborator

Gamenot commented Feb 19, 2023

I will have to think about what should be done about this issue. We did not anticipate 0 length lanes.

@Gamenot
Copy link
Collaborator

Gamenot commented Feb 19, 2023

I have applied a fix.

@ajlangley
Copy link
Contributor Author

Thank you for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants