Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update integration with external mujoco library #2

Merged
merged 9 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build/
Lingo.lock
bin
src-gen
Expand Down
32 changes: 26 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,47 @@ The derived reactors customize this base class for particular MuJoCo model files

## Prerequisites

MuJoCo depends on [GLFW](https://www.glfw.org), a graphics library that you must install. On macOS:
### Linux (Ubuntu)

1. Install GLFW, a graphics library used by MuJoCo

```sh
apt install libglfw3-dev
```

2. Download a prebuilt version of Mujoco v3.2.6 and install it to `/opt/mujoco`. The following works for x86, for aarch64, change the download path accordingly (https://github.com/google-deepmind/mujoco/releases/tag/3.2.6)
```sh
wget https://github.com/google-deepmind/mujoco/releases/download/3.2.6/mujoco-3.2.6-linux-x86_64.tar.gz
tar xvf mujoco-*
sudo mv mujoco-3.2.6 /opt/mujoco
```

Alternatively, Mujoco can be built from source as explained under the section for MacOS below.

### macOS
1. Install GLFW, a graphics library used by MuJoCo

```sh
brew install glfw
```

MuJoCo itself seems to be best installed from source. The following worked for me on macOS:
2. Build Mujoco v3.2.6 from source and install to `/opt/mujoco`

```sh
git clone git@github.com:google-deepmind/mujoco.git
git clone https://github.com/google-deepmind/mujoco.git -b 3.2.6
cd mujoco
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/mujoco
cmake --build .
sudo cmake --install .

```

The `sudo` on the last line is required to install it in `/usr/local`, which is what I did.
### All platforms

The [mujoco.cmake](src/include/mujoco.cmake) file will need to be changed if you change either of the above install locations.
If mujoco is installed to a different location the
[mujoco.cmake](src/include/mujoco.cmake) must be updated accordingly.

## Demos

Expand Down
2 changes: 1 addition & 1 deletion src/MuJoCoCarDemo.lf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ target C {
keepalive: true, // Because of physical action.
}

import MuJoCoCar from "lib/MujocoCar.lf"
import MuJoCoCar from "lib/MuJoCoCar.lf"

main reactor(period: time = 33333333 ns, speed_sensitivity: double = 0.05, turn_sensitivity: double = 0.01) {
timer t(0, period)
Expand Down
17 changes: 10 additions & 7 deletions src/include/mujoco.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# For Mujoco
list(APPEND CMAKE_PREFIX_PATH "/usr/local/")
find_package(mujoco REQUIRED)
target_include_directories(${LF_MAIN_TARGET} PUBLIC /usr/local/include)
target_link_libraries(${LF_MAIN_TARGET} PUBLIC mujoco::mujoco)
# If mujoco is installed to a different location, then the following variable
# should be set to the correct path. See README.md
set(MUJOCO_PATH "/opt/mujoco")
list(APPEND CMAKE_PREFIX_PATH ${MUJOCO_PATH})
find_library(MUJOCO_LIB mujoco REQUIRED)
erlingrj marked this conversation as resolved.
Show resolved Hide resolved
find_path(MUJOCO_INCLUDE_PATH mujoco REQUIRED)
target_include_directories(${LF_MAIN_TARGET} PUBLIC ${MUJOCO_INCLUDE_PATH})
target_link_libraries(${LF_MAIN_TARGET} PUBLIC ${MUJOCO_LIB})

# For GLFW
list(APPEND CMAKE_PREFIX_PATH "/opt/homebrew/")
find_package(glfw3 3.4 REQUIRED)
target_include_directories(${LF_MAIN_TARGET} PUBLIC /opt/homebrew/include)
find_package(glfw3 REQUIRED)
target_include_directories(${LF_MAIN_TARGET} PUBLIC ${glfw3_INCLUDE_DIRS})
erlingrj marked this conversation as resolved.
Show resolved Hide resolved
target_link_libraries(${LF_MAIN_TARGET} PUBLIC glfw)
2 changes: 1 addition & 1 deletion src/lib/MuJoCoCar.lf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ target C {
files: "../models/car.xml"
}

import MuJoCoBase from "MujocoBase.lf"
import MuJoCoBase from "MuJoCoBase.lf"

/**
* @brief Model of a two-wheeled steerable vehicle.
Expand Down