Skip to content

Commit

Permalink
namespace is now under ros key
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikN committed Jun 19, 2024
1 parent 75875b7 commit 399110a
Show file tree
Hide file tree
Showing 18 changed files with 54 additions and 33 deletions.
1 change: 1 addition & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ iterate:
sudo snap try squashfs-root/
sudo snap connect rosbot-xl:raw-usb
sudo snap connect rosbot-xl:shm-plug rosbot-xl:shm-slot
sudo snap connect rosbot-xl:shutdown

end_time=$(date +%s)
duration=$(( end_time - start_time ))
Expand Down
10 changes: 5 additions & 5 deletions snap/hooks/configure
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ source $SNAP/usr/bin/utils.sh
$SNAP/usr/bin/configure_hook_ros.sh

# Define the top-level key and the list of valid keys
VALID_DRIVER_KEYS=("namespace" "mecanum" "include-camera-mount" "camera-model" "lidar-model" "db-serial-port" "manipulator-serial-port" )
VALID_DRIVER_KEYS=("mecanum" "include-camera-mount" "camera-model" "lidar-model" "db-serial-port" "manipulator-serial-port" )
VALID_WEBUI_KEYS=("layout" "port")

# Call the validation function
Expand Down Expand Up @@ -49,16 +49,16 @@ SUPPORTED_RANGE=(0 65535)
# Validate a specific port, for example, webui.port
validate_number "webui.port" SUPPORTED_RANGE[@] EXCLUDED_PORTS[@]

VALID_CONFIGURATION_OPTIONS=("mobile-platform" "mobile-manipulator")
VALID_CONFIGURATION_OPTIONS=("basic" "manipulation")

# Validate parameters with array of possible values
validate_option "configuration" VALID_CONFIGURATION_OPTIONS[@]

OPT="configuration"
VALUE="$(snapctl get ${OPT})"
if [ "${VALUE}" == "mobile-manipulator" ]; then
log_and_echo "Currently the 'driver.namespace', 'driver.include-camera-mount' and 'driver.camera-model' are not supported for the 'mobile-manipulator' option. Unsetting them."
snapctl set driver.namespace!
if [ "${VALUE}" == "manipulation" ]; then
log_and_echo "Currently the 'ros.namespace', 'driver.include-camera-mount' and 'driver.camera-model' are not supported for the 'manipulation' option. Unsetting them."
snapctl set ros.namespace!
snapctl set driver.camera-model=None
snapctl set driver.include-camera-mount=False
fi
Expand Down
3 changes: 1 addition & 2 deletions snap/hooks/install
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ snapctl set driver.mecanum=True
snapctl set driver.include-camera-mount=True
snapctl set driver.camera-model=None
snapctl set driver.lidar-model=None
snapctl set driver.namespace! # unset
snapctl set driver.db-serial-port=auto
snapctl set driver.manipulator-serial-port=auto

snapctl set webui.layout=default
snapctl set webui.port=8080

snapctl set configuration=mobile-platform
snapctl set configuration=basic

if ! snapctl is-connected raw-usb; then
log "Plug 'raw-usb' isn't connected, please run:"
Expand Down
13 changes: 8 additions & 5 deletions snap/local/bridge_launcher.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/bin/bash -e

NAMESPACE="$(snapctl get driver.namespace)"
LAUNCH_OPTIONS=""

# Check if the namespace is set and not empty
# Retrieve the namespace using snapctl
NAMESPACE="$(snapctl get ros.namespace)"

# Check if NAMESPACE is not set or is empty
if [ -n "$NAMESPACE" ]; then
ros2 launch $SNAP/usr/bin/bridge_launch.py namespace:=${NAMESPACE}
else
ros2 launch $SNAP/usr/bin/bridge_launch.py
LAUNCH_OPTIONS+="namespace:=${NAMESPACE} "
fi

ros2 launch $SNAP/usr/bin/bridge_launch.py ${LAUNCH_OPTIONS}
4 changes: 2 additions & 2 deletions snap/local/caddy_launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ echo "${index_html_content/"$replace_pattern"/$replace_value}" > $index_html_pat
sed -i "s|<div id=\"root\"></div>|<script>\nlocalStorage.clear();sessionStorage.clear();\n</script>\n&|" $index_html_path

# Define a function to log and echo messages
# Retrieve the driver.namespace value
namespace=$(snapctl get driver.namespace)
# Retrieve the ros.namespace value
namespace=$(snapctl get ros.namespace)

# Check if the namespace is set and not empty
if [ -n "$namespace" ]; then
Expand Down
2 changes: 2 additions & 0 deletions snap/local/foxglove-set-namespace.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash -e

# deprecated (using caddy templates instead)

LAYOUT="$(snapctl get webui.layout)"
NAMESPACE="$(snapctl get driver.namespace)"

Expand Down
17 changes: 13 additions & 4 deletions snap/local/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

source $SNAP/usr/bin/utils.sh

LAUNCH_OPTIONS=""

# Retrieve the namespace using snapctl
NAMESPACE="$(snapctl get ros.namespace)"

# Check if NAMESPACE is not set or is empty
if [ -n "$NAMESPACE" ]; then
LAUNCH_OPTIONS+="namespace:=${NAMESPACE} "
fi

# Iterate over the snap parameters and retrieve their value.
# If a value is set, it is forwarded to the launch file.
OPTIONS="namespace mecanum include-camera-mount camera-model lidar-model"
LAUNCH_OPTIONS=""
OPTIONS="mecanum include-camera-mount camera-model lidar-model"

for OPTION in ${OPTIONS}; do
VALUE="$(snapctl get driver.${OPTION})"
Expand All @@ -22,9 +31,9 @@ fi

OPT="configuration"
VALUE="$(snapctl get ${OPT})"
if [ "${VALUE}" == "mobile-platform" ]; then
if [ "${VALUE}" == "basic" ]; then
ros2 launch rosbot_xl_bringup bringup.launch.py ${LAUNCH_OPTIONS}
else
elif [ "${VALUE}" == "manipulation" ]; then
# Check if SERIAL_PORT is set to auto or specified
SERIAL_PORT=$(find_ttyUSB driver.manipulator-serial-port "0403" "6014")
if [ $? -ne 0 ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ check_xml_profile_type() {
fi
}

VALID_ROS_KEYS=("localhost-only" "domain-id" "transport")
VALID_ROS_KEYS=("localhost-only" "domain-id" "transport" "namespace")

# Call the validation function
validate_keys "ros" VALID_ROS_KEYS[@]
Expand Down Expand Up @@ -105,14 +105,14 @@ ROS_SNAP_ARGS="${SNAP_COMMON}/ros_snap_args"
echo "export ROS_DOMAIN_ID=${ROS_DOMAIN_ID}" > "${ROS_ENV_FILE}"
echo "export ROS_LOCALHOST_ONLY=${ROS_LOCALHOST_ONLY}" >> "${ROS_ENV_FILE}"

NAMESPACE=$(snapctl get driver.namespace)
NAMESPACE=$(snapctl get ros.namespace)

# Check if the namespace is set and not empty
if [ -n "$NAMESPACE" ]; then
echo "ros.domain-id=${ROS_DOMAIN_ID} ros.localhost-only=${ROS_LOCALHOST_ONLY} ros.transport=${TRANSPORT_SETTING} driver.namespace=${NAMESPACE}" > "${ROS_SNAP_ARGS}"
echo "ros.domain-id=${ROS_DOMAIN_ID} ros.localhost-only=${ROS_LOCALHOST_ONLY} ros.transport=${TRANSPORT_SETTING} ros.namespace=${NAMESPACE}" > "${ROS_SNAP_ARGS}"
echo "export ROS_NAMESPACE=${NAMESPACE}" >> "${ROS_ENV_FILE}"
else
echo "ros.domain-id=${ROS_DOMAIN_ID} ros.localhost-only=${ROS_LOCALHOST_ONLY} ros.transport=${TRANSPORT_SETTING} driver.namespace!" > "${ROS_SNAP_ARGS}"
echo "ros.domain-id=${ROS_DOMAIN_ID} ros.localhost-only=${ROS_LOCALHOST_ONLY} ros.transport=${TRANSPORT_SETTING} ros.namespace!" > "${ROS_SNAP_ARGS}"
echo "unset ROS_NAMESPACE" >> "${ROS_ENV_FILE}"
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ source $SNAP/usr/bin/utils.sh
snapctl set ros.transport="udp"
snapctl set ros.localhost-only=0
snapctl set ros.domain-id=0
snapctl set ros.namespace! # unset

if ! snapctl is-connected ros-humble-ros-base; then
log "Plug 'ros-humble-ros-base' isn't connected, please run:"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion snap/local/teleop_launcher.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash -e

# Retrieve the namespace using snapctl
NAMESPACE="$(snapctl get driver.namespace)"
NAMESPACE="$(snapctl get ros.namespace)"

# Check if NAMESPACE is not set or is empty
if [ -z "$NAMESPACE" ]; then
Expand Down
26 changes: 16 additions & 10 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: |
To install this snap on the Single Board Computer (SBC) within the ROSbot XL chassis, follow these steps:
1. Connect the SBC to the Digital Board inside ROSbot XL using an Ethernet cable.
2. Configure the Ethernet Interface with the static IP address `192.168.77.2` (port `8888` on this IP is used by the STM32F4 microcontroller).
2. Configure the Ethernet Interface with the static IP address `192.168.77.2` (port `8888` on this IP is used by the firmware).
3. Run the following command to install the snap:
snap install rosbot-xl
Expand All @@ -20,22 +20,28 @@ description: |
The snap provides the following configurable parameters (`param name`: `default value`):
* `configuration`: `basic` - presets for ROSbot XL
* `driver`: `{...}`
* `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` (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`: `{...}`
* `webui`: `{...}`
The `driver` parameter is a dictionary containing the following keys for a ROS 2 driver:
The `ros` contains the following keys:
* `ros.ros-domain-id`: `0` - Sets the `ROS_DOMAIN_ID` environment variable for the ROS driver.
* `ros.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:
* `driver.namespace`: `(unset)` - Namespace for all topics and transforms.
* `driver.mecanum`: `True` - Enables the mecanum drive controller; otherwise, uses the differential drive controller.
* `driver.include-camera-mount`: `True` - Includes the camera mount in the robot URDF.
* `driver.camera-model`: `None` - Adds the camera model to the robot URDF.
* `driver.lidar-model`: `None` - Adds the LIDAR model to the robot URDF.
* `driver.db-serial-port`: `auto` - Serial port for firmware (e.g., `/dev/ttyUSB0`), or set it to `auto`.
* `driver.manipulator-serial-port`: `auto` - Serial port for OpenManipulator-X (e.g., `/dev/ttyUSB0`), or set it to `auto`.
The `webui` parameter is a dictionary containing the following keys for the Web UI:
The `webui` contains the following keys:
* `webui.layout`: `default` - Specifies the layout for the Web UI. Available `*.json` layout files can be found in the `/var/snap/rosbot-xl/common` directory (custom layouts can also be created here).
* `webui.port`: `8080` - Specifies the port for the built-in web server hosting the Web UI.
Expand Down Expand Up @@ -66,7 +72,7 @@ description: |
Example usage:
# Set parameters in the rosbot-xl snap
sudo snap set rosbot-xl transport=udp ros-domain-id=123 driver.namespace=abc
sudo snap set rosbot-xl transport=udp ros-domain-id=123 ros.namespace=abc
# Mirror the setup for other ROS 2 snaps
sudo snap set husarion-depthai $(cat /var/snap/rosbot-xl/common/ros_snap_args)
Expand Down Expand Up @@ -359,7 +365,7 @@ parts:
# copy local scripts to the snap usr/bin
local-files-ros:
plugin: dump
source: snap/local/ros_common/
source: snap/local/local-ros/
organize:
'*.sh': usr/bin/
'*.xml': usr/share/rosbot-xl/config/
Expand Down

0 comments on commit 399110a

Please sign in to comment.