Skip to content

Commit

Permalink
Jazzy fix (#5)
Browse files Browse the repository at this point in the history
* separate launch file for humble and jazzy

* remove snapcraft.yaml from version control
  • Loading branch information
DominikN authored Aug 7, 2024
1 parent 2fb1adf commit 286a35d
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 128 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
squashfs-root/
*.snap
exported.txt
exported.txt
**/snapcraft.yaml
9 changes: 7 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand All @@ -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 ))
Expand Down
4 changes: 2 additions & 2 deletions snap/local/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
108 changes: 108 additions & 0 deletions snap/local/rplidar-jazzy.launch.py
Original file line number Diff line number Diff line change
@@ -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)
])
120 changes: 0 additions & 120 deletions snap/snapcraft.yaml

This file was deleted.

9 changes: 7 additions & 2 deletions snapcraft_template.yaml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]

Expand All @@ -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}')"
Expand Down

0 comments on commit 286a35d

Please sign in to comment.