Skip to content

abizovnuralem/go2_ros2_sdk

Repository files navigation

Ros2 SDK

Welcome to the Unitree Go2 ROS2 SDK Project!

IsaacSim Python Linux platform Windows platform ROS2 Build License

We are happy to present you our integration of the Unitree Go2 with ROS2 over Wi-Fi, that was designed by the talented @tfoldi. You can explore his groundbreaking work at go2-webrtc.

This repo will empower your Unitree GO2 AIR/PRO/EDU robots with ROS2 capabilities, using both WebRTC (Wi-Fi) and CycloneDDS (Ethernet) protocols.

Project RoadMap:

  1. URDF ✅
  2. Joint states sync in real time ✅
  3. IMU sync in real time ✅
  4. Joystick control in real time ✅
  5. Go2 topics info in real time ✅
  6. Foot force sensors info in real time ✅
  7. Lidar stream (added pointCloud2) ✅
  8. Camera stream ✅
  9. Foxglove bridge ✅
  10. Laser Scan ✅
  11. Multi robot support ✅
  12. WebRTC and CycloneDDS support ✅
  13. Creating a PointCloud map and store it ✅
  14. SLAM (slam_toolbox) (in the current version is not working, need to fix params)
  15. Navigation (nav2) (in the current version is not working, need to fix params)
  16. Object detection ✅
  17. AutoPilot

Your feedback and support mean the world to us.

If you're as enthusiastic about this project as we are, please consider giving it a ⭐ star!!!

Your encouragement fuels our passion and helps us develop our RoadMap further. We welcome any help or suggestions you can offer!

Together, let's push the boundaries of what's possible with the Unitree Go2 and ROS2!

Exciting Features:

✨ Full ROS2 SDK support for your Unitree GO2

🤖 Compatible with AIR, PRO, and EDU variants

👣 Access to foot force sensors feedback (available on some GO2 PRO models or EDU)

Real time Go2 Air/PRO/EDU joints sync:

Go2 joints sync

Go2 Air/PRO/EDU lidar point cloud:

Go2 point cloud

System requirements

Tested systems and ROS2 distro

systems ROS2 distro Build status
Ubuntu 22.04 iron ROS2 CI
Ubuntu 22.04 humble ROS2 CI
Ubuntu 22.04 rolling ROS2 CI

Installation

mkdir -p ros2_ws/src
cd ros2_ws/src
git clone --recurse-submodules https://github.com/abizovnuralem/go2_ros2_sdk.git
cp -a go2_ros2_sdk/. .
rm -r -f go2_ros2_sdk
sudo apt install ros-humble-image-tools
sudo apt install ros-humble-vision-msgs
sudo apt install python3-pip clang
pip install -r requirements.txt
cd ..

NOTE 1: check for any error messages, and do not disregard them. If pip install does not complete cleanly, various features will not work. For example, open3d does not yet support python3.12 and therefore you will need to set up a 3.11 venv first etc.

NOTE 2: for real time object detection and tracking, please install PyTorch.

Install rust language support in your system: instructions

cargo should work in terminal

cargo --version

Build go2_ros_sdk. You need to have ros2 and rosdep installed. If you do not: instructions. Then:

source /opt/ros/$ROS_DISTRO/setup.bash
rosdep install --from-paths src --ignore-src -r -y
colcon build

Usage

Don't forget to set up your Go2 robot in Wifi-mode and obtain the IP. You can use the mobile app to get it, go to Device -> Data -> Automatic Machine Inspection and look for STA Network: wlan0.

source install/setup.bash
export ROBOT_IP="robot_ip"
export CONN_TYPE="webrtc"
ros2 launch go2_robot_sdk robot.launch.py

Real time image detection and tracking

Giraffe Detection and Tracking

This capability is directly based on J. Francis's work. Once you have launched the sdk, the color image data will be available at go2_camera/color/image. In another terminal enter:

source install/setup.bash
ros2 run coco_detector coco_detector_node

There will be a short delay the first time the node is run for PyTorch TorchVision to download the neural network. You should see a downloading progress bar. This network is then cached for subsequent runs.

On another terminal, to view the detection messages:

source install/setup.bash
ros2 topic echo /detected_objects

The detection messages contain the detected object (class_id) and the score, a number from 0 to 1. For example: detections:results:hypothesis:class_id: giraffe and detections:results:hypothesis:score: 0.9989. The bbox:center:x and bbox:center:y contain the centroid of the object in pixels. These data can be used to implement real-time object following for animals and people. People are detected as detections:results:hypothesis:class_id: person.

To view the image stream annotated with the labels and bounding boxes:

source install/setup.bash
ros2 run image_tools showimage --ros-args -r /image:=/annotated_image

Example Use:

ros2 run coco_detector coco_detector_node --ros-args -p publish_annotated_image:=False -p device:=cuda -p detection_threshold:=0.7

This will run the coco detector without publishing the annotated image (it is True by default) using the default CUDA device (device=cpu by default). It sets the detection_threshold to 0.7 (it is 0.9 by default). The detection_threshold should be between 0.0 and 1.0; the higher this number the more detections will be rejected. If you have too many false detections try increasing this number. Thus only Detection2DArray messages are published on topic /detected_objects.

3D map generation

To save the map, you need to:

export MAP_SAVE=True
export MAP_NAME="3d_map"

Every 10 seconds, the map will be save to root folder of the repo.

Multi robot support

If you want to connect several robots for collaboration:

export ROBOT_IP="robot_ip_1, robot_ip_2, robot_ip_N"

Switching between webrtc connection (Wi-Fi) to CycloneDDS (Ethernet)

export CONN_TYPE="webrtc"

or

export CONN_TYPE="cyclonedds"

Foxglove

Foxglove bridge

To use Foxglove, you need to install Foxglove Studio:

sudo snap install foxglove-studio
  1. Open Foxglove Studio and press "Open Connection".
  2. In the "Open Connection" settings, choose "Foxglove WebSocket" and use the default configuration ws:https://localhost:8765, then press "Open".

WSL 2

If you are running ROS2 under WSL2 - you may need to configure Joystick\Gamepad to navigate the robot.

  1. Step 1 - share device with WSL2

    Follow steps here https://learn.microsoft.com/en-us/windows/wsl/connect-usb to share your console device with WSL2

  2. Step 2 - Enable WSL2 joystick drivers

    WSL2 does not come by default with the modules for joysticks. Build WSL2 Kernel with the joystick drivers. Follow the instructions here: https://github.com/dorssel/usbipd-win/wiki/WSL-support#building-your-own-wsl-2-kernel-with-additional-drivers If you're comfortable with WSl2, skip the export steps and start at Install prerequisites.

    Before buiding, edit .config file and update the CONFIG_ values listed in this GitHub issue: microsoft/WSL#7747 (comment)

  3. Step 3 - Give permissions to /dev/input devices

    Once you've finished the guides under Step 3 - you should be able to see your joystick device under /dev/input

    ls /dev/input
    by-id  by-path  event0  js0

    By default /dev/input/event* will only have root permissions, so joy node won't have access to the joystick

    Create a file /etc/udev/rules.d/99-userdev-input.rules with the following content: KERNEL=="event*", SUBSYSTEM=="input", RUN+="/usr/bin/setfacl -m u:YOURUSERNAME:rw $env{DEVNAME}"

    Run as root: udevadm control --reload-rules && udevadm trigger

    https://askubuntu.com/a/609678

  4. Step 3 - verify that joy node is able to see the device properly.

    Run ros2 run joy joy_enumerate_devices

    ID : GUID                             : GamePad : Mapped : Joystick Device Name
    -------------------------------------------------------------------------------
    0 : 030000005e040000120b000007050000 :    true :  false : Xbox Series X Controller
    

Thanks

Special thanks to @tfoldi, @legion1581, @budavariam, @alex.lin and TheRoboVerse community!

License

This project is licensed under the BSD 2-clause License - see the LICENSE file for details.