TrafficSimulation
Abstract
Traffic Simulation
simulates traffic situation follow traffic rules.
Spawn points (Spawnable Lanes) and spawnable vehicles can be configured using components and Traffic Simulation
simulates traffic situation following configuration.
Overview
Traffic Simulation
consists of the following components:
Component | Description |
---|---|
TrafficSimulator | Collecting all traffic simulators and managing the spawning and simulating process. |
NpcVehicleSpawner | Get Npc vehicle states and updating simulation steps. |
NpcVehicleSimulator | Spawning random Npc vehicle in spawning lanes. |
RandomTrafficSimulator | Managing lifecycle of NPCs and simulating NPC behaviours. |
TrafficLane TrafficLight TrafficIntersection StopLine |
Traffic entities. |
NpcVehicle | Vehicle models (NPCs) controlled by RandomTrafficSimulator . |
Configuration
Traffic Simulation
can be configured from TrafficSimulator
component.
The configurable elements are listed in the following table:
General Settings
Parameter | Description |
---|---|
Ego Vehicle | Ego vehicle handler. If not set, the manager creates a dummy ego. This reference is also set automatically when the Ego spawns via the traffic simulator. |
Seed | Seed value for random generator. |
Traffic Intersections | The field that is set TrafficIntersection objects.TrafficIntersection to be set is controlled by Traffic Simulation . |
NPC Vehicle Settings
Parameter | Description |
---|---|
Vehicle Config | Parameters for NPC vehicle control.Sudden Deceleration is a deceleration related to emergency braking. |
Obstacle Layer Mask | The obstacle layer for raytracing the collision distances. |
Ground Layer Mask | The Ground layer for raytracing the collision distances. |
Max Vehicle Count | The maximum number of vehicles that can simultaneously live in the scene. Lowering this value results in less dense traffic but improves the simulator's performance. |
Spawn Distance To Ego | The minimal distance between the EGO and the NPC to spawn. |
Debug
Parameter | Description |
---|---|
Show Gizmos | Enable the checkbox to show all visualization using editor gizmos. |
Show Yielding Phase | Enable the checkbox to show editor gizmos that visualize Yielding Phase of NPCs. |
Show Obstacle Checking | Enable the checkbox to show editor gizmos that visualize Obstacle Checking phase of NPCs. |
Show Spawn Points | Enable the checkbox to show editor gizmos that visualize Spawn Points where NPCs is generated. |
Random Traffic Sims
Parameter | Description |
---|---|
Enable Simulation | Enable the checkbox to Random Traffic Sims which spawn NPC vehicles randomly. |
TrafficSim Npc Vehicle Prefabs | Prefabs representing controlled vehicles. They must have NPCVehicle component attached. |
Spawnable TrafficLanes | TrafficLane components where NPC vehicles can be spawned during traffic simulation. |
Enable Spawn Count Limit | Enable the checkbox to limit of vehicle spawning. |
Spawn Count Limit | The number of limit of vehicles spawning. |
Gizmos
Gizmos are useful for checking current behavior of NPCs and its causes.
Gizmos have a high computational load so please disable them if the simulation is laggy.
The visualizable elements are listed in the following table:
Shape | Description |
---|---|
Rectangle | Yielding Phase of each NPCs to avoid colliding with the other NPCs. |
Arrow | Obstacle Checking of each NPCs to stop in front of the obstacle. |
Diamond | Spawn Points where NPCs is generated by Random Traffic Sims . |
Instruction
To use Traffic Simulation
, please follow the steps below.
For the preparation, the following must be prepared:
- 3D map (.fbx)
- lanelet map (.osm)
1. Place Traffic Simulator
Create empty GameObject
(should be named TrafficSimulator
).
Attach this object to TrafficSimulator
component.
(optional) To place objects which is generated later, you may creat empty objects named TrafficIntersections
and NPCPedestrians
.
2. TrafficIntersection and LaneletTrafficLight settings
Please place intersection objects and attach LaneletTrafficLight
script.
Then, please you set traffic lights to intersection.
Please configure TrafficIntersection
and LaneletTrafficLight
components as the following:
- Add a empty
GameObject
as a child object ofTrafficIntersections
hierarchy- The
GameObject
should be namedTrafficIntersection.x
- The
Transform
ofGameObject
should be set on the target intersection
- The
- Attach a
TrafficIntersection
component to the intersection game object - Attach
LaneletTrafficLight
to traffic light objects placed on the target intersection - Modify
Bulb Material Config
as follow images
vehicle raffic light
pedestrian traffic light
- If there are wrong order of bulb, modify each
Bulb Material Config
- If there are wrong order of bulb, modify each
- Set traffic light objects attached
LaneletTrafficLight
in step. 3 toTrafficLightGroups
inTrafficIntersection
- Traffic lights which should light same sequences should be set on same
TrafficLightGroups
- Traffic lights which should light same sequences should be set on same
Warning
Do not attach LaneletTrafficLight
to traffic lights which are not set to TrafficIntersection
.
It causes errors.
Info
For detailed settings of Bulb Material Config
, see here.
Modify Lighting Sequences
If you need to set an arbitrary signal control pattern, you can modify it in Lighting Sequences
field.
Create any number of of lements of Lighting Sequences
and set parameters for each one.
When the scene plays, the Lighting Sequences
will execute sequentially from Element 0
.
In addition, when the last element completes, the sequence will loop back to Element 0
.
The Waypoint settings
parameters are listed in the following table:
Lighting Sequences
Parameter | Description |
---|---|
Interval Sec | Duration for which this sequence continues. |
Group Lighting Orders | Settings for lighting each TrafficLightGroups . |
Group Lighting Orders
Parameter | Description |
---|---|
Group | Target TrafficLightGroups . |
Bulb Data | Setting for lighting each bulb in traffic lights within TrafficLightGroups . |
Bulb Data
Parameter | Description |
---|---|
Type | Target bulb. |
Color | Color of lighting on target bulb. |
Status | Type of lighting. (Solid On, Solid Off and Flashing) |
Set right of ways on uncontrolled intersections
On intersections without traffic lights, it is needed to set the right of way of TrafficLane manually for the vehicles to operate properly.
Please configure TrafficLane
components as the following:
- Select a straight lane that should be right of way in the intersection
- The selected lane should be highlighted
- Click the
Set RightOfWays
button to give the lane priority over other lanes
Please check if all lanes that intersect with the selected lane are highlighted yellow.
This means that the right of way was applied correctly.
3. Load lanelet
LaneletLoader
can load a lanelet map and create TrafficLane
and StopLine
.
In addition, LaneletLoader
set parameter of traffic rules to TrafficLane
, StopLine
and traffic lights.
LaneletLoader
can be performed by opening AWSIM -> Common -> Load Lanelet
at the toolbar of Unity Editor.
Please use LaneletLoader
as the following:
1. Fill in Osm
field with a lanelet map (.osm
) you prepared, Root Object
field with a TrafficSimulator
object.
2. Adjust Waypoint settings
parameters for the loading process if needed.
3. To load the lanelet map, please click Load
button.
The Waypoint settings
parameters are listed in the following table:
Parameter | Description |
---|---|
Resolution | Resolution of resampling. Lower values provide better accuracy at the cost of processing time. |
Min Delta Length | Minimum length(m) between adjacent points. |
Min Delta Angle | Minimum angle(deg) between adjacent edges. Lowering this value produces a smoother curve. |
TrafficLane
, StopLine
and TrafficLight
will be generated and placed as child objects of the Root Object
.
You can check their visual representation by clicking consecutive elements in the scene hierarchy.
4. TrafficSimulator setting
Please configure TrafficSimulator
component as the following:
- Fill in
Ego Vehicle
field with EGO vehicle- Example:
EgoVehicle/Lexus RX450h 2015
- Example:
- Change
Obstacle Layer Mask
andGround Layer Mask
field toEverything
- Fill in
Traffic Intersections
field withTrafficIntersection
objects - Fill in
Random Traffic Sims
field- Fill in
Traffic Sim Npc Vehicle Prefab
field with vehicle prefabs what you want to spawn- Prefabs is in
Assets/Awsim/Prefabs/Usecase/TrafficSimulation/
- Prefabs is in
- Fill in
Spawnable Traffic Lanes
field withTrafficLane
where you want to spawn vehicles
- Fill in
Info
For detailed settings of TrafficSimulator
, see here.
5. Place Pedestrian (optional)
You can place pedestrian NPCs if needed.
Pedestrians can animated and walk around where they are placed.
Direction which pedestrian start to walking can be set in Transform
of it.
Please configure pedestrian NPCs as the following:
- Place pedestrian prefabs on a scene
- Prefabs is in
Assets/Awsim/Prefabs/Entity/Npc/Pedestrian/
- Pedestrians should be child object of
NPCPedestrians
hierarchy
- Prefabs is in
- Attach
SimplePedestrianWalkerController
component to pedestrians - (optional) Configure parameters of
SimplePedestrianWalkerController
The parameters of SimplePedestrianWalkerController
are listed in the following table:
Parameter | Description |
---|---|
Duration | Duration at which the pedestrian walk. |
Speed | Speed at which the pedestian walk. |
6. Call methods of TrafficSimulator
To enable Traffic Simulation
, some methods of TrafficSimulator
should be called from callback of MonoBehaviour
.
Please create or open class which is inherit MonoBehaviour
and make field of TrafficSimulator
.
Then, add description of calling method of TrafficSimulator
.
The method should be called are listed in the following table:
Method | Description |
---|---|
Initialize() | Should be called Start() callback. |
OnUpdate() | Should be called Update() callback. |
OnFixedUpdate() | Should be called FixedUpdate() callback. |
Info
AWSIM includes AutowareSimulationDemo
scene.
Please refer to:
* Assets/Awsim/Scenes/AutowareSimulationDemo/AutowareSimulationDemo.cs
* Assets/Awsim/Scenes/AutowareSimulationDemo.unity
scene
Call methods of Pedestrian (optional)
To move Pedestrian, some methods of SimplePedestrianWalkerController
should be called same as TrafficSimulator
.
Please create or open class which is inherit MonoBehaviour
and make field of SimplePedestrianWalkerController[]
.
Then, add description of calling method of each element of SimplePedestrianWalkerController[]
using for loop.
The method should be called are listed in the following table:
Method | Description |
---|---|
Initialize() | Should be called Start() callback. |
OnUpdate() | Should be called Update() callback. |
OnFixedUpdate() | Should be called FixedUpdate() callback. |