├── docs
├── assets
│ ├── gui.png
│ └── banner.png
└── GUI.md
├── mjpc
├── tasks
│ ├── quadruped
│ │ └── assets
│ │ │ ├── martian.png
│ │ │ ├── fractal_noise.png
│ │ │ └── fractal.xml
│ ├── common_assets
│ │ ├── connector
│ │ │ ├── mcX_f.stl
│ │ │ ├── mcX_m.stl
│ │ │ ├── mcX_f_collision_mcX_f_MESH.stl
│ │ │ └── mcX_m_collision_mcX_m_MESH.stl
│ │ ├── reorientation_cube_textures
│ │ │ ├── fileup.png
│ │ │ ├── grayup.png
│ │ │ ├── fileback.png
│ │ │ ├── filedown.png
│ │ │ ├── fileleft.png
│ │ │ ├── grayback.png
│ │ │ ├── graydown.png
│ │ │ ├── grayleft.png
│ │ │ ├── filefront.png
│ │ │ ├── fileright.png
│ │ │ ├── grayfront.png
│ │ │ └── grayright.png
│ │ ├── cube.xml.patch
│ │ ├── reorientation_cross.xml
│ │ └── reorientation_cube.xml
│ ├── humanoid
│ │ ├── tracking
│ │ │ └── keyframes
│ │ │ │ └── README.md
│ │ ├── interact
│ │ │ └── scenes
│ │ │ │ ├── stool.xml
│ │ │ │ ├── table.xml
│ │ │ │ ├── bed.xml
│ │ │ │ ├── bench.xml
│ │ │ │ ├── armchair.xml
│ │ │ │ └── dining_chair.xml
│ │ ├── stand
│ │ │ ├── task.xml
│ │ │ └── stand.h
│ │ └── walk
│ │ │ └── walk.h
│ ├── tasks.h
│ ├── acrobot
│ │ ├── acrobot.xml.patch
│ │ ├── task.xml
│ │ ├── acrobot.cc
│ │ └── acrobot.h
│ ├── quadrotor
│ │ ├── quadrotor.xml.patch
│ │ └── quadrotor.h
│ ├── particle
│ │ ├── task.xml
│ │ ├── task_timevarying.xml
│ │ └── particle.xml.patch
│ ├── common.xml
│ ├── rubik
│ │ ├── transition_model.xml.patch
│ │ ├── cube_3x3x3.xml.patch
│ │ └── solve.h
│ ├── fingers
│ │ ├── fingers.h
│ │ └── fingers.cc
│ ├── panda
│ │ └── panda.h
│ ├── allegro
│ │ ├── right_hand.xml.patch
│ │ └── allegro.h
│ ├── cartpole
│ │ ├── cartpole.xml.patch
│ │ ├── cartpole.cc
│ │ ├── cartpole.h
│ │ └── task.xml
│ ├── bimanual
│ │ ├── insert
│ │ │ └── insert.h
│ │ ├── handover
│ │ │ └── handover.h
│ │ └── reorient
│ │ │ └── reorient.h
│ ├── walker
│ │ ├── walker.h
│ │ ├── walker.xml.patch
│ │ └── task.xml
│ ├── manipulation
│ │ └── manipulation.h
│ ├── swimmer
│ │ ├── swimmer.h
│ │ ├── task.xml
│ │ └── swimmer.cc
│ ├── shadow_reorient
│ │ └── hand.h
│ └── op3
│ │ └── stand.h
├── test
│ ├── spline
│ │ └── CMakeLists.txt
│ ├── state
│ │ ├── CMakeLists.txt
│ │ └── state_test.cc
│ ├── tasks
│ │ └── CMakeLists.txt
│ ├── utilities
│ │ └── CMakeLists.txt
│ ├── planners
│ │ └── robust
│ │ │ └── CMakeLists.txt
│ ├── sampling_planner
│ │ └── CMakeLists.txt
│ ├── ilqg_planner
│ │ └── CMakeLists.txt
│ ├── load.h
│ ├── estimator
│ │ └── CMakeLists.txt
│ ├── gradient_planner
│ │ ├── CMakeLists.txt
│ │ └── zero_test.cc
│ ├── agent
│ │ ├── CMakeLists.txt
│ │ ├── threadpool_test.cc
│ │ └── cost_derivatives_test.cc
│ ├── direct
│ │ └── CMakeLists.txt
│ ├── testdata
│ │ ├── box.xml
│ │ ├── common.xml
│ │ ├── particle_task.xml
│ │ ├── estimator
│ │ │ ├── particle
│ │ │ │ ├── particle.xml
│ │ │ │ ├── task1D.xml
│ │ │ │ ├── task_imu.xml
│ │ │ │ ├── task1D_damped.xml
│ │ │ │ └── task1D_framepos.xml
│ │ │ └── box
│ │ │ │ └── task0.xml
│ │ └── particle_residual.h
│ ├── load.cc
│ ├── lqr.h
│ ├── simulation.h
│ └── simulation.cc
├── testspeed.h
├── estimators
│ ├── include.h
│ └── include.cc
├── planners
│ ├── planner.cc
│ ├── gradient
│ │ ├── settings.h
│ │ ├── gradient.h
│ │ └── policy.h
│ ├── include.h
│ ├── policy.h
│ ├── ilqg
│ │ ├── settings.h
│ │ ├── boxqp.h
│ │ └── policy.h
│ ├── sampling
│ │ ├── policy.h
│ │ └── policy.cc
│ ├── include.cc
│ └── model_derivatives.h
├── direct
│ └── model_parameters.cc
├── app.h
├── norm.h
├── interface.h
├── macos_gui.mm
├── testspeed_app.cc
├── grpc
│ ├── filter_server.cc
│ ├── direct_server.cc
│ ├── agent_server.cc
│ ├── ui_agent_server.cc
│ └── filter.proto
├── threadpool.h
├── main.cc
└── threadpool.cc
├── CITATION.bib
├── .gitignore
├── python
└── mujoco_mpc
│ ├── __init__.py
│ ├── mjpc_parameters.py
│ ├── demos
│ └── agent
│ │ └── cartpole_gui.py
│ └── mjx
│ └── visualize.py
├── CITATION.cff
└── cmake
├── MujocoHarden.cmake
├── MujocoMacOS.cmake
├── CheckAvxSupport.cmake
└── MujocoLinkOptions.cmake
/docs/assets/gui.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/docs/assets/gui.png
--------------------------------------------------------------------------------
/docs/assets/banner.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/docs/assets/banner.png
--------------------------------------------------------------------------------
/mjpc/tasks/quadruped/assets/martian.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/mjpc/tasks/quadruped/assets/martian.png
--------------------------------------------------------------------------------
/mjpc/tasks/common_assets/connector/mcX_f.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/mjpc/tasks/common_assets/connector/mcX_f.stl
--------------------------------------------------------------------------------
/mjpc/tasks/common_assets/connector/mcX_m.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/mjpc/tasks/common_assets/connector/mcX_m.stl
--------------------------------------------------------------------------------
/mjpc/tasks/quadruped/assets/fractal_noise.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/mjpc/tasks/quadruped/assets/fractal_noise.png
--------------------------------------------------------------------------------
/mjpc/tasks/humanoid/tracking/keyframes/README.md:
--------------------------------------------------------------------------------
1 | * The data in this directory was obtained from mocap.cs.cmu.edu.
2 | * The database was created with funding from NSF EIA-0196217.
3 |
--------------------------------------------------------------------------------
/mjpc/tasks/common_assets/reorientation_cube_textures/fileup.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/mjpc/tasks/common_assets/reorientation_cube_textures/fileup.png
--------------------------------------------------------------------------------
/mjpc/tasks/common_assets/reorientation_cube_textures/grayup.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/mjpc/tasks/common_assets/reorientation_cube_textures/grayup.png
--------------------------------------------------------------------------------
/mjpc/tasks/common_assets/connector/mcX_f_collision_mcX_f_MESH.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/mjpc/tasks/common_assets/connector/mcX_f_collision_mcX_f_MESH.stl
--------------------------------------------------------------------------------
/mjpc/tasks/common_assets/connector/mcX_m_collision_mcX_m_MESH.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/mjpc/tasks/common_assets/connector/mcX_m_collision_mcX_m_MESH.stl
--------------------------------------------------------------------------------
/mjpc/tasks/common_assets/reorientation_cube_textures/fileback.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/mjpc/tasks/common_assets/reorientation_cube_textures/fileback.png
--------------------------------------------------------------------------------
/mjpc/tasks/common_assets/reorientation_cube_textures/filedown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/mjpc/tasks/common_assets/reorientation_cube_textures/filedown.png
--------------------------------------------------------------------------------
/mjpc/tasks/common_assets/reorientation_cube_textures/fileleft.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/mjpc/tasks/common_assets/reorientation_cube_textures/fileleft.png
--------------------------------------------------------------------------------
/mjpc/tasks/common_assets/reorientation_cube_textures/grayback.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/mjpc/tasks/common_assets/reorientation_cube_textures/grayback.png
--------------------------------------------------------------------------------
/mjpc/tasks/common_assets/reorientation_cube_textures/graydown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/mjpc/tasks/common_assets/reorientation_cube_textures/graydown.png
--------------------------------------------------------------------------------
/mjpc/tasks/common_assets/reorientation_cube_textures/grayleft.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/mjpc/tasks/common_assets/reorientation_cube_textures/grayleft.png
--------------------------------------------------------------------------------
/mjpc/tasks/common_assets/reorientation_cube_textures/filefront.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/mjpc/tasks/common_assets/reorientation_cube_textures/filefront.png
--------------------------------------------------------------------------------
/mjpc/tasks/common_assets/reorientation_cube_textures/fileright.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/mjpc/tasks/common_assets/reorientation_cube_textures/fileright.png
--------------------------------------------------------------------------------
/mjpc/tasks/common_assets/reorientation_cube_textures/grayfront.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/mjpc/tasks/common_assets/reorientation_cube_textures/grayfront.png
--------------------------------------------------------------------------------
/mjpc/tasks/common_assets/reorientation_cube_textures/grayright.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-deepmind/mujoco_mpc/HEAD/mjpc/tasks/common_assets/reorientation_cube_textures/grayright.png
--------------------------------------------------------------------------------
/CITATION.bib:
--------------------------------------------------------------------------------
1 | @article{howell2022,
2 | title={{Predictive Sampling: Real-time Behaviour Synthesis with MuJoCo}},
3 | author={Howell, Taylor and Gileadi, Nimrod and Tunyasuvunakool, Saran and Zakka, Kevin and Erez, Tom and Tassa, Yuval},
4 | archivePrefix={arXiv},
5 | eprint={2212.00541},
6 | primaryClass={cs.RO},
7 | url={https://arxiv.org/abs/2212.00541},
8 | doi={10.48550/arXiv.2212.00541},
9 | year={2022},
10 | month={dec}
11 | }
12 |
--------------------------------------------------------------------------------
/mjpc/tasks/quadruped/assets/fractal.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Don't commit binaries
2 | *.a
3 | *.asm
4 | *.dll
5 | *.dylib
6 | *.exe
7 | *.lib
8 | *.out
9 | *.o
10 | *.so
11 | *.so.*
12 | # Clang cache
13 | .cache/
14 | # Exclude editor config
15 | .vscode/
16 | .vs/
17 | # Exclude temporary folders
18 | *.egg-info/
19 | .eggs/
20 | build/
21 | build_cmake/
22 | # Exclude macOS folder attributes
23 | .DS_Store
24 | # Exclude macOS Info.framework.plist
25 | Info.framework.plist
26 | # Python byte-compiled / optimized / DLL files
27 | __pycache__/
28 | *.py[cod]
29 | *$py.class
30 | # MuJoCo
31 | MUJOCO_LOG.TXT
32 | MJDATA.TXT
33 | MJMODEL.TXT
34 | # Python
35 | python/dist/
36 |
--------------------------------------------------------------------------------
/mjpc/tasks/common_assets/cube.xml.patch:
--------------------------------------------------------------------------------
1 | mjpc/tasks/cube.xml.patch--- common_assets/reorientation_cube.xml 2024-02-11 18:42:07
2 | +++ hand/cube.xml 2024-02-12 14:52:27
3 | @@ -19,9 +19,9 @@
4 |
5 |
6 |
7 | -
8 | +
9 |
10 | -
11 | +
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/mjpc/test/spline/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright 2024 DeepMind Technologies Limited
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | test(spline_test)
16 | target_link_libraries(spline_test gmock)
17 |
--------------------------------------------------------------------------------
/mjpc/test/state/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright 2022 DeepMind Technologies Limited
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | test(state_test)
16 | target_link_libraries(state_test load gmock)
17 |
--------------------------------------------------------------------------------
/python/mujoco_mpc/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 DeepMind Technologies Limited
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
--------------------------------------------------------------------------------
/mjpc/test/tasks/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright 2022 DeepMind Technologies Limited
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | test(task_test)
16 | target_link_libraries(task_test load gmock libtestspeed)
17 |
--------------------------------------------------------------------------------
/mjpc/test/utilities/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright 2023 DeepMind Technologies Limited
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | test(utilities_test)
16 | target_link_libraries(utilities_test load gmock)
17 |
--------------------------------------------------------------------------------
/mjpc/test/planners/robust/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright 2023 DeepMind Technologies Limited
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | test(robust_planner_test)
16 | target_link_libraries(robust_planner_test load gmock)
17 |
--------------------------------------------------------------------------------
/mjpc/test/sampling_planner/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright 2022 DeepMind Technologies Limited
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | test(sampling_planner_test)
16 | target_link_libraries(sampling_planner_test load gmock)
17 |
--------------------------------------------------------------------------------
/python/mujoco_mpc/mjpc_parameters.py:
--------------------------------------------------------------------------------
1 | """Dataclass for MJPC task parameters and cost weights."""
2 |
3 | import dataclasses
4 | from typing import Optional, Union
5 |
6 | import numpy as np
7 |
8 |
9 | @dataclasses.dataclass(frozen=True)
10 | class Pose:
11 | pos: np.ndarray | None # 3D vector
12 | quat: np.ndarray | None # Unit quaternion
13 |
14 |
15 | @dataclasses.dataclass(frozen=True)
16 | class MjpcParameters:
17 | """Dataclass to store and set task settings."""
18 | mode: Optional[str] = None
19 | task_parameters: dict[str, Union[str, float]] = dataclasses.field(
20 | default_factory=dict
21 | )
22 | cost_weights: dict[str, float] = dataclasses.field(default_factory=dict)
23 | # A map from body name to pose
24 | mocap: dict[str, Pose] = dataclasses.field(default_factory=dict)
25 |
--------------------------------------------------------------------------------
/mjpc/test/ilqg_planner/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright 2022 DeepMind Technologies Limited
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | test(ilqg_test)
16 | target_link_libraries(ilqg_test load gmock)
17 |
18 | test(backward_pass_test)
19 | target_link_libraries(backward_pass_test lqr gmock)
20 |
--------------------------------------------------------------------------------
/mjpc/tasks/humanoid/interact/scenes/stool.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/mjpc/test/load.h:
--------------------------------------------------------------------------------
1 | // Copyright 2022 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MJPC_TEST_LOAD_H_
16 | #define MJPC_TEST_LOAD_H_
17 |
18 | #include
19 |
20 | #include
21 |
22 | namespace mjpc {
23 |
24 | // convenience function for paths
25 | mjModel* LoadTestModel(std::string_view path);
26 |
27 | } // namespace mjpc
28 |
29 | #endif // MJPC_TEST_LOAD_H_
30 |
--------------------------------------------------------------------------------
/mjpc/tasks/humanoid/interact/scenes/table.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/mjpc/tasks/common_assets/reorientation_cross.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/mjpc/tasks/tasks.h:
--------------------------------------------------------------------------------
1 | // Copyright 2022 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // Definitions for tasks built into mujoco_mpc.
16 |
17 | #ifndef MJPC_TASKS_TASKS_H_
18 | #define MJPC_TASKS_TASKS_H_
19 |
20 | #include
21 | #include
22 |
23 | #include "mjpc/task.h"
24 |
25 | namespace mjpc {
26 | std::vector> GetTasks();
27 | } // namespace mjpc
28 |
29 | #endif // MJPC_TASKS_TASKS_H_
30 |
--------------------------------------------------------------------------------
/mjpc/test/estimator/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright 2023 DeepMind Technologies Limited
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | test(batch_filter_test)
16 | target_link_libraries(batch_filter_test load simulation gmock)
17 |
18 | test(batch_prior_test)
19 | target_link_libraries(batch_prior_test load simulation gmock)
20 |
21 | test(kalman_test)
22 | target_link_libraries(kalman_test load simulation gmock)
23 |
24 | test(unscented_test)
25 | target_link_libraries(unscented_test load simulation gmock)
26 |
--------------------------------------------------------------------------------
/mjpc/testspeed.h:
--------------------------------------------------------------------------------
1 | // Copyright 2024 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MJPC_MJPC_TESTSPEED_H_
16 | #define MJPC_MJPC_TESTSPEED_H_
17 |
18 | #include
19 |
20 | namespace mjpc {
21 | double SynchronousPlanningCost(std::string task_name, int planner_thread_count,
22 | int steps_per_planning_iteration,
23 | double total_time);
24 | } // namespace mjpc
25 |
26 | #endif // MJPC_MJPC_TESTSPEED_H_
27 |
--------------------------------------------------------------------------------
/mjpc/test/gradient_planner/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright 2022 DeepMind Technologies Limited
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | test(gradient_planner_test)
16 | target_link_libraries(gradient_planner_test load gmock)
17 |
18 | test(gradient_test)
19 | target_link_libraries(
20 | gradient_test
21 | lqr
22 | gmock
23 | )
24 |
25 | test(zero_test)
26 | target_link_libraries(zero_test gmock)
27 |
28 | test(linear_test)
29 | target_link_libraries(linear_test gmock)
30 |
31 | test(cubic_test)
32 | target_link_libraries(cubic_test gmock)
33 |
--------------------------------------------------------------------------------
/mjpc/tasks/acrobot/acrobot.xml.patch:
--------------------------------------------------------------------------------
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 |
8 | -
9 | -
10 | -
11 | -
12 |
13 |
14 |
15 |
16 |
17 | -
21 |
22 |
23 |
24 | -
25 | +
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/python/mujoco_mpc/demos/agent/cartpole_gui.py:
--------------------------------------------------------------------------------
1 | # Copyright 2022 DeepMind Technologies Limited
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import mujoco
16 | from mujoco_mpc import agent as agent_lib
17 | import pathlib
18 |
19 | # Cartpole model
20 | model_path = (
21 | pathlib.Path(__file__).parent.parent.parent
22 | / "../../build/mjpc/tasks/cartpole/task.xml"
23 | )
24 | model = mujoco.MjModel.from_xml_path(str(model_path))
25 |
26 | # Run GUI
27 | with agent_lib.Agent(
28 | server_binary_path=pathlib.Path(agent_lib.__file__).parent
29 | / "mjpc"
30 | / "ui_agent_server",
31 | task_id="Cartpole",
32 | model=model,
33 | ) as agent:
34 | while True:
35 | pass
36 |
--------------------------------------------------------------------------------
/CITATION.cff:
--------------------------------------------------------------------------------
1 | cff-version: 1.2.0
2 | authors:
3 | - family-names: Howell
4 | given-names: Taylor
5 | - family-names: Gileadi
6 | given-names: Nimrod
7 | - family-names: Tunyasuvunakool
8 | given-names: Saran
9 | - family-names: Zakka
10 | given-names: Kevin
11 | - family-names: Erez
12 | given-names: Tom
13 | - family-names: Tassa
14 | given-names: Yuval
15 | date-released: "2022-12-01"
16 | message: "If you use this software, please cite it as below."
17 | preferred-citation:
18 | authors:
19 | - family-names: Howell
20 | given-names: Taylor
21 | - family-names: Gileadi
22 | given-names: Nimrod
23 | - family-names: Tunyasuvunakool
24 | given-names: Saran
25 | - family-names: Zakka
26 | given-names: Kevin
27 | - family-names: Erez
28 | given-names: Tom
29 | - family-names: Tassa
30 | given-names: Yuval
31 | date-published: "2022-12-01"
32 | doi: 10.48550/ARXIV.2212.00541
33 | month: 12
34 | publisher:
35 | name: arXiv
36 | title: "Predictive Sampling: Real-time Behaviour Synthesis with MuJoCo"
37 | type: article
38 | url: "https://arxiv.org/abs/2212.00541"
39 | year: 2022
40 | title: "MuJoCo MPC (MJPC)"
41 | url: "https://github.com/google-deepmind/mujoco_mpc"
42 |
--------------------------------------------------------------------------------
/mjpc/estimators/include.h:
--------------------------------------------------------------------------------
1 | // Copyright 2022 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MJPC_ESTIMATORS_INCLUDE_H_
16 | #define MJPC_ESTIMATORS_INCLUDE_H_
17 |
18 | #include
19 | #include
20 |
21 | #include "mjpc/estimators/estimator.h"
22 | #include "mjpc/estimators/kalman.h"
23 | #include "mjpc/estimators/unscented.h"
24 |
25 | namespace mjpc {
26 |
27 | // Estimator names, separated by '\n'.
28 | extern const char kEstimatorNames[];
29 |
30 | // Loads all available estimators
31 | std::vector> LoadEstimators();
32 |
33 | } // namespace mjpc
34 |
35 | #endif // MJPC_ESTIMATORS_INCLUDE_H_
36 |
--------------------------------------------------------------------------------
/mjpc/planners/planner.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2022 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "mjpc/planners/planner.h"
16 |
17 | #include
18 |
19 | #include
20 | #include "mjpc/utilities.h"
21 |
22 | namespace mjpc {
23 | void Planner::ResizeMjData(const mjModel* model, int num_threads) {
24 | int new_size = std::max(1, num_threads);
25 | if (data_.size() > new_size) {
26 | data_.erase(data_.begin() + new_size, data_.end());
27 | } else {
28 | data_.reserve(new_size);
29 | while (data_.size() < new_size) {
30 | data_.push_back(MakeUniqueMjData(mj_makeData(model)));
31 | }
32 | }
33 | }
34 | } // namespace mjpc
35 |
--------------------------------------------------------------------------------
/mjpc/test/agent/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright 2022 DeepMind Technologies Limited
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | test(agent_test)
16 | target_link_libraries(agent_test load gmock)
17 |
18 | test(agent_utilities_test)
19 | target_link_libraries(agent_utilities_test load threadpool gmock)
20 |
21 | test(cost_derivatives_test)
22 | target_link_libraries(cost_derivatives_test gmock)
23 |
24 | test(norm_test)
25 | target_link_libraries(norm_test gmock)
26 |
27 | test(rollout_test)
28 | target_link_libraries(rollout_test load gmock)
29 |
30 | test(threadpool_test)
31 | target_link_libraries(threadpool_test threadpool gmock)
32 |
33 | test(trajectory_test)
34 | target_link_libraries(trajectory_test gmock)
35 |
36 |
--------------------------------------------------------------------------------
/mjpc/test/direct/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright 2022 DeepMind Technologies Limited
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | test(direct_force_test)
16 | target_link_libraries(direct_force_test load simulation gmock)
17 |
18 | test(direct_parameter_test)
19 | target_link_libraries(direct_parameter_test load simulation gmock)
20 |
21 | test(direct_optimize_test)
22 | target_link_libraries(direct_optimize_test load simulation gmock)
23 |
24 | test(direct_sensor_test)
25 | target_link_libraries(direct_sensor_test load simulation gmock)
26 |
27 | test(direct_trajectory_test)
28 | target_link_libraries(direct_trajectory_test gmock)
29 |
30 | test(direct_utilities_test)
31 | target_link_libraries(direct_utilities_test load simulation gmock)
32 |
--------------------------------------------------------------------------------
/mjpc/direct/model_parameters.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2023 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "mjpc/direct/model_parameters.h"
16 |
17 | #include
18 | #include
19 |
20 | namespace mjpc {
21 |
22 | // Loads all available ModelParameters
23 | std::vector> LoadModelParameters() {
24 | // model parameters
25 | std::vector> model_parameters;
26 |
27 | // add model parameters
28 | model_parameters.emplace_back(new mjpc::Particle1DDampedParameters());
29 | model_parameters.emplace_back(new mjpc::Particle1DFramePosParameters());
30 |
31 | return model_parameters;
32 | }
33 |
34 | } // namespace mjpc
35 |
--------------------------------------------------------------------------------
/mjpc/app.h:
--------------------------------------------------------------------------------
1 | // Copyright 2021 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MJPC_APP_H_
16 | #define MJPC_APP_H_
17 |
18 | #include
19 | #include
20 |
21 | #include "mjpc/simulate.h" // mjpc fork
22 | #include "mjpc/task.h"
23 |
24 | namespace mjpc {
25 | class MjpcApp {
26 | public:
27 | MjpcApp(std::vector> tasks, int task_id = 0);
28 | MjpcApp(const MjpcApp&) = delete;
29 | MjpcApp& operator=(const MjpcApp&) = delete;
30 | ~MjpcApp();
31 |
32 | void Start();
33 |
34 | ::mujoco::Simulate* Sim();
35 | };
36 |
37 | void StartApp(std::vector> tasks, int task_id = 0);
38 |
39 | } // namespace mjpc
40 |
41 | #endif // MJPC_APP_H_
42 |
--------------------------------------------------------------------------------
/mjpc/planners/gradient/settings.h:
--------------------------------------------------------------------------------
1 | // Copyright 2022 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MJPC_PLANNERS_GRADIENT_SETTINGS_H_
16 | #define MJPC_PLANNERS_GRADIENT_SETTINGS_H_
17 |
18 | namespace mjpc {
19 |
20 | // GradientPlanner settings
21 | struct GradientPlannerSettings {
22 | int max_rollout = 1; // maximum number of planner iterations
23 | double min_linesearch_step = 1.0e-8; // minimum step size for line search
24 | double fd_tolerance = 1.0e-5; // finite-difference tolerance
25 | double fd_mode = 0; // type of finite difference; 0: one-side, 1: centered
26 | int action_limits = 1; // flag
27 | };
28 |
29 | } // namespace mjpc
30 |
31 | #endif // MJPC_PLANNERS_GRADIENT_SETTINGS_H_
32 |
--------------------------------------------------------------------------------
/mjpc/test/testdata/box.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/mjpc/planners/include.h:
--------------------------------------------------------------------------------
1 | // Copyright 2022 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MJPC_PLANNERS_INCLUDE_H_
16 | #define MJPC_PLANNERS_INCLUDE_H_
17 |
18 | #include
19 | #include
20 |
21 | #include "mjpc/planners/planner.h"
22 |
23 | namespace mjpc {
24 |
25 | // planner types
26 | enum PlannerType : int {
27 | kSamplingPlanner = 0,
28 | kGradientPlanner,
29 | kILQGPlanner,
30 | kILQSPlanner,
31 | kRobustPlanner,
32 | kCrossEntropyPlanner,
33 | kSampleGradientPlanner,
34 | };
35 |
36 | // Planner names, separated by '\n'.
37 | extern const char kPlannerNames[];
38 |
39 | // Loads all available planners
40 | std::vector> LoadPlanners();
41 |
42 | } // namespace mjpc
43 |
44 | #endif // MJPC_PLANNERS_INCLUDE_H_
45 |
--------------------------------------------------------------------------------
/mjpc/tasks/acrobot/task.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/cmake/MujocoHarden.cmake:
--------------------------------------------------------------------------------
1 | # Copyright 2022 DeepMind Technologies Limited
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | option(MUJOCO_HARDEN "Enable build hardening for MuJoCo." OFF)
16 | if(MUJOCO_HARDEN
17 | AND NOT
18 | CMAKE_CXX_COMPILER_ID
19 | MATCHES
20 | ".*Clang.*"
21 | )
22 | message(FATAL_ERROR "MUJOCO_HARDEN is only supported when building with Clang")
23 | endif()
24 |
25 | if(MUJOCO_HARDEN)
26 | set(MUJOCO_HARDEN_COMPILE_OPTIONS -D_FORTIFY_SOURCE=2 -fstack-protector)
27 | if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
28 | set(MUJOCO_HARDEN_LINK_OPTIONS -Wl,-bind_at_load)
29 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
30 | set(MUJOCO_HARDEN_LINK_OPTIONS -Wl,-z,relro -Wl,-z,now)
31 | endif()
32 | else()
33 | set(MUJOCO_HARDEN_COMPILE_OPTIONS "")
34 | set(MUJOCO_HARDEN_LINK_OPTIONS "")
35 | endif()
36 |
--------------------------------------------------------------------------------
/mjpc/test/agent/threadpool_test.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2022 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "mjpc/threadpool.h"
16 |
17 | #include "gtest/gtest.h"
18 | #include
19 |
20 | namespace mjpc {
21 | namespace {
22 |
23 | // test threadpool scheduling
24 | TEST(ThreadPoolTest, Count) {
25 | // pool
26 | ThreadPool pool(2);
27 |
28 | // count
29 | int count[3] = {0, 0, 0};
30 |
31 | // run
32 | {
33 | int count_before = pool.GetCount();
34 | for (int i = 0; i < 3; i++) {
35 | pool.Schedule([&count, i]() { count[i] += i; });
36 | }
37 | pool.WaitCount(count_before + 3);
38 | }
39 | pool.ResetCount();
40 |
41 | // test
42 | for (int i = 0; i < 3; i++) {
43 | EXPECT_EQ(count[i], i);
44 | }
45 | }
46 |
47 | } // namespace
48 | } // namespace mjpc
49 |
--------------------------------------------------------------------------------
/mjpc/tasks/quadrotor/quadrotor.xml.patch:
--------------------------------------------------------------------------------
1 | diff --git a/quadrotor_modified.xml b/quadrotor_modified.xml
2 | --- a/quadrotor_modified.xml
3 | +++ b/quadrotor_modified.xml
4 | @@ -25,13 +25,12 @@
5 |
6 |
7 |
8 | -
9 |
10 |
11 |
12 |
13 |
14 | -
15 | +
16 |
17 |
18 |
19 | @@ -58,14 +57,4 @@
20 |
21 |
22 |
23 | -
24 | -
25 | -
26 | -
27 | -
28 | -
29 | -
30 | -
31 | -
32 | -
33 |
34 |
--------------------------------------------------------------------------------
/mjpc/norm.h:
--------------------------------------------------------------------------------
1 | // Copyright 2022 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MJPC_NORM_H_
16 | #define MJPC_NORM_H_
17 |
18 | namespace mjpc {
19 |
20 | // maximum number of norm parameters
21 | inline constexpr int kMaxNormParameters = 3;
22 |
23 | // norm types
24 | enum NormType : int {
25 | kNull = -1,
26 | kQuadratic = 0,
27 | kL22 = 1,
28 | kL2 = 2,
29 | kCosh = 3,
30 | // retain ordering for backward compatibility
31 | kPowerLoss = 5,
32 | kSmoothAbsLoss = 6,
33 | kSmoothAbs2Loss = 7,
34 | kRectifyLoss = 8,
35 | };
36 |
37 | // norm's number of parameters
38 | int NormParameterDimension(int type);
39 |
40 | // evaluate norm; optionally, gradient and Hessian
41 | double Norm(double *g, double *H, const double *x, const double *params, int n,
42 | NormType type);
43 |
44 | } // namespace mjpc
45 |
46 | #endif // MJPC_NORM_H_
47 |
--------------------------------------------------------------------------------
/mjpc/tasks/particle/task.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/docs/GUI.md:
--------------------------------------------------------------------------------
1 | # Graphical User Interface
2 |
3 | - [Graphical User Interface](#graphical-user-interface)
4 | - [Overview](#overview)
5 | - [User Guide](#user-guide)
6 |
7 | ## Overview
8 |
9 | The MJPC GUI is built on top of MuJoCo's `simulate` application with a few additional features. The below screenshot shows a capture of the GUI for the `walker` task.
10 |
11 | 
12 |
13 | ## User Guide
14 |
15 | - Press `F1` to bring up a help pane that describes how to use the GUI.
16 | - The MJPC GUI is an extension of MuJoCo's native `simulate` viewer, with the same keyboard shortcuts and mouse functionality.
17 | - `+` speeds up the simulation, resulting in fewer planning steps per simulation step.
18 | - `-` slows down the simulation, resulting in more planning steps per simulation step.
19 | - The `simulate` viewer enables drag-and-drop interaction with simulated objects to apply forces or torques.
20 | - Double-click on a body to select it.
21 | - `Ctrl + left drag` applies a torque to the selected object, resulting in rotation.
22 | - `Ctrl + right drag` applies a force to the selected object in the `(x,z)` plane, resulting in translation.
23 | - `Ctrl + Shift + right drag` applies a force to the selected object in the `(x,y)` plane.
24 | - MJPC adds three keyboard shortcuts:
25 | - The `Enter` key starts and stops the planner.
26 | - The `\` key starts and stops the controller (sending actions from the planner to the model).
27 | - The `9` key turns the traces on/off.
28 |
--------------------------------------------------------------------------------
/mjpc/tasks/common.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/mjpc/estimators/include.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2022 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include
16 | #include
17 | #include "mjpc/estimators/batch.h"
18 | #include "mjpc/estimators/estimator.h"
19 | #include "mjpc/estimators/include.h"
20 |
21 | namespace mjpc {
22 |
23 | const char kEstimatorNames[] =
24 | "Ground Truth\n"
25 | "Kalman\n"
26 | "Unscented\n"
27 | "Batch";
28 |
29 | // load all available estimators
30 | std::vector> LoadEstimators() {
31 | // planners
32 | std::vector> estimators;
33 |
34 | // add estimators
35 | estimators.emplace_back(new mjpc::GroundTruth()); // ground truth state
36 | estimators.emplace_back(new mjpc::Kalman()); // extended Kalman filter
37 | estimators.emplace_back(new mjpc::Unscented()); // unscented Kalman filter
38 | estimators.emplace_back(new mjpc::Batch()); // recursive batch filter
39 |
40 | return estimators;
41 | }
42 |
43 | } // namespace mjpc
44 |
--------------------------------------------------------------------------------
/mjpc/test/testdata/common.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/mjpc/test/load.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2022 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "mjpc/test/load.h"
16 |
17 | #include
18 | #include
19 | #include
20 |
21 | // DEEPMIND INTERNAL IMPORT
22 | #include
23 | #include
24 | #include "mjpc/array_safety.h"
25 |
26 | namespace mjpc {
27 |
28 | static std::string RelativeTestModelPath(std::string_view path) {
29 | return absl::StrCat("../../mjpc/test/testdata/", path);
30 | }
31 |
32 | // convenience function for paths
33 | mjModel* LoadTestModel(std::string_view path) {
34 | // filename
35 | char filename[1024];
36 | const std::string path_str =
37 | RelativeTestModelPath(path);
38 | mujoco::util_mjpc::strcpy_arr(filename, path_str.c_str());
39 |
40 | // load model
41 | char loadError[1024] = "";
42 | mjModel* model = mj_loadXML(filename, nullptr, loadError, 1000);
43 | if (loadError[0]) std::cerr << "load error: " << loadError << '\n';
44 |
45 | return model;
46 | }
47 |
48 | } // namespace mjpc
49 |
--------------------------------------------------------------------------------
/mjpc/planners/policy.h:
--------------------------------------------------------------------------------
1 | // Copyright 2022 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MJPC_PLANNERS_POLICY_H_
16 | #define MJPC_PLANNERS_POLICY_H_
17 |
18 | #include
19 | #include "mjpc/task.h"
20 |
21 | namespace mjpc {
22 |
23 | // virtual policy
24 | class Policy {
25 | public:
26 | // destructor
27 | virtual ~Policy() = default;
28 |
29 | // allocate memory
30 | virtual void Allocate(const mjModel* model, const Task& task,
31 | int horizon) = 0;
32 |
33 | // reset memory to zeros
34 | virtual void Reset(int horizon,
35 | const double* initial_repeated_action = nullptr) = 0;
36 |
37 | // set action from policy
38 | // for policies that have a feedback term, passing nullptr for state turns
39 | // the feedback term off and returns the nominal action for that time
40 | virtual void Action(double* action, const double* state,
41 | double time) const = 0;
42 | };
43 |
44 | } // namespace mjpc
45 |
46 | #endif // MJPC_PLANNERS_POLICY_H_
47 |
--------------------------------------------------------------------------------
/mjpc/planners/ilqg/settings.h:
--------------------------------------------------------------------------------
1 | // Copyright 2022 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MJPC_PLANNERS_ILQG_SETTINGS_H_
16 | #define MJPC_PLANNERS_ILQG_SETTINGS_H_
17 |
18 | namespace mjpc {
19 |
20 | // iLQG settings
21 | struct iLQGSettings {
22 | double min_linesearch_step = 1.0e-3; // minimum step size for line search
23 | double fd_tolerance = 1.0e-6; // finite difference tolerance
24 | double fd_mode = 0; // type of finite difference; 0: one-sided, 1: centered
25 | double min_regularization = 1.0e-6; // minimum regularization value
26 | double max_regularization = 1.0e6; // maximum regularization value
27 | int regularization_type = 0; // 0: control; 1: feedback; 2: value; 3: none
28 | int max_regularization_iterations =
29 | 5; // maximum number of regularization updates per iteration
30 | int action_limits = 1; // flag
31 | int nominal_feedback_scaling = 1; // flag
32 | int verbose = 0; // print optimizer info
33 | };
34 |
35 | } // namespace mjpc
36 |
37 | #endif // MJPC_PLANNERS_ILQG_SETTINGS_H_
38 |
--------------------------------------------------------------------------------
/mjpc/tasks/humanoid/interact/scenes/bed.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
27 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/mjpc/tasks/rubik/transition_model.xml.patch:
--------------------------------------------------------------------------------
1 | diff --git a/transition_model.xml b/transition_model.xml
2 | --- a/transition_model.xml
3 | +++ b/transition_model.xml
4 | @@ -1,5 +1,5 @@
5 |
6 | -
7 | +
8 |
9 |
10 |
11 | @@ -14,10 +14,10 @@
12 |
13 |
14 |
15 | -
16 | +
17 |
18 | -
19 | -
20 | +
21 | +
22 |
23 |
24 |
25 | @@ -203,11 +203,11 @@
26 |
27 |
28 |
29 | -
30 | -
31 | -
32 | -
33 | -
34 | -
35 | +
36 | +
37 | +
38 | +
39 | +
40 | +
41 |
42 |
43 |
--------------------------------------------------------------------------------
/mjpc/tasks/fingers/fingers.h:
--------------------------------------------------------------------------------
1 | // Copyright 2022 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MJPC_MJPC_TASKS_FINGERS_FINGERS_H_
16 | #define MJPC_MJPC_TASKS_FINGERS_FINGERS_H_
17 |
18 | #include
19 | #include
20 | #include
21 | #include "mjpc/task.h"
22 |
23 | namespace mjpc {
24 | class Fingers : public Task {
25 | public:
26 | std::string Name() const override;
27 | std::string XmlPath() const override;
28 | class ResidualFn : public mjpc::BaseResidualFn {
29 | public:
30 | explicit ResidualFn(const Fingers* task) : mjpc::BaseResidualFn(task) {}
31 | void Residual(const mjModel* model, const mjData* data,
32 | double* residual) const override;
33 | };
34 | Fingers() : residual_(this) {}
35 |
36 | protected:
37 | std::unique_ptr ResidualLocked() const override {
38 | return std::make_unique(this);
39 | }
40 | ResidualFn* InternalResidual() override { return &residual_; }
41 |
42 | private:
43 | ResidualFn residual_;
44 | };
45 | } // namespace mjpc
46 |
47 |
48 | #endif // MJPC_MJPC_TASKS_FINGERS_FINGERS_H_
49 |
--------------------------------------------------------------------------------
/mjpc/tasks/panda/panda.h:
--------------------------------------------------------------------------------
1 | // Copyright 2022 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MJPC_MJPC_TASKS_PANDA_PANDA_H_
16 | #define MJPC_MJPC_TASKS_PANDA_PANDA_H_
17 |
18 | #include
19 | #include
20 | #include "mjpc/task.h"
21 |
22 | namespace mjpc {
23 | class Panda : public Task {
24 | public:
25 | std::string Name() const override;
26 | std::string XmlPath() const override;
27 | class ResidualFn : public mjpc::BaseResidualFn {
28 | public:
29 | explicit ResidualFn(const Panda* task) : mjpc::BaseResidualFn(task) {}
30 | void Residual(const mjModel* model, const mjData* data,
31 | double* residual) const override;
32 | };
33 | Panda() : residual_(this) {}
34 | void TransitionLocked(mjModel* model, mjData* data) override;
35 |
36 | protected:
37 | std::unique_ptr ResidualLocked() const override {
38 | return std::make_unique(this);
39 | }
40 | ResidualFn* InternalResidual() override { return &residual_; }
41 |
42 | private:
43 | ResidualFn residual_;
44 | };
45 | } // namespace mjpc
46 |
47 |
48 | #endif // MJPC_MJPC_TASKS_PANDA_PANDA_H_
49 |
--------------------------------------------------------------------------------
/mjpc/tasks/allegro/right_hand.xml.patch:
--------------------------------------------------------------------------------
1 | diff --git a/right_hand_modified.xml b/right_hand_modified.xml
2 | --- a/right_hand_modified.xml
3 | +++ b/right_hand_modified.xml
4 | @@ -6,7 +6,7 @@
5 |
6 |
7 |
8 | -
9 | +
10 |
11 |
12 |
13 | @@ -124,8 +124,9 @@
14 |
15 |
16 |
17 | -
18 | +
19 |
20 | +
21 |
22 |
23 |
24 | @@ -148,6 +149,7 @@
25 |
26 |
27 |
28 | +
29 |
30 |
31 |
32 | @@ -257,4 +259,12 @@
33 |
34 |
35 |
36 | +
37 | +
38 | +
39 | +
40 | +
41 | +
42 | +
43 | +
44 |
45 |
--------------------------------------------------------------------------------
/mjpc/tasks/humanoid/interact/scenes/bench.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
31 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/mjpc/interface.h:
--------------------------------------------------------------------------------
1 | // Copyright 2021 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MJPC_MJPC_INTERFACE_H_
16 | #define MJPC_MJPC_INTERFACE_H_
17 |
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include "mjpc/agent.h"
23 | #include "mjpc/task.h"
24 | #include "mjpc/threadpool.h"
25 | #include "mjpc/utilities.h"
26 |
27 |
28 | namespace mjpc {
29 | class AgentRunner{
30 | public:
31 | ~AgentRunner();
32 | explicit AgentRunner(const mjModel* model, std::shared_ptr task);
33 | void Step(mjData* data);
34 | void Residual(const mjModel* model, mjData* data);
35 | private:
36 | Agent agent_;
37 | ThreadPool agent_plan_pool_;
38 | std::atomic_bool exit_request_ = false;
39 | std::atomic_int ui_load_request_ = 0;
40 | };
41 |
42 | } // namespace mjpc
43 |
44 | extern "C" void destroy_policy();
45 | extern "C" void create_policy_from_task_id(const mjModel* model, int task_id);
46 | extern "C" void create_policy(const mjModel* model,
47 | std::shared_ptr task);
48 | extern "C" void step_policy(mjData* data);
49 | extern "C" void set_weights(double* weights);
50 |
51 | #endif // MJPC_MJPC_INTERFACE_H_
52 |
--------------------------------------------------------------------------------
/mjpc/test/lqr.h:
--------------------------------------------------------------------------------
1 | // Copyright 2022 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MJPC_TEST_LQR_H_
16 | #define MJPC_TEST_LQR_H_
17 |
18 | #include
19 |
20 | namespace mjpc {
21 |
22 | // ----- LQR problem ----- //
23 |
24 | // linear dynamics
25 | void f(double* y, const double* x, const double* u);
26 |
27 | // dynamics state Jacobian
28 | void fx(double* A, const double* x, const double* u);
29 |
30 | // dynamics action Jacobian
31 | void fu(double* B, const double* x, const double* u);
32 |
33 | // cost
34 | double c(const double* x, const double* u);
35 |
36 | // cost gradient state
37 | void cx(double* Jx, const double* x, const double* u);
38 |
39 | // cost gradient action
40 | void cu(double* Ju, const double* x, const double* u);
41 |
42 | // cost Hessian state
43 | void cxx(double* Jxx, const double* x, const double* u);
44 |
45 | // cost Hessian action
46 | void cuu(double* Juu, const double* x, const double* u);
47 |
48 | // cost Hessian action
49 | void cxu(double* Jxu, const double* x, const double* u);
50 |
51 | // rollout return
52 | double RolloutReturn(double* x, const double* u, const double* x0, int T);
53 |
54 | } // namespace mjpc
55 |
56 | #endif // MJPC_TEST_LQR_H_
57 |
--------------------------------------------------------------------------------
/mjpc/test/testdata/particle_task.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/mjpc/tasks/allegro/allegro.h:
--------------------------------------------------------------------------------
1 | // Copyright 2022 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MJPC_TASKS_ALLEGRO_ALLEGRO_H_
16 | #define MJPC_TASKS_ALLEGRO_ALLEGRO_H_
17 |
18 | #include
19 | #include
20 |
21 | #include
22 | #include "mjpc/task.h"
23 |
24 | namespace mjpc {
25 | class Allegro : public Task {
26 | public:
27 | std::string Name() const override;
28 | std::string XmlPath() const override;
29 |
30 | class ResidualFn : public BaseResidualFn {
31 | public:
32 | explicit ResidualFn(const Allegro *task) : BaseResidualFn(task) {}
33 | void Residual(const mjModel *model, const mjData *data,
34 | double *residual) const override;
35 | };
36 | Allegro() : residual_(this) {}
37 |
38 | // Reset the cube into the hand if it's on the floor
39 | void TransitionLocked(mjModel *model, mjData *data) override;
40 |
41 | protected:
42 | std::unique_ptr ResidualLocked() const override {
43 | return std::make_unique(this);
44 | }
45 | ResidualFn *InternalResidual() override { return &residual_; }
46 |
47 | private:
48 | ResidualFn residual_;
49 | };
50 | } // namespace mjpc
51 |
52 | #endif // MJPC_TASKS_ALLEGRO_ALLEGRO_H_
53 |
--------------------------------------------------------------------------------
/mjpc/macos_gui.mm:
--------------------------------------------------------------------------------
1 | // Copyright 2022 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include
16 | #include
17 |
18 | #include
19 |
20 | std::string GetSavePath(const char* filename) {
21 | NSSavePanel* panel = [NSSavePanel savePanel];
22 | NSURL* userDocumentsDir = [NSFileManager.defaultManager URLsForDirectory:NSDocumentDirectory
23 | inDomains:NSUserDomainMask].firstObject;
24 | [panel setDirectoryURL:userDocumentsDir];
25 | [panel setNameFieldStringValue:[NSString stringWithUTF8String:filename]];
26 | if ([panel runModal] == NSModalResponseOK) {
27 | std::ostringstream s;
28 | s << [panel.URL.path cStringUsingEncoding:NSUTF8StringEncoding];
29 | return s.str();
30 | } else {
31 | return "";
32 | }
33 | }
34 |
35 | #ifdef __AVX__
36 | void DisplayErrorDialogBox(const char* title, const char* msg) {
37 | NSAlert *alert = [[[NSAlert alloc] init] autorelease];
38 | [alert setMessageText:[NSString stringWithUTF8String:title]];
39 | [alert setInformativeText:[NSString stringWithUTF8String:msg]];
40 | [alert setAlertStyle:NSAlertStyleCritical];
41 | [alert addButtonWithTitle:@"Exit"];
42 | [alert runModal];
43 | }
44 | #endif
45 |
--------------------------------------------------------------------------------
/mjpc/tasks/cartpole/cartpole.xml.patch:
--------------------------------------------------------------------------------
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 | -
6 | -
7 | -
8 | -
9 | -
10 | -