This repo uses unitree_ros2 from unitree. It's just adding some new messages and a complete robot_hal script to talk with the robot, compatible with some dls controllers.
The main dependencies other ros-humble are
ros-humble-rmw-cyclonedds-cpp
ros-humble-rosidl-generator-dds-idlAn example of conda environment containing these dependencies can be found in the folder installation.
First, compile unitree stuff:
git submodule update --init --recursive
cd unitree_ros2/cyclonedds_ws
colcon build # Compile all packages in the workspace
source install/setup.bashConnect Unitree robot and the computer using Ethernet cable. Then, use ifconfig to view the network interface that the robot connected.
Next, open the network settings, find the network interface that the robot connected.In IPv4 setting, change the IPv4 mode to manual, set the address to 192.168.123.99, and set the mask to 255.255.255.0. After completion, click apply and wait for the network to reconnect.
Open setup.sh file.
sudo gedit setup.bash#!/bin/bash
.......
export CYCLONEDDS_URI='<CycloneDDS><Domain><General><Interfaces>
<NetworkInterface name="enp3s0" priority="default" multicast="default" />
</Interfaces></General></Domain></CycloneDDS>'where "enp3s0" is the network interface name of unitree robot connected. Modify it to the corresponding network interface according to the actual situation.
Source the environment to setup the ROS2 support of Unitree robot:
source setup.bashIf your computer is not connected to the robot but you still want to use Unitree ROS2 for simulation and other functions, you can use the local loopback "lo" as the network interface.
source setup_local.bash # use "lo" as the network interfaceAfter completing the above configuration, it is recommended to restart the computer before conducting the test.
Ensure that the network of robot is connected correctly, open a terminal and input:
source setup.bash
ros2 topic listIf you have any problem in seeing, listening the topic, maybe it's the firewall.
The firewall gives us problem!!
sudo ufw disableor
sudo ufw allow from 192.168.123.18 to any port 7400:65535 proto udp
sudo ufw allow from 192.168.123.161 to any port 7400:65535 proto udpThe source code of the hal is located at /hal/src/hal.
Open a terminal and input:
source setup.bash
cd hal
colcon build --packages-select dls2_msgs
source install/setup.bash
colcon build --packages-select halAfter compilation, run in the terminal:
./install/hal/bin/robot_hal You can even use
python3 launch_hal.py