From 885be7e06eba4c5e5775c7997e16efb9715f3a9c Mon Sep 17 00:00:00 2001 From: dominikn Date: Fri, 14 Jun 2024 10:54:44 +0000 Subject: [PATCH] fix urdfs --- snap/hooks/configure | 75 ++++++++------------- snap/local/ros_common/configure_hook_ros.sh | 6 ++ snap/local/ros_common/utils.sh | 2 +- snap/snapcraft.yaml | 6 +- 4 files changed, 37 insertions(+), 52 deletions(-) diff --git a/snap/hooks/configure b/snap/hooks/configure index 739550d..245c04e 100644 --- a/snap/hooks/configure +++ b/snap/hooks/configure @@ -9,61 +9,40 @@ source $SNAP/usr/bin/utils.sh $SNAP/usr/bin/configure_hook_ros.sh -# Check and validate the camera model -OPT="camera-model" -VALUE="$(snapctl get driver.${OPT})" +# Function to validate the option values +validate_option() { + local OPT=$1 + local VALID_OPTIONS=("${!2}") -# Define the valid options for camera model -VALID_CAMERA_OPTIONS=("None" "intel_realsense_d435" "orbbec_astra" "stereolabs_zed" "stereolabs_zedm" "stereolabs_zed2" "stereolabs_zed2i" "stereolabs_zedx" "stereolabs_zedxm") - -# Join the valid camera options with newlines -JOINED_CAMERA_OPTIONS=$(printf "%s\n" "${VALID_CAMERA_OPTIONS[@]}") - -if [ -n "${VALUE}" ]; then - case "${VALUE}" in - "${VALID_CAMERA_OPTIONS[@]}") ;; - *) - log_and_echo "'${VALUE}' is not a supported value for '${OPT}'. Possible values are:\n${JOINED_CAMERA_OPTIONS}" - exit 1 - ;; - esac -fi - -# Make sure correct the camera-model is selected -OPT="lidar-model" -VALUE="$(snapctl get driver.${OPT})" - -# Define the valid options as an array -VALID_OPTIONS=("None" "slamtec_rplidar_a2" "slamtec_rplidar_a3" "slamtec_rplidar_s1" "slamtec_rplidar_s2" "slamtec_rplidar_s3" "velodyne_puck") + VALUE="$(snapctl get driver.${OPT})" -# Join the valid options with a semicolon and space -JOINED_OPTIONS=$(printf "%s\n" "${VALID_OPTIONS[@]}") + # Create an associative array to check valid options + declare -A valid_options_map + for option in "${VALID_OPTIONS[@]}"; do + valid_options_map["$option"]=1 + done -if [ -n "${VALUE}" ]; then - case "${VALUE}" in - "${VALID_OPTIONS[@]}") ;; - *) - log_and_echo "'${VALUE}' is not a supported value for '${OPT}'. Possible values are:\n${JOINED_OPTIONS[*]}" - exit 1 - ;; - esac -fi + # Join the valid options with newlines + JOINED_OPTIONS=$(printf "%s\n" "${VALID_OPTIONS[@]}") -# Make sure ROS 2 nodes parameters value is a boolean -OPTS="mecanum include-camera-mount" -for OPT in ${OPTS}; do - VALUE="$(snapctl get driver.${OPT})" if [ -n "${VALUE}" ]; then - case "${VALUE}" in - "True") ;; - "False") ;; - *) - log_and_echo "configure hook: '${VALUE}' is not a supported value for ${OPT}. Possible values are True or False." + if [[ -z "${valid_options_map[$VALUE]}" ]]; then + log_and_echo "'${VALUE}' is not a supported value for '${OPT}'. Possible values are:\n${JOINED_OPTIONS}" exit 1 - ;; - esac + fi fi -done +} + +# Define the valid options for camera model and lidar model +VALID_CAMERA_OPTIONS=("None" "intel_realsense_d435" "orbbec_astra" "stereolabs_zed" "stereolabs_zedm" "stereolabs_zed2" "stereolabs_zed2i" "stereolabs_zedx" "stereolabs_zedxm") +VALID_LIDAR_OPTIONS=("None" "slamtec_rplidar_a2" "slamtec_rplidar_a3" "slamtec_rplidar_s1" "slamtec_rplidar_s2" "slamtec_rplidar_s3" "velodyne_puck") +VALID_BOOLEAN_OPTIONS=("True" "False") + +# Validate parameters with array of possible values +validate_option "camera-model" VALID_CAMERA_OPTIONS[@] +validate_option "lidar-model" VALID_LIDAR_OPTIONS[@] +validate_option "mecanum" VALID_BOOLEAN_OPTIONS[@] +validate_option "include-camera-mount" VALID_BOOLEAN_OPTIONS[@] # Make sure the serial-port value is valid OPT="serial-port" diff --git a/snap/local/ros_common/configure_hook_ros.sh b/snap/local/ros_common/configure_hook_ros.sh index b24de38..158e0d7 100755 --- a/snap/local/ros_common/configure_hook_ros.sh +++ b/snap/local/ros_common/configure_hook_ros.sh @@ -72,6 +72,12 @@ fi OPT="transport" TRANSPORT_SETTING="$(snapctl get ${OPT})" +# Check if TRANSPORT_SETTING is "builtin" +if [ "$TRANSPORT_SETTING" == "builtin" ]; then + # Change the value to "rmw_fastrtps_cpp" + TRANSPORT_SETTING="rmw_fastrtps_cpp" +fi + # Only exit with status 1 if conditions are not met if [ "$TRANSPORT_SETTING" != "rmw_fastrtps_cpp" ] && [ "$TRANSPORT_SETTING" != "rmw_cyclonedds_cpp" ] && [ ! -f "${SNAP_COMMON}/${TRANSPORT_SETTING}.xml" ]; then log_and_echo "'${SNAP_COMMON}/${TRANSPORT_SETTING}.xml' does not exist." diff --git a/snap/local/ros_common/utils.sh b/snap/local/ros_common/utils.sh index 7c3223a..bdbc41f 100755 --- a/snap/local/ros_common/utils.sh +++ b/snap/local/ros_common/utils.sh @@ -7,7 +7,7 @@ log_and_echo() { # Log the message with logger logger -t "${SNAP_NAME}" "${script_name}: $message" # Echo the message to standard error - echo >&2 "$message" + echo -e >&2 "$message" } log() { diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 6c3550f..4e4e5bc 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -24,7 +24,7 @@ description: | * `ros-domain-id`: `0` - Sets the `ROS_DOMAIN_ID` environment variable for the ROS driver. * `ros-localhost-only`: `0` - Sets the `ROS_LOCALHOST_ONLY` environment variable for the ROS driver. * `serial-port`: `auto` - Configures the serial port for firmware updates (e.g., `/dev/ttyUSB0`), or set it to `auto`. - * `transport`: `udp` - Configures DDS transport. Options are `udp`, `shm`, `builtin`. Corresponding DDS XML files can be found in the `/var/snap/rosbot-xl/common` directory (custom FastDDS setups can also be created here). + * `transport`: `udp` - Configures DDS transport. Options are `udp`, `shm`, `builtin` (or `rmw_fastrtps_cpp`), `rmw_cyclonedds_cpp`. Corresponding DDS XML files can be found in the `/var/snap/rosbot-xl/common` directory (custom FastDDS setups can also be created here). * `webui`: `{...}` The `driver` parameter is a dictionary containing the following keys for a ROS 2 driver: @@ -77,7 +77,6 @@ description: | # Install configurations with /var/snap/rosbot-xl/common/manage_ros_env.sh - # After changing rosbot-xl parameters, open a new terminal, or run: source ~/.bashrc ros2 run teleop_twist_keyboard teleop_twist_keyboard --ros-args --remap __ns:=/${ROS_NAMESPACE} @@ -210,7 +209,8 @@ parts: rosbot-xl: plugin: colcon source: https://github.com/husarion/rosbot_xl_ros.git - source-branch: "0.11.4" + # source-branch: "0.11.4" + source-commit: "fca8704edeb6166474b65b317aed3cf455f63ab9" build-packages: - python3-vcstool stage-packages: