38 lines
1.7 KiB
Bash
Executable File
38 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# One explicit discovery policy for the station and every child launch.
|
|
# The inherited generic ROS_DOMAIN_ID is never silently adopted.
|
|
ROS_SIM_DOMAIN=77
|
|
|
|
ros_domain_force_real() {
|
|
local runtime_file requested_domain requested_localhost previous_domain
|
|
runtime_file="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)/config/ros_runtime.env"
|
|
requested_domain="${REAL_ROS_DOMAIN_ID:-}"
|
|
requested_localhost="${REAL_ROS_LOCALHOST_ONLY:-}"
|
|
if [[ -f "${runtime_file}" ]]; then
|
|
source "${runtime_file}"
|
|
fi
|
|
requested_domain="${requested_domain:-${ORISYS_ROS_DOMAIN_ID:-42}}"
|
|
requested_localhost="${requested_localhost:-${ORISYS_ROS_LOCALHOST_ONLY:-1}}"
|
|
if [[ ! "${requested_domain}" =~ ^[0-9]+$ ]] || (( 10#${requested_domain} > 232 )); then
|
|
echo "[domain] ERROR: ROS domain must be an integer in 0..232" >&2
|
|
return 2
|
|
fi
|
|
if [[ "${requested_localhost}" != 0 && "${requested_localhost}" != 1 ]]; then
|
|
echo "[domain] ERROR: REAL_ROS_LOCALHOST_ONLY must be 0 or 1" >&2
|
|
return 2
|
|
fi
|
|
if (( 10#${requested_domain} == ROS_SIM_DOMAIN )); then
|
|
echo "[domain] ERROR: domain 77 is reserved for simulation" >&2
|
|
return 2
|
|
fi
|
|
previous_domain="${ROS_DOMAIN_ID:-unset}"
|
|
export ROS_DOMAIN_ID="$((10#${requested_domain}))"
|
|
export ROS_LOCALHOST_ONLY="${requested_localhost}"
|
|
# All nested launch scripts inherit exactly the same selection.
|
|
export REAL_ROS_DOMAIN_ID="${ROS_DOMAIN_ID}"
|
|
export REAL_ROS_LOCALHOST_ONLY="${ROS_LOCALHOST_ONLY}"
|
|
if [[ "${previous_domain}" != "${ROS_DOMAIN_ID}" ]]; then
|
|
echo "[domain] orisys_arm: ${previous_domain} -> ${ROS_DOMAIN_ID}; localhost_only=${ROS_LOCALHOST_ONLY}" >&2
|
|
fi
|
|
}
|