#!/usr/bin/env bash # Source this file; do not execute it. UNITREE_ROS2_ROOT selects the built # Unitree ROS 2 workspace; DDS interface selection stays local to this project. if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then echo "Use: source scripts/source_unitree_env.sh " >&2 exit 2 fi _h2_interface="${1:-}" if [[ -z "${_h2_interface}" ]]; then echo "Missing robot network interface." >&2 echo "Use: source scripts/source_unitree_env.sh enp4s0f0" >&2 return 2 fi if [[ ! -d "/sys/class/net/${_h2_interface}" ]]; then echo "Network interface does not exist: ${_h2_interface}" >&2 return 2 fi if [[ "$(cat "/sys/class/net/${_h2_interface}/operstate")" != "up" ]]; then echo "Network interface is not up: ${_h2_interface}" >&2 return 2 fi _h2_unitree_setup="${UNITREE_ROS2_ROOT:-$HOME/unitree_ros2}/install/setup.bash" if [[ ! -f "$_h2_unitree_setup" ]]; then echo "Missing Unitree ROS 2 setup: $_h2_unitree_setup; set UNITREE_ROS2_ROOT to your built workspace." >&2 return 2 fi source /opt/ros/humble/setup.bash || return $? source "$_h2_unitree_setup" || return $? export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp export ROS_DOMAIN_ID=0 export ROS_LOCALHOST_ONLY=0 export CYCLONEDDS_URI="" unset _h2_interface _h2_unitree_setup echo "H2 Unitree ROS 2 environment loaded (CycloneDDS interface: $1)."