Simulator: Increasing the NPC traffic infront/adjacent of the ego vehicle

Created on 22 Jul 2020  路  9Comments  路  Source: lgsvl/simulator

Hey team!

I would like to increase the NPC traffic around the ego vehicle. I read in this issue -- https://github.com/lgsvl/simulator/issues/843#issuecomment-654955329, that it is done intentionally.

I'm not using PythonAPI. So I would like to edit the code directly in Unity and build the simulator.

My requirements -

  1. Increase the number of NPCs around the EGO and constantly present. I use SF map.
  2. Increase the threshold of cars waiting at the signal.

I use 2020.03 version as the 2020.05 exposure level is too low and dark for EGO to detect/follow a lane.

It would be great if you can please list the steps/files to be edited, to accomplish the task. Apart from building the simulator, adding/editing files, I would say I'm still a beginner in Unity.

Thank you.

answered

All 9 comments

@dr563105 Let me see if I can help with this.
There are a couple of places we need to edit in code and scene objects

  • MapOrigin. This has options for maps to increase NPCs. We max this value because of fps issues. You can increase this in code if you want. I suggest the other changes first before changing the max
    NPCHelp0
  • Next is NCPManager.cs. Here you can remove the check for Spawnable (This checks to see if it is an edge lane of the map. You can remove this so it uses any lane within the spawn area set in MapOrigin that follows the ego)
  • Finally you can remove the isVisible check. This checks if any sensors "see" the npc when it tries to spawn and aborts if it will be visible on spawn.
    NPCHelp1

As per your requests this will increase the vehicles around the EGO but does not make more vehicles at a light (NPCs need to start at lane index 0 to be sure to traverse the lane waypoints correctly and calculate lane changes/stoplights/traffic lights). If you need this much control of NPC's, I recommend setting manually with the python API. Another issue is FPS. We have tested NPC counts with baseline hardware and going over this can and will have undesired issues. We are looking into Unity's DOTs systems to increase npc's/pedestrian/others counts but it will be a while before this is released. Hope this helps.

Thanks Eric. I first tried with changes in NPCManager.cs, though it had increase in NPC, there were areas where there were none. Only on changing lanes, turning at an intersection, I could make the spawn happen. Sometimes that was also not happening.

Is it possible to make more NPCs do the changing lane frequently?

Then I increased the NPC max count in SF map origin. It originally had 20. I raised it to 30 which is the max limit. Tested it again. I couldn't see much difference in traffic. In certain areas in the map, certainly get more traffic than others.
Then I changed the NPC max count in here. I couldn't see an improvement.

That count is it map related or the change I did is correct?

Is it possible to increase the red stop signal light duration? Which file/line handles that? That way I can expose my NN to the traffic light.

I'm testing for object detection and without a lot of NPCs, the NN can't learn from the images. These changes give me an improvement from the default case.

No problem. Lane change is in the NPC controller code and I don't recommend changing this. You could try to get a random index that is lane.worlpoints.length - 1 in NPCManager.cs. This would open more places to spawn on the lanes but may have odd NPC behavior. Then, you could reduce the size of the spawn area in MapOrigin. This would try to spawn closer to the ego. Lastly, the traffic light timings can be adjusted with the API or in the code here.
SignalHelp0

Thanks Eric.

I changed the signal labels in that file. I think I'm getting good waiting time.

Regarding changing the value, I think you meant this variable lane.mapWorldPositions.Count present in this line
var lane = mapManager.GetLane(RandomGenerator.Next(mapManager.trafficLanes.Count)); in NPCManager.cs.
Which gets the value from mapManager. So I'm kind of lost where to initialise the value. Can you please help?
Despite that I can say I'm getting a good NPC traffic behaviour.

@dr563105 Close but no, the line I am referencing is this.
NPCHelp3
This could be converted to a random index instead of 0 but you need to exclude the last index or npcs will have issues with traffic signals and stop signs. You may even want to exclude last 2 indexes if there are > 3 waypoints. This will let multiple npcs spawn on one lane, giving you better density. Leave the var lane as is, this makes sure you are not selecting an intersection lane that will really mess up npc behavior.

Thanks again Eric. I will close this issue for now. When I have issues again, I will reopen it.

I have a new requirement - is it possible to slow the NPCs way down, easily with a few changes to the code?

I looked into the code and did some changes to NPCController, NPCLaneController and others. I made some crude hacks to see it was really possible. It was. The vehicles slowed down enough to form an envoy around ego. However, I was hit with multiple null exceptions.

@dr563105 I think the only way would be to adjust the speed limit on the mapLane annotation. Sorry, we have not made this for random traffic, only API

I thought so. Thanks. I finally got the hang of driving alongside NPC matching its pace. Some glorious crashes, some mad NPC driving and lots of fun.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wsp50317 picture wsp50317  路  5Comments

kmitri-dxc picture kmitri-dxc  路  5Comments

ck-leo picture ck-leo  路  5Comments

clepz picture clepz  路  6Comments

yumianhuli2 picture yumianhuli2  路  3Comments