mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-22 14:19:57 +08:00
feat(sitl): select uXRCE-DDS or Zenoh at runtime
SITL users who want Zenoh had to build the separate px4_sitl_zenoh target, so the prebuilt packages and containers could only talk uXRCE-DDS. Build both clients into the SITL default board (and thereby SIH) and pick one at startup instead. PX4_ROS2_MIDDLEWARE=uxrce_dds|zenoh|none selects the middleware and is stored in ZENOH_ENABLE, so without the variable the persisted parameter decides; uXRCE-DDS stays the default. rcS keeps only this selection and sources px4-rc.uxrce_dds or px4-rc.zenoh for the client startup. The Zenoh one maps ROS_DOMAIN_ID to ZENOH_DOMAIN_ID and applies PX4_ZENOH_LOCATOR, when set, as the router address. The container entrypoint follows the uXRCE-DDS start command into its new file so Docker Desktop keeps routing DDS to the host. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Beniamino Pozzan <beniamino.pozzan@gmail.com>
This commit is contained in:
1 parent
e66b9ea7ea
commit
97edba71fd
7 files changed
+86
-37
No files matched your search
@@ -40,6 +40,8 @@ px4_add_romfs_files(
|
||||
px4-rc.mavlinksim
|
||||
px4-rc.sihsim
|
||||
px4-rc.rotorpy
|
||||
px4-rc.uxrce_dds
|
||||
px4-rc.zenoh
|
||||
rc.replay
|
||||
rcS
|
||||
)
|
||||
@@ -0,0 +1,35 @@
|
||||
#!/bin/sh
|
||||
# shellcheck disable=SC2154
|
||||
|
||||
# Start the uXRCE-DDS client with UDP transport (sourced by rcS when selected)
|
||||
uxrce_dds_ns=""
|
||||
if [ "$px4_instance" -ne "0" ]
|
||||
then
|
||||
# for multi instances setup, add namespace prefix
|
||||
uxrce_dds_ns="-n uav_$px4_instance"
|
||||
fi
|
||||
if [ "${PX4_UXRCE_DDS_NS+x}" ]; then
|
||||
# Override, as variable is set (empty or not)
|
||||
if [ -n "$PX4_UXRCE_DDS_NS" ]; then
|
||||
# Override namespace if environment variable is non-empty
|
||||
uxrce_dds_ns="-n $PX4_UXRCE_DDS_NS"
|
||||
else
|
||||
# Clear namespace if variable is empty
|
||||
uxrce_dds_ns=""
|
||||
fi
|
||||
fi
|
||||
if [ -n "$ROS_DOMAIN_ID" ]
|
||||
then
|
||||
# Match UXRCE_DDS_DOM_ID with ROS_DOMAIN_ID, if defined
|
||||
param set UXRCE_DDS_DOM_ID $ROS_DOMAIN_ID
|
||||
else
|
||||
param set UXRCE_DDS_DOM_ID 0
|
||||
fi
|
||||
uxrce_dds_port=8888
|
||||
if [ -n "$PX4_UXRCE_DDS_PORT" ]
|
||||
then
|
||||
# Override port if environment variable is defined
|
||||
uxrce_dds_port="$PX4_UXRCE_DDS_PORT"
|
||||
fi
|
||||
|
||||
uxrce_dds_client start -t udp -p $uxrce_dds_port $uxrce_dds_ns
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
# shellcheck disable=SC2154
|
||||
|
||||
# Start the Zenoh client (sourced by rcS when selected)
|
||||
if [ -n "$ROS_DOMAIN_ID" ]
|
||||
then
|
||||
# Match ZENOH_DOMAIN_ID with ROS_DOMAIN_ID, if defined
|
||||
param set ZENOH_DOMAIN_ID $ROS_DOMAIN_ID
|
||||
else
|
||||
param set ZENOH_DOMAIN_ID 0
|
||||
fi
|
||||
if [ -n "$PX4_ZENOH_LOCATOR" ]
|
||||
then
|
||||
# Connect to the Zenoh router at this locator, e.g. tcp/192.168.1.5:7447
|
||||
zenoh config net client "$PX4_ZENOH_LOCATOR"
|
||||
fi
|
||||
zenoh start
|
||||
@@ -294,43 +294,38 @@ fi
|
||||
|
||||
navigator start
|
||||
|
||||
# Try to start the UXRCE-DDS Client with UDP transport if module exists
|
||||
uxrce_dds_ns=""
|
||||
if [ "$px4_instance" -ne "0" ]
|
||||
then
|
||||
# for multi instances setup, add namespace prefix
|
||||
uxrce_dds_ns="-n uav_$px4_instance"
|
||||
fi
|
||||
if [ "${PX4_UXRCE_DDS_NS+x}" ]; then
|
||||
# Override, as variable is set (empty or not)
|
||||
if [ -n "$PX4_UXRCE_DDS_NS" ]; then
|
||||
# Override namespace if environment variable is non-empty
|
||||
uxrce_dds_ns="-n $PX4_UXRCE_DDS_NS"
|
||||
else
|
||||
# Clear namespace if variable is empty
|
||||
uxrce_dds_ns=""
|
||||
fi
|
||||
fi
|
||||
if [ -n "$ROS_DOMAIN_ID" ]
|
||||
then
|
||||
# Match UXRCE_DDS_DOM_ID with ROS_DOMAIN_ID, if defined
|
||||
param set UXRCE_DDS_DOM_ID $ROS_DOMAIN_ID
|
||||
else
|
||||
param set UXRCE_DDS_DOM_ID 0
|
||||
fi
|
||||
uxrce_dds_port=8888
|
||||
if [ -n "$PX4_UXRCE_DDS_PORT" ]
|
||||
then
|
||||
# Override port if environment variable is defined
|
||||
uxrce_dds_port="$PX4_UXRCE_DDS_PORT"
|
||||
fi
|
||||
|
||||
uxrce_dds_client start -t udp -p $uxrce_dds_port $uxrce_dds_ns
|
||||
|
||||
# ROS 2 middleware: PX4_ROS2_MIDDLEWARE (uxrce_dds, zenoh or none) overrides
|
||||
# ZENOH_ENABLE. uXRCE-DDS runs unless Zenoh is enabled or none is selected.
|
||||
ros2_middleware=uxrce_dds
|
||||
case "$PX4_ROS2_MIDDLEWARE" in
|
||||
"")
|
||||
;;
|
||||
uxrce_dds)
|
||||
param set ZENOH_ENABLE 0
|
||||
;;
|
||||
zenoh)
|
||||
param set ZENOH_ENABLE 1
|
||||
;;
|
||||
none)
|
||||
param set ZENOH_ENABLE 0
|
||||
ros2_middleware=none
|
||||
;;
|
||||
*)
|
||||
echo "WARN [init] Unknown PX4_ROS2_MIDDLEWARE '$PX4_ROS2_MIDDLEWARE', expected uxrce_dds, zenoh or none"
|
||||
;;
|
||||
esac
|
||||
if param greater -s ZENOH_ENABLE 0
|
||||
then
|
||||
zenoh start
|
||||
ros2_middleware=zenoh
|
||||
fi
|
||||
case "$ros2_middleware" in
|
||||
uxrce_dds)
|
||||
. px4-rc.uxrce_dds
|
||||
;;
|
||||
zenoh)
|
||||
. px4-rc.zenoh
|
||||
;;
|
||||
esac
|
||||
|
||||
if param greater -s MNT_MODE_IN -1
|
||||
then
|
||||
|
||||
@@ -15,7 +15,7 @@ set -e
|
||||
if [ -n "$DOCKER_HOST_IP" ]; then
|
||||
# Runtime-only images expect the DDS Agent on the host.
|
||||
sed -i -E "s/(uxrce_dds_client start -t udp)( -h [^ ]+)?/\1 -h $DOCKER_HOST_IP/g" \
|
||||
"$PX4_PREFIX/etc/init.d-posix/rcS"
|
||||
"$PX4_PREFIX/etc/init.d-posix/px4-rc.uxrce_dds"
|
||||
fi
|
||||
|
||||
exec "$PX4_PREFIX/bin/px4" "$@"
|
||||
@@ -66,6 +66,8 @@ CONFIG_MODULES_UUV_POS_CONTROL=y
|
||||
CONFIG_MODULES_UXRCE_DDS_CLIENT=y
|
||||
CONFIG_MODULES_VISION_TARGET_ESTIMATOR=y
|
||||
CONFIG_MODULES_VTOL_ATT_CONTROL=y
|
||||
CONFIG_MODULES_ZENOH=y
|
||||
CONFIG_ZENOH_PUB_OPTION_OVERRIDE=y
|
||||
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
|
||||
CONFIG_SYSTEMCMDS_BSONDUMP=y
|
||||
CONFIG_SYSTEMCMDS_DYN=y
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
CONFIG_MODULES_UXRCE_DDS_CLIENT=n
|
||||
CONFIG_MODULES_ZENOH=y
|
||||
CONFIG_ZENOH_PUB_OPTION_OVERRIDE=y
|
||||
Reference in new issue
Block a user