Skip to content

Commit 20e5030

Browse files
authored
Merge pull request #256 from thowell/patch
Patches
2 parents 189c25c + 0819b85 commit 20e5030

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1239
-2122
lines changed

CMakeLists.txt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ set(MUJOCO_MPC_MUJOCO_GIT_TAG
6060
CACHE STRING "Git revision for MuJoCo."
6161
)
6262

63+
set(MUJOCO_MPC_MENAGERIE_GIT_TAG
64+
aef3ee5c07ea51506e893a62fd832773ff0162c8
65+
CACHE STRING "Git revision for MuJoCo Menagerie."
66+
)
67+
68+
set(MUJOCO_MPC_DM_CONTROL_GIT_TAG
69+
774f46182140106e22725914aad3c6299ed91edd
70+
CACHE STRING "Git revision for dm_control."
71+
)
72+
6373
findorfetch(
6474
USE_SYSTEM_PACKAGE
6575
OFF
@@ -160,14 +170,25 @@ unset(BUILD_SHARED_LIBS_OLD)
160170
FetchContent_Declare(
161171
menagerie
162172
GIT_REPOSITORY https://github.com/google-deepmind/mujoco_menagerie.git
163-
GIT_TAG main
173+
GIT_TAG ${MUJOCO_MPC_MENAGERIE_GIT_TAG}
164174
)
165175

166176
FetchContent_GetProperties(menagerie)
167177
if(NOT menagerie_POPULATED)
168178
FetchContent_Populate(menagerie)
169179
endif()
170180

181+
FetchContent_Declare(
182+
dm_control
183+
GIT_REPOSITORY https://github.com/google-deepmind/dm_control.git
184+
GIT_TAG ${MUJOCO_MPC_DM_CONTROL_GIT_TAG}
185+
)
186+
187+
FetchContent_GetProperties(dm_control)
188+
if(NOT dm_control_POPULATED)
189+
FetchContent_Populate(dm_control)
190+
endif()
191+
171192
if(NOT TARGET lodepng)
172193
FetchContent_Declare(
173194
lodepng

docs/CONTRIBUTING.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ This code adheres to the [Google style](https://google.github.io/styleguide/).
3232

3333
## New Tasks
3434

35-
When submitting a PR for a new task using models from [MuJoCo Menagerie](https://github.com/google-deepmind/mujoco_menagerie), do not include assets directly. Instead, modify the task [CMakeLists](mjpc/tasks/CMakeLists.txt) to copy these assets to the build binary.
35+
When submitting a PR for a new task that depends on third-party models, including from [MuJoCo Menagerie](https://github.com/google-deepmind/mujoco_menagerie) and [dm_control](https://github.com/google-deepmind/dm_control), do not include the xml model or assets in the task directly. Instead, modify the task [CMakeLists](mjpc/tasks/CMakeLists.txt) to copy the xml model and/or assets to the build binary.
36+
37+
If the xml model needs to be modified, create a patch that is applied in the [CMakeLists](mjpc/tasks/CMakeLists.txt). A [patch](https://github.com/google-deepmind/mujoco_mpc/blob/main/mjpc/tasks/op3/op3.xml.patch) can be generated using the following command:
38+
```
39+
diff -u {original}.xml {modified}.xml > {modified}.xml.patch
40+
```
41+
The first three lines of the generated patch file will need to be be adapted for your use case. Please see an [example](https://github.com/google-deepmind/mujoco_mpc/blob/main/mjpc/tasks/op3/op3.xml.patch) for a template.
3642

3743
## Unit Tests
3844

mjpc/tasks/CMakeLists.txt

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,55 @@
1616
# built binary.
1717

1818
add_custom_target(
19-
copy_menagerie_resources ALL
19+
copy_model_resources ALL
20+
## dm_control models
21+
# acrobot
22+
COMMAND ${CMAKE_COMMAND} -E copy
23+
${dm_control_SOURCE_DIR}/dm_control/suite/acrobot.xml
24+
${CMAKE_CURRENT_BINARY_DIR}/acrobot/acrobot.xml
25+
COMMAND patch -o ${CMAKE_CURRENT_BINARY_DIR}/acrobot/acrobot_modified.xml
26+
${CMAKE_CURRENT_BINARY_DIR}/acrobot/acrobot.xml
27+
<${CMAKE_CURRENT_SOURCE_DIR}/acrobot/acrobot.xml.patch
28+
# cartpole
29+
COMMAND ${CMAKE_COMMAND} -E copy
30+
${dm_control_SOURCE_DIR}/dm_control/suite/cartpole.xml
31+
${CMAKE_CURRENT_BINARY_DIR}/cartpole/cartpole.xml
32+
COMMAND patch -o ${CMAKE_CURRENT_BINARY_DIR}/cartpole/cartpole_modified.xml
33+
${CMAKE_CURRENT_BINARY_DIR}/cartpole/cartpole.xml
34+
<${CMAKE_CURRENT_SOURCE_DIR}/cartpole/cartpole.xml.patch
35+
# humanoid
36+
COMMAND ${CMAKE_COMMAND} -E copy
37+
${dm_control_SOURCE_DIR}/dm_control/suite/humanoid.xml
38+
${CMAKE_CURRENT_BINARY_DIR}/humanoid/humanoid.xml
39+
COMMAND patch -o ${CMAKE_CURRENT_BINARY_DIR}/humanoid/humanoid_modified.xml
40+
${CMAKE_CURRENT_BINARY_DIR}/humanoid/humanoid.xml
41+
<${CMAKE_CURRENT_SOURCE_DIR}/humanoid/humanoid.xml.patch
42+
# particle
43+
COMMAND ${CMAKE_COMMAND} -E copy
44+
${dm_control_SOURCE_DIR}/dm_control/suite/point_mass.xml
45+
${CMAKE_CURRENT_BINARY_DIR}/particle/particle.xml
46+
COMMAND patch -o ${CMAKE_CURRENT_BINARY_DIR}/particle/particle_modified.xml
47+
${CMAKE_CURRENT_BINARY_DIR}/particle/particle.xml
48+
<${CMAKE_CURRENT_SOURCE_DIR}/particle/particle.xml.patch
49+
# swimmer
50+
COMMAND ${CMAKE_COMMAND} -E copy
51+
${dm_control_SOURCE_DIR}/dm_control/suite/swimmer.xml
52+
${CMAKE_CURRENT_BINARY_DIR}/swimmer/swimmer.xml
53+
COMMAND patch -o ${CMAKE_CURRENT_BINARY_DIR}/swimmer/swimmer_modified.xml
54+
${CMAKE_CURRENT_BINARY_DIR}/swimmer/swimmer.xml
55+
<${CMAKE_CURRENT_SOURCE_DIR}/swimmer/swimmer.xml.patch
56+
# walker
57+
COMMAND ${CMAKE_COMMAND} -E copy
58+
${dm_control_SOURCE_DIR}/dm_control/suite/walker.xml
59+
${CMAKE_CURRENT_BINARY_DIR}/walker/walker.xml
60+
COMMAND patch -o ${CMAKE_CURRENT_BINARY_DIR}/walker/walker_modified.xml
61+
${CMAKE_CURRENT_BINARY_DIR}/walker/walker.xml
62+
<${CMAKE_CURRENT_SOURCE_DIR}/walker/walker.xml.patch
63+
64+
## Menagerie models
65+
COMMAND ${CMAKE_COMMAND} -E copy
66+
${menagerie_SOURCE_DIR}/shadow_hand/right_hand.xml
67+
${CMAKE_CURRENT_BINARY_DIR}/hand/right_hand.xml
2068
COMMAND ${CMAKE_COMMAND} -E copy
2169
${menagerie_SOURCE_DIR}/wonik_allegro/right_hand.xml
2270
${CMAKE_CURRENT_BINARY_DIR}/allegro/right_hand.xml
@@ -29,21 +77,39 @@ add_custom_target(
2977
COMMAND ${CMAKE_COMMAND} -E copy_directory
3078
${menagerie_SOURCE_DIR}/shadow_hand/assets
3179
${CMAKE_CURRENT_BINARY_DIR}/hand/assets
80+
COMMAND ${CMAKE_COMMAND} -E copy
81+
${menagerie_SOURCE_DIR}/franka_emika_panda/panda.xml
82+
${CMAKE_CURRENT_BINARY_DIR}/panda/panda.xml
3283
COMMAND ${CMAKE_COMMAND} -E copy_directory
3384
${menagerie_SOURCE_DIR}/franka_emika_panda/assets
3485
${CMAKE_CURRENT_BINARY_DIR}/panda/assets
86+
COMMAND patch -o ${CMAKE_CURRENT_BINARY_DIR}/panda/panda_modified.xml
87+
${CMAKE_CURRENT_BINARY_DIR}/panda/panda.xml
88+
<${CMAKE_CURRENT_SOURCE_DIR}/panda/panda.xml.patch
89+
COMMAND ${CMAKE_COMMAND} -E copy
90+
${menagerie_SOURCE_DIR}/unitree_a1/a1.xml
91+
${CMAKE_CURRENT_BINARY_DIR}/quadruped/a1.xml
3592
COMMAND ${CMAKE_COMMAND} -E copy_directory
3693
${menagerie_SOURCE_DIR}/unitree_a1/assets
3794
${CMAKE_CURRENT_BINARY_DIR}/quadruped/assets
95+
COMMAND patch -o ${CMAKE_CURRENT_BINARY_DIR}/quadruped/a1_modified.xml
96+
${CMAKE_CURRENT_BINARY_DIR}/quadruped/a1.xml
97+
<${CMAKE_CURRENT_SOURCE_DIR}/quadruped/a1.xml.patch
3898
COMMAND ${CMAKE_COMMAND} -E copy_directory
3999
${menagerie_SOURCE_DIR}/franka_emika_panda
40100
${CMAKE_CURRENT_BINARY_DIR}/manipulation
41101
COMMAND ${CMAKE_COMMAND} -E copy_directory
42102
${menagerie_SOURCE_DIR}/robotiq_2f85
43103
${CMAKE_CURRENT_BINARY_DIR}/manipulation
104+
COMMAND ${CMAKE_COMMAND} -E copy
105+
${menagerie_SOURCE_DIR}/skydio_x2/x2.xml
106+
${CMAKE_CURRENT_BINARY_DIR}/quadrotor/quadrotor.xml
44107
COMMAND ${CMAKE_COMMAND} -E copy_directory
45108
${menagerie_SOURCE_DIR}/skydio_x2/assets
46109
${CMAKE_CURRENT_BINARY_DIR}/quadrotor/assets
110+
COMMAND patch -o ${CMAKE_CURRENT_BINARY_DIR}/quadrotor/quadrotor_modified.xml
111+
${CMAKE_CURRENT_BINARY_DIR}/quadrotor/quadrotor.xml
112+
<${CMAKE_CURRENT_SOURCE_DIR}/quadrotor/quadrotor.xml.patch
47113
## Cube solve task
48114
# copy cube model from MuJoCo
49115
COMMAND ${CMAKE_COMMAND} -E copy
@@ -97,14 +163,14 @@ add_custom_target(
97163
COMMAND ${Python_EXECUTABLE}
98164
${CMAKE_CURRENT_BINARY_DIR}/manipulation/merge_panda_robotiq.py
99165
${CMAKE_CURRENT_BINARY_DIR}/manipulation/panda_robotiq.xml
100-
COMMENT "Copying menagerie assets into binary directory")
166+
COMMENT "Copying Menagerie and dm_control assets into binary directory")
101167

102168
add_custom_target(copy_resources ALL
103169
COMMAND ${CMAKE_COMMAND} -E copy_directory
104170
${CMAKE_CURRENT_SOURCE_DIR}
105171
${CMAKE_CURRENT_BINARY_DIR}
106172
COMMENT "Copying tasks into binary directory")
107173

108-
add_dependencies(copy_menagerie_resources copy_resources)
174+
add_dependencies(copy_model_resources copy_resources)
109175

110-
add_dependencies(libmjpc copy_menagerie_resources)
176+
add_dependencies(libmjpc copy_model_resources)

mjpc/tasks/acrobot/acrobot.xml

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
diff --git a/acrobot_modified.xml b/acrobot_modified.xml
2+
--- a/acrobot_modified.xml
3+
+++ b/acrobot_modified.xml
4+
@@ -6,22 +6,18 @@
5+
IEEE control systems 15, no. 1 (1995): 49-55.
6+
-->
7+
<mujoco model="acrobot">
8+
- <include file="./common/visual.xml"/>
9+
- <include file="./common/skybox.xml"/>
10+
- <include file="./common/materials.xml"/>
11+
-
12+
<default>
13+
<joint damping=".05"/>
14+
<geom type="capsule" mass="1"/>
15+
</default>
16+
17+
- <option timestep="0.01" integrator="RK4">
18+
+ <option timestep="0.01">
19+
<flag constraint="disable" energy="enable"/>
20+
</option>
21+
22+
<worldbody>
23+
<light name="light" pos="0 0 6"/>
24+
- <geom name="floor" size="3 3 .2" type="plane" material="grid"/>
25+
+ <geom name="floor" size="3 3 .2" type="plane" material="blue_grid"/>
26+
<site name="target" type="sphere" pos="0 0 4" size="0.2" material="target" group="3"/>
27+
<camera name="fixed" pos="0 -6 2" zaxis="0 -1 0"/>
28+
<camera name="lookat" mode="targetbodycom" target="upper_arm" pos="0 -2 3"/>

mjpc/tasks/acrobot/task.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<mujoco model="Acrobot Swing-Up">
22
<include file="../common.xml"/>
3-
<include file="acrobot.xml" />
3+
<!-- modified from: https://github.com/google-deepmind/dm_control/blob/main/dm_control/suite/acrobot.xml-->
4+
<include file="acrobot_modified.xml" />
45

56
<size memory="4K"/>
67

mjpc/tasks/cartpole/cartpole.xml

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
diff --git a/cartpole_modified.xml b/cartpole_modified.xml
2+
--- a/cartpole_modified.xml
3+
+++ b/cartpole_modified.xml
4+
@@ -1,10 +1,6 @@
5+
-<mujoco model="cart-pole">
6+
- <include file="./common/skybox.xml"/>
7+
- <include file="./common/visual.xml"/>
8+
- <include file="./common/materials.xml"/>
9+
-
10+
- <option timestep="0.01" integrator="RK4">
11+
- <flag contact="disable" energy="enable"/>
12+
+<mujoco model="Cartpole">
13+
+ <option timestep="0.001">
14+
+ <flag contact="disable"/>
15+
</option>
16+
17+
<default>
18+
@@ -18,15 +14,16 @@
19+
<light name="light" pos="0 0 6"/>
20+
<camera name="fixed" pos="0 -4 1" zaxis="0 -1 0"/>
21+
<camera name="lookatcart" mode="targetbody" target="cart" pos="0 -2 2"/>
22+
- <geom name="floor" pos="0 0 -.05" size="4 4 .2" type="plane" material="grid"/>
23+
+ <geom name="floor" pos="0 0 -.05" size="4 4 .2" type="plane" material="blue_grid"/>
24+
<geom name="rail1" type="capsule" pos="0 .07 1" zaxis="1 0 0" size="0.02 2" material="decoration" />
25+
<geom name="rail2" type="capsule" pos="0 -.07 1" zaxis="1 0 0" size="0.02 2" material="decoration" />
26+
<body name="cart" pos="0 0 1">
27+
- <joint name="slider" type="slide" limited="true" axis="1 0 0" range="-1.8 1.8" solreflimit=".08 1" damping="5e-4"/>
28+
+ <joint name="slider" type="slide" limited="true" axis="1 0 0" range="-1.8 1.8" solreflimit=".08 1" damping="1.0e-4"/>
29+
<geom name="cart" type="box" size="0.2 0.15 0.1" material="self" mass="1"/>
30+
<body name="pole_1" childclass="pole">
31+
- <joint name="hinge_1"/>
32+
+ <joint name="hinge_1" damping="1.0e-4"/>
33+
<geom name="pole_1"/>
34+
+ <site name="tip" pos="0 0 1"/>
35+
</body>
36+
</body>
37+
</worldbody>

mjpc/tasks/cartpole/task.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<mujoco model="Cart-Pole Swing-Up">
22
<include file="../common.xml"/>
3-
<include file="cartpole.xml" />
3+
<!-- modified from: https://github.com/google-deepmind/dm_control/blob/main/dm_control/suite/cartpole.xml -->
4+
<include file="cartpole_modified.xml" />
45

56
<size memory="4K"/>
67

0 commit comments

Comments
 (0)