|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "10174b23-25f5-45d2-85a2-43985ce76950", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "In this notebook, we explore basic analysis of the positions and speeds to detect similarities and differences between behaviouirs.\n", |
| 9 | + "\n", |
| 10 | + "We start importing some libraries." |
| 11 | + ] |
| 12 | + }, |
| 13 | + { |
| 14 | + "cell_type": "code", |
| 15 | + "execution_count": null, |
| 16 | + "id": "35f7c19a-b478-4fa9-9451-2722d6275e7c", |
| 17 | + "metadata": {}, |
| 18 | + "outputs": [], |
| 19 | + "source": [ |
| 20 | + "import numpy as np\n", |
| 21 | + "import matplotlib.pyplot as plt\n", |
| 22 | + "import matplotlib as mpl\n", |
| 23 | + "import os\n", |
| 24 | + "\n", |
| 25 | + "import perdiver.perdiver as perdiver\n", |
| 26 | + "\n", |
| 27 | + "from navground import core, sim\n", |
| 28 | + "\n", |
| 29 | + "plots_dir = os.path.join(\"plots\", \"visualisation\")\n", |
| 30 | + "experiment_dir = \"experiments\"\n", |
| 31 | + "os.makedirs(plots_dir, exist_ok=True)\n", |
| 32 | + "os.makedirs(\"experiments\", exist_ok=True)" |
| 33 | + ] |
| 34 | + }, |
| 35 | + { |
| 36 | + "cell_type": "code", |
| 37 | + "execution_count": null, |
| 38 | + "id": "f88c00d1-7647-4543-8357-965de185f7ec", |
| 39 | + "metadata": {}, |
| 40 | + "outputs": [], |
| 41 | + "source": [ |
| 42 | + "# Small Corridor\n", |
| 43 | + "length = 8\n", |
| 44 | + "width=1.0\n", |
| 45 | + "# Large Corridor\n", |
| 46 | + "# width=1.5\n", |
| 47 | + "# length = 15.0\n", |
| 48 | + "num_steps = 400\n", |
| 49 | + "\n", |
| 50 | + "num_agents = 11 # 31\n", |
| 51 | + "num_runs = 1\n", |
| 52 | + "behaviour_list = [\"ORCA\", \"HL\", \"HRVO\", \"Dummy\"]\n", |
| 53 | + "marker_behaviour = {\"ORCA\": \"o\", \"HL\": \"X\", \"HRVO\": \"+\", \"Dummy\": \"*\"}\n", |
| 54 | + "color_behaviour = {}\n", |
| 55 | + "for i, behaviour in enumerate(behaviour_list):\n", |
| 56 | + " color_behaviour[behaviour] = mpl.colormaps[\"Set1\"](i / (len(behaviour_list) +1))\n", |
| 57 | + "for behaviour in behaviour_list:\n", |
| 58 | + " path = os.path.join(experiment_dir, f\"visualisation_{behaviour}.h5\")\n", |
| 59 | + " yaml = f\"\"\"\n", |
| 60 | + " steps: {num_steps}\n", |
| 61 | + " time_step: 0.1\n", |
| 62 | + " record_pose: true\n", |
| 63 | + " record_twist: true\n", |
| 64 | + " runs: {num_runs}\n", |
| 65 | + " record_collisions: true\n", |
| 66 | + " record_deadlocks: true\n", |
| 67 | + " record_safety_violation: true\n", |
| 68 | + " record_efficacy: true\n", |
| 69 | + " terminated_when_idle_or_stuck: false\n", |
| 70 | + " scenario:\n", |
| 71 | + " type: Corridor\n", |
| 72 | + " length: {length}\n", |
| 73 | + " width: {width} \n", |
| 74 | + " groups:\n", |
| 75 | + " -\n", |
| 76 | + " type: thymio\n", |
| 77 | + " number: {num_agents}\n", |
| 78 | + " radius: 0.08\n", |
| 79 | + " control_period: 0.1\n", |
| 80 | + " speed_tolerance: 0.02\n", |
| 81 | + " kinematics:\n", |
| 82 | + " type: 2WDiff\n", |
| 83 | + " wheel_axis: 0.094\n", |
| 84 | + " max_speed: 0.166\n", |
| 85 | + " behavior:\n", |
| 86 | + " type: {behaviour}\n", |
| 87 | + " optimal_speed: \n", |
| 88 | + " sampler: normal\n", |
| 89 | + " mean: 0.2\n", |
| 90 | + " std_dev: 0.05\n", |
| 91 | + " horizon: 5.0\n", |
| 92 | + " safety_margin: \n", |
| 93 | + " sampler: normal\n", |
| 94 | + " mean: 0.2\n", |
| 95 | + " std_dev: 0.05\n", |
| 96 | + " state_estimation:\n", |
| 97 | + " type: Bounded\n", |
| 98 | + " range: 5.0\n", |
| 99 | + " \"\"\"\n", |
| 100 | + " experiment = sim.load_experiment(yaml)\n", |
| 101 | + " experiment.run(keep=False, data_path=path)\n", |
| 102 | + " del experiment" |
| 103 | + ] |
| 104 | + }, |
| 105 | + { |
| 106 | + "cell_type": "code", |
| 107 | + "execution_count": null, |
| 108 | + "id": "d84b1524-0407-4828-b2ab-8b8485e41a97", |
| 109 | + "metadata": {}, |
| 110 | + "outputs": [], |
| 111 | + "source": [ |
| 112 | + "runs = {}\n", |
| 113 | + "# Reload simulations\n", |
| 114 | + "for behaviour in behaviour_list:\n", |
| 115 | + " path = os.path.join(experiment_dir, f\"visualisation_{behaviour}.h5\")\n", |
| 116 | + " recorded_experiment = sim.RecordedExperiment(path)\n", |
| 117 | + " runs[behaviour] = recorded_experiment.runs" |
| 118 | + ] |
| 119 | + }, |
| 120 | + { |
| 121 | + "cell_type": "markdown", |
| 122 | + "id": "ec5913e6-73bc-4a7e-b5c0-1a0fe3f11ee4", |
| 123 | + "metadata": {}, |
| 124 | + "source": [ |
| 125 | + "Now, we illustrate movements for each behaviour in a single image." |
| 126 | + ] |
| 127 | + }, |
| 128 | + { |
| 129 | + "cell_type": "code", |
| 130 | + "execution_count": null, |
| 131 | + "id": "73b1f80f-61aa-4a96-b574-c4d361661a5a", |
| 132 | + "metadata": {}, |
| 133 | + "outputs": [], |
| 134 | + "source": [ |
| 135 | + "fig, ax = plt.subplots(nrows=len(behaviour_list), figsize=(10, 1.5*len(behaviour_list)))\n", |
| 136 | + "timestep_list = list(range(0,100,10))\n", |
| 137 | + "for i, behaviour in enumerate(behaviour_list):\n", |
| 138 | + " run = runs[behaviour][0]\n", |
| 139 | + " perdiver.plot_timesteps_corridor(run, timestep_list, length, width, ax[i])\n", |
| 140 | + " ax[i].set_title(behaviour, fontsize=20)\n", |
| 141 | + "plt.tight_layout()\n", |
| 142 | + "plt.savefig(os.path.join(plots_dir, \"behaviours_simulations.png\"))" |
| 143 | + ] |
| 144 | + }, |
| 145 | + { |
| 146 | + "cell_type": "code", |
| 147 | + "execution_count": null, |
| 148 | + "id": "6ed906db-afe1-4713-adb4-cff59c65d427", |
| 149 | + "metadata": {}, |
| 150 | + "outputs": [], |
| 151 | + "source": [] |
| 152 | + } |
| 153 | + ], |
| 154 | + "metadata": { |
| 155 | + "kernelspec": { |
| 156 | + "display_name": "Python 3 (ipykernel)", |
| 157 | + "language": "python", |
| 158 | + "name": "python3" |
| 159 | + }, |
| 160 | + "language_info": { |
| 161 | + "codemirror_mode": { |
| 162 | + "name": "ipython", |
| 163 | + "version": 3 |
| 164 | + }, |
| 165 | + "file_extension": ".py", |
| 166 | + "mimetype": "text/x-python", |
| 167 | + "name": "python", |
| 168 | + "nbconvert_exporter": "python", |
| 169 | + "pygments_lexer": "ipython3", |
| 170 | + "version": "3.10.12" |
| 171 | + } |
| 172 | + }, |
| 173 | + "nbformat": 4, |
| 174 | + "nbformat_minor": 5 |
| 175 | +} |
0 commit comments