File size: 1,509 Bytes
d8290eb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #!/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 <robot-network-interface>" >&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="<CycloneDDS><Domain><General><Interfaces><NetworkInterface name='${_h2_interface}' priority='default' multicast='default'/></Interfaces></General></Domain></CycloneDDS>"
unset _h2_interface _h2_unitree_setup
echo "H2 Unitree ROS 2 environment loaded (CycloneDDS interface: $1)."
|