-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a franka kitchen example (#426)
- Loading branch information
1 parent
d0c90b5
commit 70e0608
Showing
3 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "05124c35", | ||
"metadata": { | ||
"colab_type": "text", | ||
"id": "EgiF12Hf1Dhs" | ||
}, | ||
"source": [ | ||
"This notebook provides examples to go along with the [textbook](http://manipulation.csail.mit.edu/robot.html). I recommend having both windows open, side-by-side!" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"id": "99268d0c", | ||
"metadata": { | ||
"colab": {}, | ||
"colab_type": "code", | ||
"id": "eeMrMI0-1Dhu", | ||
"lines_to_end_of_cell_marker": 2 | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"from pydrake.all import PackageMap, Parser, RobotDiagramBuilder, Simulator, StartMeshcat\n", | ||
"\n", | ||
"from manipulation import running_as_notebook\n", | ||
"from manipulation.make_drake_compatible_model import MakeDrakeCompatibleModel\n", | ||
"from manipulation.utils import ApplyDefaultVisualization" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "7dec0a5e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Start the visualizer.\n", | ||
"meshcat = StartMeshcat()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "11c62164", | ||
"metadata": {}, | ||
"source": [ | ||
"## Gymnasium Robotics\n", | ||
"\n", | ||
"Includes the following environments:\n", | ||
"- Franka kitchen\n", | ||
"- ..." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "cfaf4640", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# TODO(russt): Use ModelVisualizer pending resolution of Drake#22444.\n", | ||
"if running_as_notebook: # I don't want to download the repo in CI.\n", | ||
" meshcat.Delete()\n", | ||
" builder = RobotDiagramBuilder()\n", | ||
" plant = builder.plant()\n", | ||
" parser = Parser(plant)\n", | ||
" package_map = parser.package_map()\n", | ||
" package_map.AddRemote(\n", | ||
" package_name=\"gymnasium_robotics\",\n", | ||
" params=PackageMap.RemoteParams(\n", | ||
" urls=[\n", | ||
" f\"https://github.com/Farama-Foundation/Gymnasium-Robotics/archive/refs/tags/v1.3.1.tar.gz\"\n", | ||
" ],\n", | ||
" sha256=(\"d274b3ee1d34337aa35d4686447fda6a6d20dfcb4d375eab91b4e49b1108afde\"),\n", | ||
" strip_prefix=\"Gymnasium-Robotics-1.3.1/gymnasium_robotics/envs/assets/\",\n", | ||
" ),\n", | ||
" )\n", | ||
" original_file = package_map.ResolveUrl(\n", | ||
" \"package://gymnasium_robotics/kitchen_franka/kitchen_assets/kitchen_env_model.xml\"\n", | ||
" )\n", | ||
" drake_compatible_file = original_file.replace(\".xml\", \".drake.xml\")\n", | ||
" MakeDrakeCompatibleModel(original_file, drake_compatible_file)\n", | ||
" model_instances = parser.AddModels(drake_compatible_file)\n", | ||
" plant.Finalize()\n", | ||
" ApplyDefaultVisualization(builder.builder(), meshcat=meshcat)\n", | ||
" diagram = builder.Build()\n", | ||
" simulator = Simulator(diagram)\n", | ||
"\n", | ||
" # Workaround for drake#22444: set the desired state to zero.\n", | ||
" for model_instance in model_instances:\n", | ||
" desired_state_port = plant.get_desired_state_input_port(model_instance)\n", | ||
" if desired_state_port.size() > 0:\n", | ||
" desired_state_port.FixValue(\n", | ||
" plant.GetMyContextFromRoot(simulator.get_context()),\n", | ||
" np.zeros(desired_state_port.size()),\n", | ||
" )\n", | ||
"\n", | ||
" diagram.ForcedPublish(simulator.get_context())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "4565ef03", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters