In this example we will walk through creating a Model
module. This Model will simply have pedestrians walking in circles around their initial position.
- Create Folder and Files We will create the following:
modules/model/ExampleModel
modules/model/ExampleModel/ExampleModel.hpp
modules/model/ExampleModel/CMakeLists.txt
- Create the model
#include <vipra.hpp>
VIPRA_NEW_MODULE(ExampleModel, Model) {
public:
VIPRA_MODULE_NAME("ExampleModel")
VIPRA_MODULE_TYPE(Model)
VIPRA_REGISTER_PARAMS (
VIPRA_PARAM("radius", _radius);
)
VIPRA_MODEL_INIT_STEP {
_initialPoints = pedset.all_coords();
}
VIPRA_MODEL_TIMESTEP {
for (size_t i = 0; i < pedset.num_pedestrians(); ++i) {
state.positions[i] =
VIPRA::f3d{_initialPoints[i][0] + _radius * std::cos(deltaT * timestep),
_initialPoints[i][1] + _radius * std::sin(deltaT * timestep)};
}
}
private:
VIPRA::f_pnt _radius;
VIPRA::f3dVec _initialPoints;
};
- Update
main.cpp
to use our new model
#include <vipra.hpp>
#include "modules/model/calm_model/calm_model.hpp"
auto main() -> int {
auto sim = VIPRA::simulation(
Example::Model{},
VIPRA::Pedestrians::Grid{},
VIPRA::Module::Output{
VIPRA::Output::Trajectories::Json{}
}
);
sim(
VIPRA::Input::Json{"maps/pedestrians/a320/a320_144_pedestrians.json"},
VIPRA::Input::Json{"maps/obstacles/a320/a320_polygons.json"}
VIPRA::Input::Json{"examples/module_params.json"}
}
);
}
Goals module that uses the A* algorithm to find the path to the goal.
Definition astar.hpp:23
Map module that uses a quadtree to store obstacles.
Definition quad_tree.hpp:17
Definition parameters.hpp:20
- Update the
module_params.json
{
"simulation": {
"main": {
"max_timestep": 10000,
"timestep_size": 0.005,
"output_frequency": 100,
"random_seed": 12345
}
},
"model": { // Since our module is a model we put the parameters under the "model" field
"example_model": { // We add in a field with our module name
"radius": 0.2 // Here is our radius parameter
}
},
"goals": {
"astar": {
"endGoalType": "exit",
"gridSize": 0.1,
"closestObstacle": 0.25,
"goalRange": 0.05
}
},
"pedestrians": {
"grid": {
"gridSize": 0.5
}
},
"obstacles": {
"quad_tree": {
"minQuadSize": 0.05
}
},
"output": {
"coordinator": {
"output_dir": "./output"
},
"trajectories_json": {
"filename": "trajectories.json"
}
},
"behavior_model": {
"main": {
"behaviors_dir": "./behaviors",
"behaviors": []
}
}
}
- Adding
CMakeLists.txt
See the Base Module Implementation to see more.
- Compile Simulation
The simulation can be compiled by running
- Run
Run the simulation with
The output will be under ./output/trajectories.json