diff --git a/Go2Py/control/cat.py b/Go2Py/control/cat.py index 74c7bad..8e16b07 100755 --- a/Go2Py/control/cat.py +++ b/Go2Py/control/cat.py @@ -294,6 +294,7 @@ class CaTAgent: "contact_state": self.contact_state[np.newaxis, :], "body_linear_vel_cmd": self.commands[np.newaxis, 0:2], "body_angular_vel_cmd": self.commands[np.newaxis, 2:], + "torques": self.torques } self.timestep += 1 diff --git a/examples/06-CaT-RL-controller.ipynb b/examples/06-CaT-RL-controller.ipynb index 5ab6cb7..7cb5218 100644 --- a/examples/06-CaT-RL-controller.ipynb +++ b/examples/06-CaT-RL-controller.ipynb @@ -25,7 +25,23 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "ImportError", + "evalue": "this platform is not supported: ('failed to acquire X connection: Can\\'t connect to display \":1\": b\\'Authorization required, but no authorization protocol specified\\\\n\\'', DisplayConnectionError(':1', b'Authorization required, but no authorization protocol specified\\n'))\n\nTry one of the following resolutions:\n\n * Please make sure that you have an X server running, and that the DISPLAY environment variable is set correctly", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[1], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mGo2Py\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mrobot\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mfsm\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m FSM\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mGo2Py\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mrobot\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mremote\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m KeyboardRemote\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mGo2Py\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mrobot\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01msafety\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m SafetyHypervisor\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mGo2Py\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01msim\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmujoco\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Go2Sim\n", + "File \u001b[0;32m/home/Go2py/Go2Py/robot/remote.py:2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mthreading\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpynput\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m keyboard\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mclass\u001b[39;00m \u001b[38;5;21;01mBaseRemote\u001b[39;00m:\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__init__\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n", + "File \u001b[0;32m/usr/local/lib/python3.10/dist-packages/pynput/__init__.py:40\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mlogging\u001b[39;00m\n\u001b[1;32m 35\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m logging\u001b[38;5;241m.\u001b[39mgetLogger(\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;124m.\u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;241m.\u001b[39mformat(\n\u001b[1;32m 36\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;241m.\u001b[39mjoin(\u001b[38;5;28mcls\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__module__\u001b[39m\u001b[38;5;241m.\u001b[39msplit(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;241m2\u001b[39m)[:\u001b[38;5;241m2\u001b[39m]),\n\u001b[1;32m 37\u001b[0m \u001b[38;5;28mcls\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m))\n\u001b[0;32m---> 40\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m keyboard\n\u001b[1;32m 41\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m mouse\n", + "File \u001b[0;32m/usr/local/lib/python3.10/dist-packages/pynput/keyboard/__init__.py:31\u001b[0m\n\u001b[1;32m 26\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mitertools\u001b[39;00m\n\u001b[1;32m 28\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpynput\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m_util\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m backend, Events\n\u001b[0;32m---> 31\u001b[0m backend \u001b[38;5;241m=\u001b[39m \u001b[43mbackend\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;18;43m__name__\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 32\u001b[0m KeyCode \u001b[38;5;241m=\u001b[39m backend\u001b[38;5;241m.\u001b[39mKeyCode\n\u001b[1;32m 33\u001b[0m Key \u001b[38;5;241m=\u001b[39m backend\u001b[38;5;241m.\u001b[39mKey\n", + "File \u001b[0;32m/usr/local/lib/python3.10/dist-packages/pynput/_util/__init__.py:77\u001b[0m, in \u001b[0;36mbackend\u001b[0;34m(package)\u001b[0m\n\u001b[1;32m 74\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m module \u001b[38;5;129;01min\u001b[39;00m RESOLUTIONS:\n\u001b[1;32m 75\u001b[0m resolutions\u001b[38;5;241m.\u001b[39mappend(RESOLUTIONS[module])\n\u001b[0;32m---> 77\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mImportError\u001b[39;00m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mthis platform is not supported: \u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;241m.\u001b[39mformat(\n\u001b[1;32m 78\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m; \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;241m.\u001b[39mjoin(\u001b[38;5;28mstr\u001b[39m(e) \u001b[38;5;28;01mfor\u001b[39;00m e \u001b[38;5;129;01min\u001b[39;00m errors)) \u001b[38;5;241m+\u001b[39m (\u001b[38;5;124m'\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 79\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mTry one of the following resolutions:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 80\u001b[0m \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;241m.\u001b[39mjoin(\n\u001b[1;32m 81\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m * \u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;241m.\u001b[39mformat(s)\n\u001b[1;32m 82\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m s \u001b[38;5;129;01min\u001b[39;00m resolutions))\n\u001b[1;32m 83\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m resolutions \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m'\u001b[39m)\n", + "\u001b[0;31mImportError\u001b[0m: this platform is not supported: ('failed to acquire X connection: Can\\'t connect to display \":1\": b\\'Authorization required, but no authorization protocol specified\\\\n\\'', DisplayConnectionError(':1', b'Authorization required, but no authorization protocol specified\\n'))\n\nTry one of the following resolutions:\n\n * Please make sure that you have an X server running, and that the DISPLAY environment variable is set correctly" + ] + } + ], "source": [ "from Go2Py.robot.fsm import FSM\n", "from Go2Py.robot.remote import KeyboardRemote\n", @@ -39,7 +55,19 @@ "cell_type": "code", "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'Go2Sim' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[2], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m robot \u001b[38;5;241m=\u001b[39m \u001b[43mGo2Sim\u001b[49m()\n", + "\u001b[0;31mNameError\u001b[0m: name 'Go2Sim' is not defined" + ] + } + ], "source": [ "robot = Go2Sim()" ] @@ -69,6 +97,7 @@ " self.command_profile = CommandInterface()\n", " self.agent = CaTAgent(self.command_profile, self.robot)\n", " self.init()\n", + " self.hist_data = {}\n", "\n", " def init(self):\n", " self.obs = self.agent.reset()\n", @@ -79,7 +108,12 @@ "\n", " def update(self, robot, remote):\n", " action = self.policy(self.obs, self.policy_info)\n", - " self.obs, self.ret, self.done, self.info = self.agent.step(action)" + " self.obs, self.ret, self.done, self.info = self.agent.step(action)\n", + " for key, value in self.info.items():\n", + " if key in self.hist_data:\n", + " self.hist_data[key].append(value)\n", + " else:\n", + " self.hist_data[key] = [value]" ] }, {