diff --git a/README.md b/README.md index 4e95132..7e5775d 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,8 @@ python3 examples/demo_offensive.py python3 examples/demo_defensive.py ``` +[Visualization](./docs/SIM_VIEW.md) + ### 6. Run StableBaselines Training (Docker) ```sh @@ -98,6 +100,9 @@ docker compose build && docker compose run \ ### 7. Edit Maps +The preferred way to create maps: [SVG Editor](./docs/SVG_MAP_EDITOR.md) + +This Method is deprecated: ```sh sudo apt-get update && sudo apt-get install -y python3-tk ``` @@ -114,3 +119,19 @@ python3 -m map_editor docker-compose build && docker-compose run \ robotsf-cuda python ./scripts/hparam_opt.py ``` + +### 9. Extension: Pedestrian as Adversarial-Agent + +The pedestrian is an adversarial agent who tries to find weak points in the vehicle's policy. + +The Environment is built according to gymnasium rules, so that multiple RL algorithms can be used to train the pedestrian. + +It is important to know that the pedestrian always spawns near the robot. + +![demo_ped](./docs/video/demo_ped.gif) + +```sh +python3 examples/demo_pedestrian.py +``` + +[Visualization](./docs/SIM_VIEW.md) diff --git a/docs/SIM_VIEW.md b/docs/SIM_VIEW.md new file mode 100644 index 0000000..8991210 --- /dev/null +++ b/docs/SIM_VIEW.md @@ -0,0 +1,23 @@ +# robot-sf + +## SIM VIEW + +### About + +The [sim_view.py](../robot_sf/render/sim_view.py) file manages the visualization of the simulation.\ +If you want to change the colors or display more information you have to adjust this file. + +### Key Events + +Multiple key shortcuts are implemented: + +- **Arrow keys**: Move camera +- **CTRL + Arrow keys**: Move fast +- **ALT + Arrow keys**: Move slow +- **+**: Scale up +- **-**: Scale down +- **r**: Reset view +- **f**: Focus Robot +- **p**: Focus Pedestrian +- **h**: Display help +- **q**: Display information: none -> robot -> pedestrian if present -> none -> ... diff --git a/docs/SVG_MAP_EDITOR.md b/docs/SVG_MAP_EDITOR.md new file mode 100644 index 0000000..3d5ca93 --- /dev/null +++ b/docs/SVG_MAP_EDITOR.md @@ -0,0 +1,80 @@ +# robot-sf + +## SVG Map Editor + +### About + +This file explains how to build a map for robot-sf using a svg-editor. +All examples are made with [inkscape](https://inkscape.org/). +![example](./img/inkscape_example.png) + +### Setup + +These settings should be checked before building a map. + +- Use **px** as global unit (File -> Document Properties) + +- Use absolute coordinates for your path, marked by the **M**.\ +(Edit -> Preferences -> Input/Output -> SVG Output -> Path string format -> Absolute) + +*Inkscape version: 1.3.2* + +[Further reference](https://github.com/ll7/robot_sf_ll7/issues/40) + +### Building the map + +Colours can be selected as desired, as the simulation uses its own colour scheme. +However, it is best to remain consistent to make the map easier to understand. + +The most important part is setting the label. In Inkscape this can be done by double-clicking the object in the layers-and-objects list on the right side or by right-clicking the object and selecting the object properties. + +Use layers to make it clearer. + +#### Obstacles + +Obstacles should be avoided by the vehicle and the pedestrians.\ +Draw them by using the rectangle tool.\ +Set the label to **obstacle** + +[Obstacle Issue](https://github.com/ll7/robot_sf_ll7/issues/55) + +#### Robot + +The robot needs a spawn zone to define his starting position and a goal zone he needs to reach to finish the episode.\ +Multiple zones can be used.\ +Draw them by using the rectangle tool.\ +Set the labels to **robot_spawn_zone** and **robot_goal_zone** + +The robot path defines the route the robot takes, while reaching the goal zone.\ +Use the pen tool for this and perform multiple left clicks to set waypoints along the path.\ +The path should not start or end inside the spawn/goal zone, but just before it.\ +Set the label to **robot_route_\_\** + +(e.g. robot_route_1_0 -> Using Spawn 1 and Goal 0.\ +The zone numbers are counted from bottom to top in the list on the right-hand side) + +#### NPC Pedestrians + +The Pedestrians also need a spawn/goal zone. If they reach the goal they will spawn again at the start\ +Set the labels to **ped_spawn_zone** and **ped_goal_zone** + +For the path you don't need to set specific waypoints, just make sure the path doesn't collide with an obstacle.\ +Set the label to **ped_route_\_\** + +### Colours + +Colours used in the example map: + +- obstacle: #000000 +- robot_spawn_zone: #ffdf00 +- robot_goal_zone: #ff6c00 +- robot_route: #0300d5 and #0078d5 +- ped_spawn_zone: #23ff00 +- ped_goal_zone: #107400 +- ped_route: #c40202 + +The colours for the simulation can be found here: [sim_view.py](../robot_sf/render/sim_view.py) + +### New Features + +If you want to implement new features: [svg_map_parser.py](../robot_sf/nav/svg_map_parser.py) diff --git a/docs/img/inkscape_example.png b/docs/img/inkscape_example.png new file mode 100644 index 0000000..bcf6221 Binary files /dev/null and b/docs/img/inkscape_example.png differ diff --git a/docs/video/demo_ped.gif b/docs/video/demo_ped.gif new file mode 100755 index 0000000..9ede9ba Binary files /dev/null and b/docs/video/demo_ped.gif differ diff --git a/maps/svg_maps/03_mid_object.svg b/maps/svg_maps/03_mid_object.svg deleted file mode 100644 index 7d4ee70..0000000 --- a/maps/svg_maps/03_mid_object.svg +++ /dev/null @@ -1,129 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/maps/svg_maps/04_small_mid_object.svg b/maps/svg_maps/04_small_mid_object.svg deleted file mode 100644 index ee04e78..0000000 --- a/maps/svg_maps/04_small_mid_object.svg +++ /dev/null @@ -1,129 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/maps/svg_maps/debug_01.svg b/maps/svg_maps/debug_01.svg deleted file mode 100644 index d45b79a..0000000 --- a/maps/svg_maps/debug_01.svg +++ /dev/null @@ -1,147 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/maps/svg_maps/debug_03.svg b/maps/svg_maps/debug_03.svg deleted file mode 100644 index 3bb1379..0000000 --- a/maps/svg_maps/debug_03.svg +++ /dev/null @@ -1,158 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/maps/svg_maps/example_map.svg b/maps/svg_maps/example_map.svg new file mode 100644 index 0000000..4f30be4 --- /dev/null +++ b/maps/svg_maps/example_map.svg @@ -0,0 +1,171 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/map_test.py b/tests/map_test.py index 5313de0..9a9e376 100644 --- a/tests/map_test.py +++ b/tests/map_test.py @@ -124,7 +124,7 @@ def test_proximity_point(): lower_bound = 15 upper_bound = 20 env_config = PedEnvSettings() - svg_file = "maps/svg_maps/debug_03.svg" + svg_file = "maps/svg_maps/debug_06.svg" map_def = convert_map(svg_file) _sim = init_ped_simulators(env_config, map_def)[0] new_point = _sim.get_proximity_point(