Skip to content

Commit bcd9172

Browse files
committed
Ensures compatibility with MuJoCo 2.2.2
1 parent 7e0c155 commit bcd9172

File tree

8 files changed

+212
-17
lines changed

8 files changed

+212
-17
lines changed

mujoco_ros/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ initial_joint_velocities:
4040
___
4141
4242
# Build Instructions
43-
1. Make sure MuJoCo is installed (the current build uses version 2.1.1) and runs on your machine.
43+
1. Make sure MuJoCo is installed (the current build uses version 2.2.2) and runs on your machine.
4444
2. Create a new ROS workspace or include this repository into an existing workspace.
4545
3. Before building, make sure that your compiler knows where to find the MuJoCo library, e.g. by running
4646
```bash

mujoco_ros/THIRD_PARTY_NOTICES

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The mujoco_ros package is incorporates the MuJoCo Version 2.1.1 library.
1+
The mujoco_ros package is incorporates the MuJoCo Version 2.2.2 library.
22
Its copyright and license information is included below.
33

44
========================= MuJoCo ============================================
@@ -19,7 +19,7 @@ limitations under the License.
1919

2020
---- MuJoCo Third Party Notice ----
2121

22-
MuJoCo version 2.1.1 incorporates the following open-source libraries:
22+
MuJoCo version 2.2.2 incorporates the following open-source libraries:
2323

2424
- libccd
2525
- Collisions

mujoco_ros/include/mujoco_ros/common_types.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
#pragma once
3838

39-
#include <mujoco.h>
39+
#include <mujoco/mujoco.h>
4040

4141
static constexpr int kBufSize = 1000;
4242

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 MUJOCO_SIMULATE_GLFW_DISPATCH_H_
16+
#define MUJOCO_SIMULATE_GLFW_DISPATCH_H_
17+
18+
#include <GLFW/glfw3.h>
19+
20+
namespace mujoco {
21+
// Dynamic dispatch table for GLFW functions required by Simulate.
22+
// This allows us to use GLFW without introducing a link-time dependency on the
23+
// library, which is useful e.g. when using GLFW via Python.
24+
struct Glfw
25+
{
26+
#define mjGLFW_DECLARE_SYMBOL(func) decltype(&::func) func
27+
// go/keep-sorted start
28+
mjGLFW_DECLARE_SYMBOL(glfwCreateWindow);
29+
mjGLFW_DECLARE_SYMBOL(glfwGetCursorPos);
30+
mjGLFW_DECLARE_SYMBOL(glfwGetFramebufferSize);
31+
mjGLFW_DECLARE_SYMBOL(glfwGetKey);
32+
mjGLFW_DECLARE_SYMBOL(glfwGetMonitorPhysicalSize);
33+
mjGLFW_DECLARE_SYMBOL(glfwGetMouseButton);
34+
mjGLFW_DECLARE_SYMBOL(glfwGetPrimaryMonitor);
35+
mjGLFW_DECLARE_SYMBOL(glfwGetTime);
36+
mjGLFW_DECLARE_SYMBOL(glfwGetVideoMode);
37+
mjGLFW_DECLARE_SYMBOL(glfwGetWindowMonitor);
38+
mjGLFW_DECLARE_SYMBOL(glfwGetWindowPos);
39+
mjGLFW_DECLARE_SYMBOL(glfwGetWindowSize);
40+
mjGLFW_DECLARE_SYMBOL(glfwGetWindowUserPointer);
41+
mjGLFW_DECLARE_SYMBOL(glfwInit);
42+
mjGLFW_DECLARE_SYMBOL(glfwMakeContextCurrent);
43+
mjGLFW_DECLARE_SYMBOL(glfwPollEvents);
44+
mjGLFW_DECLARE_SYMBOL(glfwSetClipboardString);
45+
mjGLFW_DECLARE_SYMBOL(glfwSetCursorPosCallback);
46+
mjGLFW_DECLARE_SYMBOL(glfwSetDropCallback);
47+
mjGLFW_DECLARE_SYMBOL(glfwSetKeyCallback);
48+
mjGLFW_DECLARE_SYMBOL(glfwSetMouseButtonCallback);
49+
mjGLFW_DECLARE_SYMBOL(glfwSetScrollCallback);
50+
mjGLFW_DECLARE_SYMBOL(glfwSetWindowMonitor);
51+
mjGLFW_DECLARE_SYMBOL(glfwSetWindowRefreshCallback);
52+
mjGLFW_DECLARE_SYMBOL(glfwSetWindowSizeCallback);
53+
mjGLFW_DECLARE_SYMBOL(glfwSetWindowTitle);
54+
mjGLFW_DECLARE_SYMBOL(glfwSetWindowUserPointer);
55+
mjGLFW_DECLARE_SYMBOL(glfwSwapBuffers);
56+
mjGLFW_DECLARE_SYMBOL(glfwSwapInterval);
57+
mjGLFW_DECLARE_SYMBOL(glfwTerminate);
58+
mjGLFW_DECLARE_SYMBOL(glfwWindowHint);
59+
mjGLFW_DECLARE_SYMBOL(glfwWindowShouldClose);
60+
// go/keep-sorted end
61+
#undef mjGLFW_DECLARE_SYMBOL
62+
};
63+
64+
const struct Glfw &Glfw(void *dlhandle = nullptr);
65+
} // namespace mujoco
66+
67+
#endif // MUJOCO_SIMULATE_GLFW_DISPATCH_H_

mujoco_ros/include/mujoco_ros/mujoco_sim.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#include <condition_variable>
6060
#include <ros/ros.h>
6161

62-
#include "mjxmacro.h"
62+
#include <mujoco/mjxmacro.h>
6363

6464
#include <mujoco_ros/common_types.h>
6565
#include <mujoco_ros/mujoco_env.h>

mujoco_ros/include/mujoco_ros/uitools.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define MUJOCO_UITOOLS_H_
1717

1818
#include "GLFW/glfw3.h"
19-
#include "mujoco.h"
19+
#include <mujoco/mujoco.h>
2020

2121
// this is a C-API
2222
#if defined(__cplusplus)

mujoco_ros/src/glfw_dispatch.cc

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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 <mujoco_ros/glfw_dispatch.h>
16+
17+
#ifdef mjGLFW_DYNAMIC_SYMBOLS
18+
#ifdef _MSC_VER
19+
#include <windows.h>
20+
#include <libloaderapi.h>
21+
#else
22+
#include <dlfcn.h>
23+
#endif
24+
#endif
25+
26+
#include <cstdlib>
27+
#include <iostream>
28+
29+
namespace mujoco {
30+
31+
// return dispatch table for glfw functions
32+
const struct Glfw &Glfw(void *dlhandle)
33+
{
34+
{
35+
// set static init_dlhandle
36+
static const void *init_dlhandle = dlhandle;
37+
38+
// check that not already initialized
39+
if (dlhandle && dlhandle != init_dlhandle) {
40+
std::cerr << "dlhandle is specified when GLFW dispatch table is already "
41+
"initialized\n";
42+
abort();
43+
}
44+
}
45+
46+
// make and intialize dispatch table
47+
static const struct Glfw glfw = [&]() { // create and call constructor
48+
// allocate
49+
struct Glfw glfw;
50+
51+
// load glfw dynamically
52+
#ifdef mjGLFW_DYNAMIC_SYMBOLS
53+
#ifdef _MSC_VER
54+
if (!dlhandle)
55+
dlhandle = LoadLibraryA("glfw3.dll");
56+
if (!dlhandle) {
57+
std::cerr << "cannot obtain a shared object handle\n";
58+
abort();
59+
}
60+
#define mjGLFW_RESOLVE_SYMBOL(func) \
61+
glfw.func = reinterpret_cast<decltype(glfw.func)>(GetProcAddress(reinterpret_cast<HMODULE>(dlhandle), #func))
62+
#else
63+
if (!dlhandle)
64+
dlhandle = dlopen("nullptr", RTLD_GLOBAL | RTLD_NOW);
65+
if (!dlhandle) {
66+
std::cerr << "cannot obtain a shared object handle\n";
67+
abort();
68+
}
69+
#define mjGLFW_RESOLVE_SYMBOL(func) glfw.func = reinterpret_cast<decltype(glfw.func)>(dlsym(dlhandle, #func))
70+
#endif
71+
#else
72+
#define mjGLFW_RESOLVE_SYMBOL(func) glfw.func = &::func
73+
#endif
74+
75+
// set pointers in dispatch table
76+
#define mjGLFW_INITIALIZE_SYMBOL(func) \
77+
if (!(mjGLFW_RESOLVE_SYMBOL(func))) { \
78+
std::cerr << "cannot dlsym " #func "\n"; \
79+
abort(); \
80+
}
81+
82+
// go/keep-sorted start
83+
mjGLFW_INITIALIZE_SYMBOL(glfwCreateWindow);
84+
mjGLFW_INITIALIZE_SYMBOL(glfwGetCursorPos);
85+
mjGLFW_INITIALIZE_SYMBOL(glfwGetFramebufferSize);
86+
mjGLFW_INITIALIZE_SYMBOL(glfwGetKey);
87+
mjGLFW_INITIALIZE_SYMBOL(glfwGetMonitorPhysicalSize);
88+
mjGLFW_INITIALIZE_SYMBOL(glfwGetMouseButton);
89+
mjGLFW_INITIALIZE_SYMBOL(glfwGetPrimaryMonitor);
90+
mjGLFW_INITIALIZE_SYMBOL(glfwGetTime);
91+
mjGLFW_INITIALIZE_SYMBOL(glfwGetVideoMode);
92+
mjGLFW_INITIALIZE_SYMBOL(glfwGetWindowMonitor);
93+
mjGLFW_INITIALIZE_SYMBOL(glfwGetWindowPos);
94+
mjGLFW_INITIALIZE_SYMBOL(glfwGetWindowSize);
95+
mjGLFW_INITIALIZE_SYMBOL(glfwGetWindowUserPointer);
96+
mjGLFW_INITIALIZE_SYMBOL(glfwInit);
97+
mjGLFW_INITIALIZE_SYMBOL(glfwMakeContextCurrent);
98+
mjGLFW_INITIALIZE_SYMBOL(glfwPollEvents);
99+
mjGLFW_INITIALIZE_SYMBOL(glfwSetClipboardString);
100+
mjGLFW_INITIALIZE_SYMBOL(glfwSetCursorPosCallback);
101+
mjGLFW_INITIALIZE_SYMBOL(glfwSetDropCallback);
102+
mjGLFW_INITIALIZE_SYMBOL(glfwSetKeyCallback);
103+
mjGLFW_INITIALIZE_SYMBOL(glfwSetMouseButtonCallback);
104+
mjGLFW_INITIALIZE_SYMBOL(glfwSetScrollCallback);
105+
mjGLFW_INITIALIZE_SYMBOL(glfwSetWindowMonitor);
106+
mjGLFW_INITIALIZE_SYMBOL(glfwSetWindowRefreshCallback);
107+
mjGLFW_INITIALIZE_SYMBOL(glfwSetWindowSizeCallback);
108+
mjGLFW_INITIALIZE_SYMBOL(glfwSetWindowTitle);
109+
mjGLFW_INITIALIZE_SYMBOL(glfwSetWindowUserPointer);
110+
mjGLFW_INITIALIZE_SYMBOL(glfwSwapBuffers);
111+
mjGLFW_INITIALIZE_SYMBOL(glfwSwapInterval);
112+
mjGLFW_INITIALIZE_SYMBOL(glfwTerminate);
113+
mjGLFW_INITIALIZE_SYMBOL(glfwWindowHint);
114+
mjGLFW_INITIALIZE_SYMBOL(glfwWindowShouldClose);
115+
// go/keep-sorted end
116+
117+
#undef mjGLFW_INITIALIZE_SYMBOL
118+
119+
#if defined(mjGLFW_DYNAMIC_SYMBOLS) && !defined(_MSC_VER)
120+
dlclose(dlhandle);
121+
#endif
122+
123+
return glfw;
124+
}();
125+
return glfw;
126+
}
127+
} // namespace mujoco

mujoco_ros/src/mujoco_sim.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,7 @@ void makePhysics(mjModelPtr model, int oldstate)
18431843
{
18441844
int i;
18451845

1846-
mjuiDef defPhysics[] = { { mjITEM_SECTION, "Physics", oldstate, NULL, "AP" },
1846+
mjuiDef defPhysics[] = { { mjITEM_SECTION, "Physics", oldstate, nullptr, "AP" },
18471847
{ mjITEM_SELECT, "Integrator", 2, &(model->opt.integrator), "Euler\nRK4" },
18481848
{ mjITEM_SELECT, "Collision", 2, &(model->opt.collision), "All\nPair\nDynamic" },
18491849
{ mjITEM_SELECT, "Cone", 2, &(model->opt.cone), "Pyramidal\nElliptic" },
@@ -1878,7 +1878,7 @@ void makePhysics(mjModelPtr model, int oldstate)
18781878
mjui_add(&ui0_, defPhysics);
18791879

18801880
// add flags programmatically
1881-
mjuiDef defFlag[] = { { mjITEM_CHECKINT, "", 2, NULL, "" }, { mjITEM_END } };
1881+
mjuiDef defFlag[] = { { mjITEM_CHECKINT, "", 2, nullptr, "" }, { mjITEM_END } };
18821882
for (i = 0; i < mjNDISABLE; i++) {
18831883
mju::strcpy_arr(defFlag[0].name, mjDISABLESTRING[i]);
18841884
defFlag[0].pdata = settings_.disable + i;
@@ -1901,12 +1901,12 @@ void makeRendering(mjModelPtr model, int oldstate)
19011901
int i, j;
19021902

19031903
mjuiDef defRendering[] = {
1904-
{ mjITEM_SECTION, "Rendering", oldstate, NULL, "AR" },
1904+
{ mjITEM_SECTION, "Rendering", oldstate, nullptr, "AR" },
19051905
{ mjITEM_SELECT, "Camera", 2, &(settings_.camera), "Free\nTracking" },
19061906
{ mjITEM_SELECT, "Label", 2, &(vopt_.label),
19071907
"None\nBody\nJoint\nGeom\nSite\nCamera\nLight\nTendon\nActuator\nConstraint\nSkin\nSelection\nSel Pnt\nForce" },
19081908
{ mjITEM_SELECT, "Frame", 2, &(vopt_.frame), "None\nBody\nGeom\nSite\nCamera\nLight\nWorld" },
1909-
{ mjITEM_BUTTON, "Print camera", 2, NULL, "" },
1909+
{ mjITEM_BUTTON, "Copy camera", 2, nullptr, "" },
19101910
{
19111911
mjITEM_SEPARATOR,
19121912
"Model Elements",
@@ -1939,7 +1939,7 @@ void makeRendering(mjModelPtr model, int oldstate)
19391939
mjui_add(&ui0_, defRendering);
19401940

19411941
// add flags programmatically
1942-
mjuiDef defFlag[] = { { mjITEM_CHECKBYTE, "", 2, NULL, "" }, { mjITEM_END } };
1942+
mjuiDef defFlag[] = { { mjITEM_CHECKBYTE, "", 2, nullptr, "" }, { mjITEM_END } };
19431943
for (i = 0; i < mjNVISFLAG; i++) {
19441944
// set name, remove "&"
19451945
mju::strcpy_arr(defFlag[0].name, mjVISSTRING[i][0]);
@@ -1958,7 +1958,8 @@ void makeRendering(mjModelPtr model, int oldstate)
19581958
mjui_add(&ui0_, defOpenGL);
19591959
for (i = 0; i < mjNRNDFLAG; i++) {
19601960
mju::strcpy_arr(defFlag[0].name, mjRNDSTRING[i][0]);
1961-
mju::sprintf_arr(defFlag[0].other, " %s", mjRNDSTRING[i][2]);
1961+
if (mjRNDSTRING[i][2][0])
1962+
mju::sprintf_arr(defFlag[0].other, " %s", mjRNDSTRING[i][2]);
19621963
defFlag[0].pdata = scn_.flags + i;
19631964
mjui_add(&ui0_, defFlag);
19641965
}
@@ -1967,7 +1968,7 @@ void makeRendering(mjModelPtr model, int oldstate)
19671968
// Make group section UI
19681969
void makeGroup(int oldstate)
19691970
{
1970-
mjuiDef defGroup[] = { { mjITEM_SECTION, "Group enable", oldstate, NULL, "AG" },
1971+
mjuiDef defGroup[] = { { mjITEM_SECTION, "Group enable", oldstate, nullptr, "AG" },
19711972
{ mjITEM_SEPARATOR, "Geom groups", 1 },
19721973
{ mjITEM_CHECKBYTE, "Geom 0", 2, vopt_.geomgroup, " 0" },
19731974
{ mjITEM_CHECKBYTE, "Geom 1", 2, vopt_.geomgroup + 1, " 1" },
@@ -2014,10 +2015,10 @@ void makeJoint(mjModelPtr model, mjDataPtr data, int oldstate)
20142015
int i;
20152016

20162017
mjuiDef defJoint[] = {
2017-
{ mjITEM_SECTION, "Joint", oldstate, NULL, "AJ" },
2018+
{ mjITEM_SECTION, "Joint", oldstate, nullptr, "AJ" },
20182019
{ mjITEM_END },
20192020
};
2020-
mjuiDef defSlider[] = { { mjITEM_SLIDERNUM, "", 2, NULL, "0 1" }, { mjITEM_END } };
2021+
mjuiDef defSlider[] = { { mjITEM_SLIDERNUM, "", 2, nullptr, "0 1" }, { mjITEM_END } };
20212022

20222023
// add section
20232024
mjui_add(&ui1_, defJoint);
@@ -2061,10 +2062,10 @@ void makeControl(mjModelPtr model, mjDataPtr data, int oldstate)
20612062
{
20622063
int i;
20632064

2064-
mjuiDef defControl[] = { { mjITEM_SECTION, "Control", oldstate, NULL, "AC" },
2065+
mjuiDef defControl[] = { { mjITEM_SECTION, "Control", oldstate, nullptr, "AC" },
20652066
{ mjITEM_BUTTON, "Clear all", 2 },
20662067
{ mjITEM_END } };
2067-
mjuiDef defSlider[] = { { mjITEM_SLIDERNUM, "", 2, NULL, "0 1" }, { mjITEM_END } };
2068+
mjuiDef defSlider[] = { { mjITEM_SLIDERNUM, "", 2, nullptr, "0 1" }, { mjITEM_END } };
20682069

20692070
// Add section
20702071
mjui_add(&ui1_, defControl);

0 commit comments

Comments
 (0)