Skip to content

Commit

Permalink
Refactor husarion snap common (#18)
Browse files Browse the repository at this point in the history
* using husarion-snap-common
* added utility scripts for generating store credentials
  • Loading branch information
DominikN authored Sep 16, 2024
1 parent 1a2d0b9 commit cb3ac2b
Show file tree
Hide file tree
Showing 43 changed files with 247 additions and 1,724 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.snap
squashfs-root
test*
.snapcraft_store_credentials.txt
squashfs-root/
**/snapcraft.yaml
exported.txt
13 changes: 1 addition & 12 deletions demo/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ x-net-config:

x-gpu-config:
&gpu-config
runtime: nvidia
# runtime: nvidia
environment:
- DISPLAY=${DISPLAY:?err}
- NVIDIA_VISIBLE_DEVICES=all
Expand All @@ -23,16 +23,5 @@ services:
container_name: rviz
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix:rw
- ./config/rosbot_xl.rviz:/ros2_ws/install/rosbot_xl_manipulation_moveit/share/rosbot_xl_manipulation_moveit/config/moveit.rviz
command: ros2 launch rosbot_xl_manipulation_moveit rviz.launch.py

joy2twist:
image: husarion/joy2twist:humble-1.0.0-20230204-stable
<<: *net-config
devices:
- /dev/input
volumes:
- ./config/joy2twist.yaml:/joy2twist.yaml
command: >
ros2 launch joy2twist gamepad_controller.launch.py
joy2twist_params_file:=/joy2twist.yaml
22 changes: 0 additions & 22 deletions demo/config/joy2twist.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions demo/net.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# =======================================

# 1. Fast DDS + LAN
# RMW_IMPLEMENTATION=rmw_fastrtps_cpp
RMW_IMPLEMENTATION=rmw_fastrtps_cpp

# 2. Cyclone DDS + LAN
RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
# RMW_IMPLEMENTATION=rmw_cyclonedds_cpp

# 3. Fast DDS + VPN
# RMW_IMPLEMENTATION=rmw_fastrtps_cpp
Expand Down
38 changes: 34 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ teleop:
# export FASTRTPS_DEFAULT_PROFILES_FILE=$(pwd)/shm-only.xml
ros2 run teleop_twist_keyboard teleop_twist_keyboard # --ros-args -r __ns:=/robot

iterate:
#!/bin/bash -e
iterate target="jazzy":
#!/bin/bash
start_time=$(date +%s)

echo "Starting script..."
Expand All @@ -152,13 +152,31 @@ iterate:
sudo rm -rf squashfs-root/
sudo rm -rf rosbot-xl*.snap
export SNAPCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS=1
snapcraft clean

if [ {{target}} == "humble" ]; then
export ROS_DISTRO=humble
elif [ {{target}} == "jazzy" ]; then
export ROS_DISTRO=jazzy
else
echo "Unknown target: {{target}}"
exit 1
fi

if [ -f snap/snapcraft.yaml ]; then
snapcraft clean
sudo rm -rf snap/snapcraft.yaml
fi

./render_template.py ./snapcraft_template.yaml.jinja2 snap/snapcraft.yaml
chmod 444 snap/snapcraft.yaml
snapcraft
unsquashfs rosbot-xl*.snap
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
sudo snap connect rosbot-xl:hardware-observe
sudo snap connect rosbot-xl:joystick

end_time=$(date +%s)
duration=$(( end_time - start_time ))
Expand All @@ -172,4 +190,16 @@ iterate:
remove-logs:
#!/bin/bash
sudo rm -rf /var/log/journal/*
sudo systemctl restart systemd-journald
sudo systemctl restart systemd-journald

prepare-store-credentials:
#!/bin/bash
snapcraft export-login --snaps=rosbot-xl \
--acls package_access,package_push,package_update,package_release \
exported.txt

publish:
#!/bin/bash
export SNAPCRAFT_STORE_CREDENTIALS=$(cat exported.txt)
snapcraft login
snapcraft upload --release edge rosbot-xl*.snap
27 changes: 5 additions & 22 deletions snap/hooks/configure
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ source $SNAP/usr/bin/utils.sh

# Define the top-level key and the list of valid keys
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
validate_keys "driver" VALID_DRIVER_KEYS[@]
validate_keys "webui" VALID_WEBUI_KEYS[@]

# 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")
Expand All @@ -27,25 +25,10 @@ validate_option "driver.mecanum" VALID_BOOLEAN_OPTIONS[@]
validate_option "driver.include-camera-mount" VALID_BOOLEAN_OPTIONS[@]

# Validate specific serial ports
validate_serial_port "driver.db-serial-port"
validate_serial_port "driver.manipulator-serial-port"

# Get the transport setting using snapctl
OPT="webui.layout"
LAYOUT="$(snapctl get ${OPT})"

# Only exit with status 1 if conditions are not met
if [ ! -f "${SNAP_COMMON}/foxglove-${LAYOUT}.json" ]; then
log_and_echo "'${SNAP_COMMON}/foxglove-${LAYOUT}.json' does not exist."
exit 1
fi

# Make sure WEBUI_PORT is valid
EXCLUDED_PORTS=(3000 8888)
SUPPORTED_RANGE=(0 65535)

# Validate a specific port, for example, webui.port
validate_number "webui.port" SUPPORTED_RANGE[@] EXCLUDED_PORTS[@]
# validate driver.serial-port
ALTERNATIVE_SERIAL_PORT_OPTIONS=("auto")
validate_path "driver.db-serial-port" "/dev/ttyUSB[0-9]+" ALTERNATIVE_SERIAL_PORT_OPTIONS[@]
validate_path "driver.manipulator-serial-port" "/dev/ttyUSB[0-9]+" ALTERNATIVE_SERIAL_PORT_OPTIONS[@]

VALID_CONFIGURATION_OPTIONS=("basic" "manipulation")

Expand All @@ -65,7 +48,7 @@ fi
$SNAP/usr/bin/configure_hook_ros.sh

# restart services with new ROS 2 config
for service in daemon web-ui web-ws joy teleop-twist-joy; do
for service in daemon joy; do
if snapctl services ${SNAP_NAME}.${service} | grep -qw enabled; then
snapctl restart ${SNAP_NAME}.${service}
log "Restarted ${SNAP_NAME}.${service}"
Expand Down
8 changes: 0 additions & 8 deletions snap/hooks/connect-plug-ros-humble-ros-base

This file was deleted.

4 changes: 0 additions & 4 deletions snap/hooks/disconnect-plug-ros-humble-ros-base

This file was deleted.

17 changes: 7 additions & 10 deletions snap/hooks/install
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,18 @@ snapctl set driver.lidar-model=None
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=basic

if ! snapctl is-connected raw-usb; then
log "Plug 'raw-usb' isn't connected, please run:"
log "sudo snap connect ${SNAP_NAME}:raw-usb"
fi

# copy meshes to shared folder
log "copy meshes to '${SNAP_COMMON}/ros2_ws/'"
mkdir -p ${SNAP_COMMON}/ros2_ws
cp -r $SNAP/opt/ros/snap/share/rosbot_xl_description ${SNAP_COMMON}/ros2_ws/rosbot_xl_description
cp -r $SNAP/opt/ros/snap/share/ros_components_description ${SNAP_COMMON}/ros2_ws/ros_components_description
# # copy meshes to shared folder
# log "copy meshes to '${SNAP_COMMON}/ros2_ws/'"
# mkdir -p ${SNAP_COMMON}/ros2_ws
# cp -r $SNAP/opt/ros/snap/share/rosbot_xl_description ${SNAP_COMMON}/ros2_ws/rosbot_xl_description
# cp -r $SNAP/opt/ros/snap/share/ros_components_description ${SNAP_COMMON}/ros2_ws/ros_components_description

# copy joy params
cp -r $SNAP/usr/share/rosbot-xl/config/teleop_twist_joy_params.yaml ${SNAP_COMMON}/
Expand All @@ -38,5 +35,5 @@ cp -r $SNAP/usr/share/rosbot-xl/config/joy_servo.yaml ${SNAP_COMMON}/
cp -r $SNAP/usr/share/rosbot-xl/config/joy_teleop.config.yaml ${SNAP_COMMON}/
cp -r $SNAP/usr/share/rosbot-xl/config/joy_params.yaml ${SNAP_COMMON}/

# copy webui layouts
cp -r $SNAP/usr/share/$SNAP_NAME/config/foxglove-*.json ${SNAP_COMMON}/
# # copy webui layouts
# cp -r $SNAP/usr/share/$SNAP_NAME/config/foxglove-*.json ${SNAP_COMMON}/
48 changes: 0 additions & 48 deletions snap/local/Caddyfile

This file was deleted.

24 changes: 0 additions & 24 deletions snap/local/bridge_launch.py

This file was deleted.

13 changes: 0 additions & 13 deletions snap/local/bridge_launcher.sh

This file was deleted.

41 changes: 0 additions & 41 deletions snap/local/caddy_launcher.sh

This file was deleted.

2 changes: 1 addition & 1 deletion snap/local/flash_launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ else
fi

# Check if SERIAL_PORT is set to auto or specified
SERIAL_PORT=$(find_ttyUSB driver.db-serial-port "0403" "6015")
SERIAL_PORT=$(find_usb_device "ttyUSB" driver.db-serial-port "0403" "6015")
if [ $? -ne 0 ]; then
log_and_echo "Failed to find the serial port."
exit 1
Expand Down
Loading

0 comments on commit cb3ac2b

Please sign in to comment.