From b07c6f6de4e65737924299680650187bd9510623 Mon Sep 17 00:00:00 2001 From: Giacomo Spigler <spiglerg@gmail.com> Date: Wed, 19 Jun 2019 19:58:25 +0200 Subject: [PATCH] Jeremy's new notebook with hardwired command strings --- .../simple_example_3_manual_control.ipynb | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/notebooks/simple_example_3_manual_control.ipynb b/notebooks/simple_example_3_manual_control.ipynb index 6527e12..369590c 100644 --- a/notebooks/simple_example_3_manual_control.ipynb +++ b/notebooks/simple_example_3_manual_control.ipynb @@ -5,9 +5,12 @@ "metadata": {}, "source": [ "### Simple Example 3 - Manual Control\n", - "This opens a separate window, and a text box in the Jupyter notebook.\n", "\n", - "eg Enter `\"0 2 s<enter>\"` to tell agent 0 to step forward, and step the environment.\n", + "By default this runs a few \"move forward\" actions for two agents, in a separate window.\n", + "\n", + "If you uncomment the \"input\" line below, it opens a text box in the Jupyter notebook, allowing basic manual control.\n", + "\n", + "eg Enter `\"0 2 s<enter>\"` to tell agent 0 to move forward, and step the environment.\n", "\n", "You should be able to see the red agent step forward, and get a reward from the env, looking like this:\n", "\n", @@ -36,6 +39,7 @@ "source": [ "import random\n", "import numpy as np\n", + "import time\n", "from flatland.envs.generators import random_rail_generator\n", "from flatland.envs.observations import TreeObsForRailEnv\n", "from flatland.envs.rail_env import RailEnv\n", @@ -66,12 +70,26 @@ "# env_renderer = RenderTool(env, gl=\"PILSVG\")\n", "\n", "env_renderer.renderEnv(show=True, frames=True)\n", - "env_renderer.renderEnv(show=True, frames=True)\n", "\n", "print(\"Manual control: s=perform step, q=quit, [agent id] [1-2-3 action] \\\n", - " (turnleft+move, move to front, turnright+move)\")\n", - "for step in range(100):\n", - " cmd = input(\">> \")\n", + " (turnleft+move, move to front, turnright+move)\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "for step in range(10):\n", + "\n", + " # This is an example command, setting agent 0's action to 2 (move forward), and agent 1's action to 2, \n", + " # then stepping the environment.\n", + " cmd = \"0 2 1 2 s\"\n", + " \n", + " # uncomment this input statement if you want to try interactive manual commands\n", + " # cmd = input(\">> \")\n", + " \n", " cmds = cmd.split(\" \")\n", "\n", " action_dict = {}\n", @@ -93,7 +111,9 @@ " i = i + 1\n", " i += 1\n", "\n", - " env_renderer.renderEnv(show=True, frames=True)" + " env_renderer.renderEnv(show=True, frames=True)\n", + " \n", + " time.sleep(0.3)" ] } ], -- GitLab