Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9fe82e9
commit 43a18a3
Showing
5 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Simulation | ||
|
||
Simulation can be done using the `simulate!` function. | ||
A simulation updates the initial scene forward in time. Each simulation step consists of the following operation: | ||
- get the actions of each agent in the scene by calling `observe!` on their respective behavior model (see the behavior section for more information) | ||
- update the scene forward using `tick!`. It consists in applying the individual actions of each agent and updates their states individually. The actions can be of different type for each vehicle. The state is updated by calling the `propagate` method associated to the corresponding action type. (This done automatically thanks to Julia's mutliple dispatch). See the action section for more information on the `propagate` method. | ||
- repeat for the desired number of steps | ||
|
||
See the tutorials for examples. | ||
|
||
```@docs | ||
get_actions! | ||
tick! | ||
simulate! | ||
``` | ||
|
||
## Callbacks | ||
|
||
One can define callback function that will be run at each simulation step. The callback function can interrupt the simulation if it return `false`. It is also useful to log simulation information. | ||
|
||
To implement a custom callback function you must implement a type and the associated `run_callback` method. Here is an example of a callback that checks if a vehicle longitudinal position has reached some goal position and stops the simulation if it is the case. | ||
```julia | ||
struct ReachGoalCallback # a callback that checks if vehicle veh_id has reach a certain position | ||
goal_pos::Float64 | ||
veh_id::Int64 | ||
end | ||
|
||
function AutomotiveDrivingModels.run_callback(cb::ReachGoalCallback, rec::EntityQueueRecord{S,D,I}, | ||
roadway::R, | ||
models::Dict{I,M}, | ||
tick::Int, | ||
) where {S,D,I,R,M<:DriverModel} | ||
veh = get_by_id(rec[0], cb.veh_id) | ||
return veh.state.posF.s > cb.goal_pos | ||
end | ||
``` | ||
|
||
A callback for collision is already implemented: `CollisionCallback`. | ||
|
||
```@docs | ||
run_callback | ||
CollisionCallback | ||
``` | ||
|
||
## Others | ||
|
||
```@docs | ||
reset_hidden_states! | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# States | ||
|
||
In this section of the documentation we explain the default vehicle state type provided by `AutomotiveDrivingModels` | ||
as well as the data types used to represent driving scene. Most of the underlying structures are defined in `Records.jl`. | ||
The data structure provided in ADM.jl are concrete instances of parametric types defined in Records. It is possible in principle to define your custom state definition and use the interface defined in ADM.jl. | ||
|
||
## Agent States | ||
|
||
Agents are represented by the entity data type provided by `Records.jl`. | ||
The entity data type has three field: a state, a definition, and an id. | ||
|
||
The state of an entity usually describes physical quantity such as position and velocity. | ||
|
||
|
||
## Scenes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters