Skip to content

Commit

Permalink
small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikN committed May 20, 2024
1 parent 3be8fcf commit 947ae9f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 19 deletions.
47 changes: 47 additions & 0 deletions snap/hooks/configure
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,53 @@ log() {

$SNAP/usr/bin/configure_hook_ros.sh

is_integer() {
expr "$1" : '-\?[0-9][0-9]*$' >/dev/null 2>&1
}

# Make sure ROS 2 nodes parameters value is a boolean
OPTS="inverted angle-compensate"
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."
exit 1
;;
esac
fi
done

# Make sure ROS 2 nodes parameters value is a boolean
OPTS="channel-type"
for OPT in ${OPTS}; do
VALUE="$(snapctl get driver.${OPT})"
if [ -n "${VALUE}" ]; then
case "${VALUE}" in
"serial") ;;
"tcp") ;;
"udp") ;;
*)
log_and_echo "configure hook: '${VALUE}' is not a supported value for ${OPT}." \
"Possible values are serial, tcp, udp."
exit 1
;;
esac
fi
done

# Make sure ROS 2 nodes parameters value is a boolean
OPT="serial-baudrate"
VALUE="$(snapctl get driver.${OPT})"
if ! is_integer "${VALUE}" ; then
log_and_echo "'${VALUE}' is not a supported value for '${OPT}'. Possible values are integers."
exit 1
fi

# restart services with new ROS 2 config
for service in daemon; do
if snapctl services ${SNAP_NAME}.${service} | grep -qw active; then
Expand Down
21 changes: 11 additions & 10 deletions snap/local/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ log() {
# Iterate over the snap parameters and retrieve their value.
# If a value is set, it is forwarded to the launch file.
OPTIONS="\
channel-type \
serial-port \
serial-baudrate \
frame-id \
inverted \
angle-compensate \
scan-mode \
robot-namespace \
device-namespace \
"
channel-type \
serial-port \
serial-baudrate \
frame-id \
inverted \
angle-compensate \
scan-mode \
namespace \
device-namespace \
"

LAUNCH_OPTIONS=""

for OPTION in ${OPTIONS}; do
Expand Down
24 changes: 15 additions & 9 deletions snap/local/rplidar.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

def get_frame_id(context):
device_ns = LaunchConfiguration('device_namespace').perform(context)
return f"{device_ns}_link" if device_ns else "laser"
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')
Expand All @@ -20,12 +21,20 @@ def generate_launch_description():
inverted = LaunchConfiguration('inverted', default='false')
angle_compensate = LaunchConfiguration('angle_compensate', default='true')
scan_mode = LaunchConfiguration('scan_mode', default='')
robot_namespace = LaunchConfiguration('robot_namespace', 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('robot_namespace').perform(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',
Expand All @@ -40,14 +49,11 @@ def launch_setup(context, *args, **kwargs):
'angle_compensate': angle_compensate,
'scan_mode': scan_mode
}],
remappings=[
('/tf', f'/{robot_ns}/tf'),
('/tf_static', f'/{robot_ns}/tf_static')
],
remappings=remappings,
output='screen'
)

return [PushRosNamespace(robot_namespace), PushRosNamespace(device_namespace), node]
return [PushRosNamespace(namespace), PushRosNamespace(device_namespace), node]

return LaunchDescription([

Expand Down Expand Up @@ -87,7 +93,7 @@ def launch_setup(context, *args, **kwargs):
description='Specifying scan mode of lidar'),

DeclareLaunchArgument(
'robot_namespace',
'namespace',
default_value='',
description='Namespace which will appear in front of all topics (including /tf and /tf_static).',
),
Expand Down

0 comments on commit 947ae9f

Please sign in to comment.