2024-09-24 19:48:14 +08:00
# OCS2 Quadruped Controller
2024-09-26 22:18:11 +08:00
This is a ros2-control controller based on [legged_control ](https://github.com/qiayuanl/legged_control )
and [ocs2_ros2 ](https://github.com/legubiao/ocs2_ros2 ).
2024-09-24 21:50:46 +08:00
2024-10-03 20:51:33 +08:00
Tested environment:
2024-10-18 11:47:31 +08:00
2024-10-03 20:51:33 +08:00
* Ubuntu 24.04
2024-10-18 11:47:31 +08:00
* ROS2 Jazzy
2024-10-18 22:22:07 +08:00
* Ubuntu 22.04
* ROS2 Humble
2024-10-03 20:51:33 +08:00
2025-03-15 19:42:35 +08:00
* [x] ** [2025-01-16]** Add support for ground truth estimator.
* [x] ** [2025-03-15]** OCS2 Controller now can switch between passive and MPC mode.
2025-01-16 16:56:04 +08:00
2024-10-01 19:10:23 +08:00
[](https://www.bilibili.com/video/BV1UcxieuEmH/)
2024-10-03 20:51:33 +08:00
## 1. Interfaces
Required hardware interfaces:
* command:
2024-10-18 11:47:31 +08:00
* joint position
* joint velocity
* joint effort
* KP
* KD
2024-10-03 20:51:33 +08:00
* state:
2024-10-18 11:47:31 +08:00
* joint effort
* joint position
* joint velocity
* imu sensor
* linear acceleration
* angular velocity
* orientation
* feet force sensor
2024-10-03 20:51:33 +08:00
2024-09-24 19:48:14 +08:00
## 2. Build
2024-09-26 22:18:11 +08:00
### 2.1 Build Dependencies
2025-02-23 22:07:46 +08:00
Before install OCS2 ROS2, please follow the guide to install [Pinocchio ](https://stack-of-tasks.github.io/pinocchio/download.html ). **Don't use the pinocchio install by rosdep** !
2024-09-26 22:18:11 +08:00
2025-02-23 22:07:46 +08:00
**After installed Pinocchio**, follow below step to clone ocs2 ros2 library to src folder.
```bash
cd ~/ros2_ws/src
git clone https://github.com/legubiao/ocs2_ros2
cd ocs2_ros2
git submodule update --init --recursive
cd ..
rosdep install --from-paths src --ignore-src -r -y
```
2024-09-26 22:18:11 +08:00
### 2.2 Build OCS2 Quadruped Controller
2024-09-24 19:48:14 +08:00
```bash
cd ~/ros2_ws
2025-02-23 22:07:46 +08:00
colcon build --packages-up-to ocs2_quadruped_controller --symlink-install
2024-09-26 22:18:11 +08:00
```
## 3. Launch
2024-10-18 11:47:31 +08:00
supported robot description:
* Unitree
* go2_description
* go1_description
* a1_description
* aliengo_description
* b2_description
* Xiaomi
* cyberdog_description
2024-11-06 20:07:48 +08:00
* DeepRobotics
* lite3_description
* x30_description
* Anybotics
* anymal_c_description
2024-10-18 11:47:31 +08:00
2025-03-15 23:21:53 +08:00
### 3.1 About OCS2 Shared Library
OCS2 Quadruped controller depends on the OCS2 library, it required c++ automatic differentiation shared library. When first launch the controller, it will compile the OCS2 model and generate the shared library.
You may see something similar to:
```
[gazebo-5] [CppAdInterface] Compiling Shared Library: /home/biao/ocs2_cpp_ad/b2/RR_foot_position/cppad_generated/RR_foot_position_libcppadcg_tmp-27918274.so
[gazebo-5] [CppAdInterface] Renaming /home/biao/ocs2_cpp_ad/b2/RR_foot_position/cppad_generated/RR_foot_position_libcppadcg_tmp-27918274.so to /home/biao/ocs2_cpp_ad/b2/RR_foot_position/cppad_generated/RR_foot_position_lib.so
[gazebo-5] [CppAdInterface] Compiling Shared Library: /home/biao/ocs2_cpp_ad/b2/RR_foot_velocity/cppad_generated/RR_foot_velocity_libcppadcg_tmp-94918274.so
[gazebo-5] [CppAdInterface] Renaming /home/biao/ocs2_cpp_ad/b2/RR_foot_velocity/cppad_generated/RR_foot_velocity_libcppadcg_tmp-94918274.so to /home/biao/ocs2_cpp_ad/b2/RR_foot_velocity/cppad_generated/RR_foot_velocity_lib.so
[gazebo-5] [CppAdInterface] Compiling Shared Library: /home/biao/ocs2_cpp_ad/b2/RR_foot_orientation/cppad_generated/RR_foot_orientation_libcppadcg_tmp-83618274.so
[gazebo-5] [CppAdInterface] Renaming /home/biao/ocs2_cpp_ad/b2/RR_foot_orientation/cppad_generated/RR_foot_orientation_libcppadcg_tmp-83618274.so to /home/biao/ocs2_cpp_ad/b2/RR_foot_orientation/cppad_generated/RR_foot_orientation_lib.so
```
The compilation process may take a few minutes. After the compilation, restart the controller and the robot should stand up.
To config the path for the cppAD shared library, you can modify the `modelFolderCppAd` item in `task.info` file, which located at the `config/ocs2` folder under robot description package. If the path is not start with `/` , it will be considered as **relative path to the Linux Home folder** .
### 3.2 Usage
#### Keyboard State Switch
* Keyboard 1 : Passive Mode
* Keyboard 2 : OCS2 MPC Mode
* Keyboard 2: stance
* Keyboard 3: trot
* Keyboard 4: standing_trot
* Keyboard 5: flying_trot
### 3.3 Launch Controller
#### Mujoco Simulation
2024-11-06 20:07:48 +08:00
> **Warm Reminder**: You need to launch [Unitree Mujoco C++ Simulation](https://github.com/legubiao/unitree_mujoco) before launch the controller.
2024-10-18 11:47:31 +08:00
```bash
source ~/ros2_ws/install/setup.bash
ros2 launch ocs2_quadruped_controller mujoco.launch.py pkg_description:=go2_description
2024-11-06 20:07:48 +08:00
```
2025-03-15 23:21:53 +08:00
#### Gazebo Launch
2025-02-26 12:48:19 +08:00
```bash
source ~/ros2_ws/install/setup.bash
ros2 launch ocs2_quadruped_controller gazebo.launch.py pkg_description:=go2_description
2025-03-15 23:21:53 +08:00
```