安装mujoco
方法一:git clone源代码编译
sudo apt install libglfw3-dev libxinerama-dev libxcursor-dev libxi-dev
git clone https://github.com/google-deepmind/mujoco.git
mkdir build && cd build
cmake ..
make -j4
sudo make install
方法二:加载release 版本 重点!!因为是下载的release版本,所以没有mujoco_config
若mujoco不能直接源代码编译
去https://github.com/google-deepmind/mujoco/releases下载指定的版本
命令:git clone https://github.com/google-deepmind/mujoco/releases
将下载的目录解压到指定目录下 ~/.mujoco,记住将下面命令的压缩包替换成自己的版本
命令: mkdir ~/.mujoco
tar -zxvf mujoco210-linux-x86_64.tar.gz -C ~/.mujoco
会出现的问题:
Add the installation prefix of "mujoco" to CMAKE_PREFIX_PATH or set "mujoco_DIR" to a directory containing one of the above files. If "mujoco" provides a separate development package or SDK, be sure it has been installed.
解决办法
将bin路径添加到LD_LIBRARY_PATH
将解压之后的路径添加到 .bashrc文件
命令:gedit ~/.bashrc
在最后一行添加
命令:export MUJOCO_PATH=/home/liu/.mujoco/mujoco-3.1.4
export LD_LIBRARY_PATH=$MUJOCO_PATH/bin:$LD_LIBRARY_PATH
在unitree_mujoco或者你要编译的项目的cmakelists.txt修改,增加以下内容
# 设置自定义 CMake 模块路径
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules")
# 设置 MuJoCo 的路径
set(MUJOCO_PATH "/home/liu/.mujoco/mujoco-3.1.4")
# 包含 MuJoCo 的头文件路径
include_directories(${MUJOCO_PATH}/include)
# 链接 MuJoCo 的库文件路径
link_directories(${MUJOCO_PATH}/lib)
# 手动指定链接的库,注意放在哪,
target_link_libraries(unitree_mujoco ${SIM_DEPENDENCIES} ${MUJOCO_PATH}/lib/libmujoco.so)
删除 find_package(MuJoCo REQUIRED) 及相关引用
如果你没有 MuJoCo 的 CMake 配置文件,删除 find_package(MuJoCo REQUIRED) 和引用 mujoco::mujoco 的部分,而是手动设置 MuJoCo 的路径。
在simulate文件夹下新建cmake_modules文件夹,建一个 FindMuJoCo.cmake文件
# FindMuJoCo.cmake
# 手动设置 MuJoCo 包含路径和库路径
find_path(MUJOCO_INCLUDE_DIR mujoco.h
PATHS
/home/liu/.mujoco/mujoco-3.1.4/include/mujoco
)
find_library(MUJOCO_LIBRARY mujoco
PATHS
/home/liu/.mujoco/mujoco-3.1.4/lib
)
# 检查是否找到路径
if (MUJOCO_INCLUDE_DIR AND MUJOCO_LIBRARY)
set(MUJOCO_FOUND TRUE)
set(MUJOCO_LIBRARIES ${MUJOCO_LIBRARY})
set(MUJOCO_INCLUDE_DIRS ${MUJOCO_INCLUDE_DIR})
else()
set(MUJOCO_FOUND FALSE)
endif()
mark_as_advanced(MUJOCO_INCLUDE_DIR MUJOCO_LIBRARY)
Test
Simulate #正确弹出即可
编译unitree_mujoco时出现,cannot find -lddsc&ddscxx #19
#查找libddscxx.so
locate libddscxx.so
#将libddscxx.so的位置链接到/usr/local/lib/libddscxx.so
sudo ln -s /home/liu/unitree_sdk2-main/thirdparty/lib/x86_64/libddscxx.so /usr/local/lib/libddscxx.so
locate libddsc.so
sudo ln -s /home/liu/unitree_sdk2-main/thirdparty/lib/x86_64/libddsc.so /usr/local/lib/libddsc.so