From 286a35dd3d3f334abaafd69c61edd6d4df8c7c45 Mon Sep 17 00:00:00 2001 From: Dominik Nowak Date: Wed, 7 Aug 2024 22:17:52 +0200 Subject: [PATCH] Jazzy fix (#5) * separate launch file for humble and jazzy * remove snapcraft.yaml from version control --- .gitignore | 3 +- justfile | 9 +- snap/local/launcher.sh | 4 +- ...dar.launch.py => rplidar-humble.launch.py} | 2 +- snap/local/rplidar-jazzy.launch.py | 108 ++++++++++++++++ snap/snapcraft.yaml | 120 ------------------ snapcraft_template.yaml.jinja2 | 9 +- 7 files changed, 127 insertions(+), 128 deletions(-) rename snap/local/{rplidar.launch.py => rplidar-humble.launch.py} (98%) create mode 100644 snap/local/rplidar-jazzy.launch.py delete mode 100644 snap/snapcraft.yaml diff --git a/.gitignore b/.gitignore index 2a86a39..22a4a47 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ squashfs-root/ *.snap -exported.txt \ No newline at end of file +exported.txt +**/snapcraft.yaml \ No newline at end of file diff --git a/justfile b/justfile index ae3b519..20abfd1 100644 --- a/justfile +++ b/justfile @@ -18,8 +18,9 @@ build target="humble": exit 1 fi + sudo rm -rf snap/snapcraft.yaml ./render_template.py ./snapcraft_template.yaml.jinja2 snap/snapcraft.yaml - + chmod 444 snap/snapcraft.yaml snapcraft install: @@ -39,7 +40,7 @@ clean: export SNAPCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS=1 snapcraft clean -iterate target="humble": +iterate target="jazzy": #!/bin/bash start_time=$(date +%s) @@ -60,14 +61,18 @@ iterate target="humble": fi snapcraft clean + sudo rm -rf snap/snapcraft.yaml ./render_template.py ./snapcraft_template.yaml.jinja2 snap/snapcraft.yaml + chmod 444 snap/snapcraft.yaml snapcraft unsquashfs husarion-rplidar*.snap sudo snap try squashfs-root/ sudo snap connect husarion-rplidar:raw-usb + sudo snap connect husarion-rplidar:hardware-observe # for find_usb_device sudo snap connect husarion-rplidar:shm-plug husarion-rplidar:shm-slot sudo husarion-rplidar.stop + sudo snap set husarion-rplidar configuration=s2 end_time=$(date +%s) duration=$(( end_time - start_time )) diff --git a/snap/local/launcher.sh b/snap/local/launcher.sh index 570bf56..e295987 100755 --- a/snap/local/launcher.sh +++ b/snap/local/launcher.sh @@ -13,7 +13,7 @@ if [ -n "$NAMESPACE" ]; then fi # Check if SERIAL_PORT is set to auto or specified -SERIAL_PORT=$(find_ttyUSB driver.serial-port "10c4") +SERIAL_PORT=$(find_usb_device "ttyUSB" driver.serial-port "10c4") if [ $? -ne 0 ]; then log_and_echo "Failed to find the serial port." exit 1 @@ -60,4 +60,4 @@ if [ "${LAUNCH_OPTIONS}" ]; then log_and_echo "Running with options: ${LAUNCH_OPTIONS}" fi -ros2 launch $SNAP/usr/bin/rplidar.launch.py ${LAUNCH_OPTIONS} +ros2 launch $SNAP/usr/bin/rplidar-${ROS_DISTRO}.launch.py ${LAUNCH_OPTIONS} diff --git a/snap/local/rplidar.launch.py b/snap/local/rplidar-humble.launch.py similarity index 98% rename from snap/local/rplidar.launch.py rename to snap/local/rplidar-humble.launch.py index 29e142f..129f6ca 100644 --- a/snap/local/rplidar.launch.py +++ b/snap/local/rplidar-humble.launch.py @@ -38,7 +38,7 @@ def launch_setup(context, *args, **kwargs): node = Node( package='rplidar_ros', - executable='rplidar_node', + executable='rplidar_composition', name='rplidar_node', parameters=[{ 'channel_type': channel_type, diff --git a/snap/local/rplidar-jazzy.launch.py b/snap/local/rplidar-jazzy.launch.py new file mode 100644 index 0000000..129f6ca --- /dev/null +++ b/snap/local/rplidar-jazzy.launch.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python3 + +import os + +from ament_index_python.packages import get_package_share_directory +from launch import LaunchDescription +from launch.actions import DeclareLaunchArgument, GroupAction, OpaqueFunction +from launch.substitutions import LaunchConfiguration +from launch_ros.actions import Node, PushRosNamespace + +def get_frame_id(context): + device_ns = LaunchConfiguration('device_namespace').perform(context) + default_frame_id = LaunchConfiguration('frame_id').perform(context) + return f"{device_ns}_link" if device_ns else f"{default_frame_id}" + +def generate_launch_description(): + channel_type = LaunchConfiguration('channel_type', default='serial') + serial_port = LaunchConfiguration('serial_port', default='/dev/ttyUSB0') + serial_baudrate = LaunchConfiguration('serial_baudrate', default='256000') # for A3 is 256000 + frame_id = LaunchConfiguration('frame_id', default='laser') + inverted = LaunchConfiguration('inverted', default='false') + angle_compensate = LaunchConfiguration('angle_compensate', default='true') + scan_mode = LaunchConfiguration('scan_mode', default='') + namespace = LaunchConfiguration('namespace', default='') + device_namespace = LaunchConfiguration('device_namespace', default='') + + def launch_setup(context, *args, **kwargs): + frame_id_value = get_frame_id(context) + robot_ns = LaunchConfiguration('namespace').perform(context) + + remappings = [] + if robot_ns: + remappings.append(('/tf', f'/{robot_ns}/tf')) + remappings.append(('/tf_static', f'/{robot_ns}/tf_static')) + else: + remappings.append(('/tf', '/tf')) + remappings.append(('/tf_static', '/tf_static')) + + node = Node( + package='rplidar_ros', + executable='rplidar_composition', + name='rplidar_node', + parameters=[{ + 'channel_type': channel_type, + 'serial_port': serial_port, + 'serial_baudrate': serial_baudrate, + 'frame_id': frame_id_value, + 'inverted': inverted, + 'angle_compensate': angle_compensate, + 'scan_mode': scan_mode + }], + remappings=remappings, + output='screen' + ) + + return [PushRosNamespace(namespace), PushRosNamespace(device_namespace), node] + + return LaunchDescription([ + + DeclareLaunchArgument( + 'channel_type', + default_value=channel_type, + description='Specifying channel type of lidar'), + + DeclareLaunchArgument( + 'serial_port', + default_value=serial_port, + description='Specifying usb port to connected lidar'), + + DeclareLaunchArgument( + 'serial_baudrate', + default_value=serial_baudrate, + description='Specifying usb port baudrate to connected lidar'), + + DeclareLaunchArgument( + 'frame_id', + default_value=frame_id, + description='Specifying frame_id of lidar'), + + DeclareLaunchArgument( + 'inverted', + default_value=inverted, + description='Specifying whether or not to invert scan data'), + + DeclareLaunchArgument( + 'angle_compensate', + default_value=angle_compensate, + description='Specifying whether or not to enable angle_compensate of scan data'), + + DeclareLaunchArgument( + 'scan_mode', + default_value=scan_mode, + description='Specifying scan mode of lidar'), + + DeclareLaunchArgument( + 'namespace', + default_value='', + description='Namespace which will appear in front of all topics (including /tf and /tf_static).', + ), + + DeclareLaunchArgument( + 'device_namespace', + default_value='', + description='Sensor namespace that will appear before all non absolute topics and TF frames, used for distinguishing multiple cameras on the same robot.', + ), + + OpaqueFunction(function=launch_setup) + ]) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml deleted file mode 100644 index 6b5bc3c..0000000 --- a/snap/snapcraft.yaml +++ /dev/null @@ -1,120 +0,0 @@ -name: husarion-rplidar -adopt-info: husarion-rplidar -license: Apache-2.0 -summary: RPLIDAR ROS 2 driver for Husarion robots -icon: snap/gui/icon.png -description: | - The `husarion-rplidar` snap contains all the necessary software to bring the RPLIDAR LIDARS up. - - **Parameters** - - The snap provides the following configurable parameters (`param name`: `default value`): - - * `configuration`: `custom` - * `driver`: `{...}` - * `ros`: `{...}` - - The `ros` contains the following keys: - - * `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. - * `ros.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). - * `ros.namespace`: `(unset)` - Namespace for all topics and transforms. - - The `driver` contains the following keys: - - * `channel-type`: `serial` - * `serial-port`: `auto` - * `serial-baudrate`: `256000` - * `frame-id`: `laser` - * `inverted`: `false` - * `angle-compensate`: `true` - * `scan-mode`: `(unset)` - * `device-namespace`: `(unset)` - - To set the parameters, use the snap set command, e.g., - - snap set husarion-rplidar driver.device-namespace=front_lidar - -grade: stable -confinement: strict -base: core22 - -contact: https://github.com/husarion/husarion-rplidar-snap/issues -issues: https://github.com/husarion/husarion-rplidar-snap/issues -website: https://husarion.com/ - -slots: - shm-slot: - interface: shared-memory - write: ['*'] # paths are relative to /dev/shm - -plugs: - shm-plug: - interface: shared-memory - shared-memory: shm-slot - private: false - -apps: - - daemon: - command: usr/bin/launcher.sh - command-chain: [usr/bin/ros_setup.sh] - daemon: simple - install-mode: enable - plugs: [network, network-bind, shm-plug, raw-usb] - slots: [shm-slot] - extensions: [ros2-humble-ros-base] - - husarion-rplidar: - command: usr/bin/launcher.sh - command-chain: [usr/bin/check_daemon_running.sh, usr/bin/ros_setup.sh] - plugs: [network, network-bind, shm-plug, raw-usb] - slots: [shm-slot] - extensions: [ros2-humble-ros-base] - - start: - command: usr/bin/start_launcher.sh - - stop: - command: usr/bin/stop_launcher.sh - -parts: - husarion-rplidar: - plugin: nil - stage-packages: - - ros-humble-rplidar-ros - override-stage: | - craftctl default - version="$(apt-cache policy ros-humble-rplidar-ros | grep Candidate | awk '{print $2}')" - craftctl set version="$version" - craftctl set grade="stable" - - local-files: - plugin: dump - source: snap/local/ - organize: - '*.sh': usr/bin/ - '*.py': usr/bin/ - - husarion-snap-common: - plugin: dump - source: https://github.com/husarion/husarion-snap-common - source-branch: "0.5.0" - source-type: git - build-environment: - - YQ_VERSION: "v4.35.1" - build-packages: - - curl - organize: - 'local-ros/*.sh': usr/bin/ - 'local-ros/*.xml': usr/share/husarion-snap-common/config/ - 'local-ros/ros.env': usr/share/husarion-snap-common/config/ - override-build: | - craftctl default - curl -L "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_${CRAFT_ARCH_BUILD_FOR}" -o $CRAFT_PART_BUILD/yq - override-prime: | - craftctl default - cp $CRAFT_PART_BUILD/yq $CRAFT_PRIME/usr/bin/yq - chmod +x $CRAFT_PRIME/usr/bin/yq - rm -rf $CRAFT_PRIME/local-ros \ No newline at end of file diff --git a/snapcraft_template.yaml.jinja2 b/snapcraft_template.yaml.jinja2 index 2e510de..d2c372e 100644 --- a/snapcraft_template.yaml.jinja2 +++ b/snapcraft_template.yaml.jinja2 @@ -44,6 +44,10 @@ contact: https://github.com/husarion/husarion-rplidar-snap/issues issues: https://github.com/husarion/husarion-rplidar-snap/issues website: https://husarion.com/ +hooks: + configure: + plugs: [raw-usb, hardware-observe] + slots: shm-slot: interface: shared-memory @@ -62,14 +66,14 @@ apps: command-chain: [usr/bin/ros_setup.sh] daemon: simple install-mode: enable - plugs: [network, network-bind, shm-plug, raw-usb] + plugs: [network, network-bind, shm-plug, raw-usb, hardware-observe] slots: [shm-slot] extensions: [ros2-{{ ros_distro }}-ros-base] husarion-rplidar: command: usr/bin/launcher.sh command-chain: [usr/bin/check_daemon_running.sh, usr/bin/ros_setup.sh] - plugs: [network, network-bind, shm-plug, raw-usb] + plugs: [network, network-bind, shm-plug, raw-usb, hardware-observe] slots: [shm-slot] extensions: [ros2-{{ ros_distro }}-ros-base] @@ -84,6 +88,7 @@ parts: plugin: nil stage-packages: - ros-{{ ros_distro }}-rplidar-ros + - ros-{{ ros_distro }}-rmw-cyclonedds-cpp override-stage: | craftctl default version="$(apt-cache policy ros-{{ ros_distro }}-rplidar-ros | grep Candidate | awk '{print $2}')"