diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..acb8de2 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,73 @@ +name: Build snap +on: + pull_request: + branches: + - main + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + include: + - ros_distro: humble + - ros_distro: jazzy + + # outputs: + # snap-file: ${{ steps.build-snap.outputs.snap }} + + steps: + + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-tags: true + + - name: Render snapcraft.yaml + run: | + pip install jinja2 + export ROS_DISTRO=${{ matrix.ros_distro }} + ./render_template.py ./snapcraft_template.yaml.jinja2 snap/snapcraft.yaml + + - name: Build snap + uses: snapcore/action-build@v1 + with: + snapcraft-channel: latest/edge + id: build-snap + env: + SNAPCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS: 1 + + - name: Make sure the snap is installable + run: | + sudo snap install --dangerous ${{ steps.build-snap.outputs.snap }} + + # # Save snap for subsequent job(s) + # - uses: actions/upload-artifact@v3 + # with: + # name: husarion-camera-snap + # path: ${{ steps.build-snap.outputs.snap }} + + # publish: + # if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') + # needs: build + # runs-on: ubuntu-latest + + # steps: + + # # Retrieve the snap + # - uses: actions/download-artifact@v3 + # with: + # name: husarion-camera-snap + # path: . + + # # Publish the snap on the store + # # by default on 'edge' but on 'candidate' for tags + # - uses: snapcore/action-publish@v1 + # env: + # SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.STORE_LOGIN }} + # with: + # snap: ${{needs.build.outputs.snap-file}} + # release: ${{ startsWith(github.ref, 'refs/tags/') && '${{ matrix.ros_distro }}/candidate' || '${{ matrix.ros_distro }}/edge'}} diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..a66bffe --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,54 @@ +name: Build and publish snap +on: + push: + tags: + - '*' + branches: + - main + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + include: + - ros_distro: humble + - ros_distro: jazzy + + steps: + + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-tags: true + + - name: Render snapcraft.yaml + run: | + pip install jinja2 + export ROS_DISTRO=${{ matrix.ros_distro }} + ./render_template.py ./snapcraft_template.yaml.jinja2 snap/snapcraft.yaml + + - name: Build snap + uses: snapcore/action-build@v1 + with: + snapcraft-channel: latest/edge + id: build-snap + env: + SNAPCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS: 1 + + - name: Make sure the snap is installable + run: | + sudo snap install --dangerous ${{ steps.build-snap.outputs.snap }} + + # Publish the snap on the store + # by default on 'edge' but on 'candidate' for tags + - name: Publish snap + uses: snapcore/action-publish@v1 + env: + SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.STORE_LOGIN }} + with: + snap: ${{ steps.build-snap.outputs.snap }} + release: ${{ matrix.ros_distro }}/${{ startsWith(github.ref, 'refs/tags/') && 'candidate' || 'edge' }} diff --git a/.github/workflows/snap.yaml b/.github/workflows/snap.yaml deleted file mode 100644 index 9c4de46..0000000 --- a/.github/workflows/snap.yaml +++ /dev/null @@ -1,61 +0,0 @@ -name: snap -on: - push: - tags: - - '*' - branches: - - main - pull_request: - branches: - - main - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-22.04 - outputs: - snap-file: ${{ steps.build-snap.outputs.snap }} - steps: - - - uses: actions/checkout@v3 - with: - fetch-tags: true - - # Build the snap - - uses: snapcore/action-build@v1 - with: - snapcraft-channel: latest/edge - id: build-snap - env: - SNAPCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS: 1 - - # Make sure the snap is installable - - run: | - sudo snap install --dangerous ${{ steps.build-snap.outputs.snap }} - - # Save snap for subsequent job(s) - - uses: actions/upload-artifact@v3 - with: - name: husarion-depthai-snap - path: ${{ steps.build-snap.outputs.snap }} - - publish: - if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') - needs: build - runs-on: ubuntu-22.04 - steps: - - # Retrieve the snap - - uses: actions/download-artifact@v3 - with: - name: husarion-depthai-snap - path: . - - # Publish the snap on the store - # by default on 'edge' but on 'candidate' for tags - - uses: snapcore/action-publish@v1 - env: - SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.STORE_LOGIN }} - with: - snap: ${{needs.build.outputs.snap-file}} - release: ${{ startsWith(github.ref, 'refs/tags/') && 'candidate' || 'edge'}} diff --git a/README.md b/README.md index 1f8f974..08f60cd 100644 --- a/README.md +++ b/README.md @@ -16,42 +16,16 @@ Snap for OAK-x cameras customized for Husarion robots | `husarion-depthai.start` | Start the `husarion-depthai.daemon` service | | `husarion-depthai.stop` | Stop the `husarion-depthai.daemon` service | | `husarion-depthai` | Start the application in the foreground (run in the current terminal). Remember to stop the daemon first | -| `husarion-depthai.image-view` | Preview the image from the camera | -## Setup FFMPEG +## Setup Camera Params -The default values for `ffmpeg-image-transport` are: - -```bash -$ sudo snap get husarion-depthai driver.ffmpeg-image-transport -Key Value -driver.ffmpeg-image-transport.encoding libx264 -driver.ffmpeg-image-transport.preset ultrafast -driver.ffmpeg-image-transport.tune zerolatency -``` - -to check available options run: - -```bash -ffmpeg -encoders -``` - -find the list of available presets by running +The default config parameters for camera node are selected with: ```bash -ffmpeg -h encoder=$SELECTED_ENCODER` +$ sudo snap set husarion-depthai driver.camera-config=default ``` -## Setup Astra Params - -Default astra params are stored in the following file: - -```bash -$ sudo snap get husarion-depthai driver.params-file -/var/snap/husarion-depthai/common/depthai_params.yaml -``` - -The default `depthai_params.yaml` file content: +The default config is get from: `/var/snap/husarion-depthai/common/camera-config-default.yaml` file: ```yaml --- @@ -111,6 +85,12 @@ The default `depthai_params.yaml` file content: i_low_bandwidth: true #false i_low_bandwidth_quality: 20 i_max_q_size: 30 + # i_width: 1280 #valid if i_output_isp: false + # i_height: 720 #valid if i_output_isp: false + # i_interleaved: false + # scaling 1920x1080 1:3 to 640x360 + # https://docs-beta.luxonis.com/develop/ros/depthai-ros-driver#Available%20sensors%20and%20their%20resolutions%3A + # IMX378, 1080P is 1920x1080, i_isp_den=3 and i_isp_num=2 will give 1280x720 (/16=) i_output_isp: true i_preview_height: 300 i_preview_size: 300 @@ -136,24 +116,78 @@ The default `depthai_params.yaml` file content: ``` -To set a new params create a copy of the `depthai_params.yaml` file: +You can create your own config file: `/var/snap/husarion-depthai/common/camera-config-.yaml`: + +```bash +sudo cp \ +/var/snap/husarion-depthai/camera-config-default.yaml \ +/var/snap/husarion-depthai/camera-config-myconfig.yaml +``` + +Modify the content of the `camera-config-myconfig.yaml` file, eg: + +```bash +sudo vim /var/snap/depthai-camera/common/camera-config-myconfig.yaml +``` + +And set the new path to the config file: + +```bash +sudo snap set depthai-camera driver.camera-params=myconfig +``` + +## Setup FFMPEG Params + +The default values for `ffmpeg-image-transport` are: + +```bash +$ sudo snap set husarion-depthai driver.ffmpeg-config=default +``` + +The default config is get from: `/var/snap/husarion-depthai/common/ffmpeg-config-default.yaml` file: + +```yaml +--- +/**: + ros__parameters: + ffmpeg_image_transport: + + # find the list of available encoders by running `ffmpeg -encoders` + encoding: libx264 + + # find the list of available presets by running `ffmpeg -h encoder=libx264` + preset: ultrafast + tune: zerolatency +``` + +You can create your own config file: `/var/snap/husarion-depthai/common/ffmpeg-config-.yaml`: ```bash sudo cp \ -/var/snap/husarion-depthai/common/depthai_params.yaml \ -/var/snap/husarion-depthai/common/depthai_params2.yaml +/var/snap/husarion-depthai/ffmpeg-config-default.yaml \ +/var/snap/husarion-depthai/ffmpeg-config-myconfig.yaml ``` -Modify the content of the `astra-params2.yaml` file, eg: +Modify the content of the `ffmpeg-config-myconfig.yaml` file, eg: ```bash -sudo vim /var/snap/husarion-depthai/common/depthai_params2.yaml +sudo vim /var/snap/husarion-depthai/common/ffmpeg-config-myconfig.yaml ``` And set the new path to the config file: ```bash -sudo snap set husarion-depthai driver.params-file=/var/snap/husarion-depthai/common/depthai_params2.yaml +sudo snap set husarion-depthai driver.ffmpeg-params=myconfig ``` -List of all available parameters for OAK-x cameras is [here](https://docs.luxonis.com/software/ros/depthai-ros/driver/) \ No newline at end of file +To check available options run: + +```bash +ffmpeg -encoders +``` + +find the list of available presets by running + +```bash +ffmpeg -h encoder=$SELECTED_ENCODER` +``` diff --git a/justfile b/justfile index 68eb0ac..3e5cd3e 100644 --- a/justfile +++ b/justfile @@ -1,6 +1,24 @@ -build: +[private] +default: + @just --list --unsorted + +build target="humble": #!/bin/bash export SNAPCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS=1 + + if [ {{target}} == "humble" ]; then + export ROS_DISTRO=humble + export CORE_VERSION=core22 + elif [ {{target}} == "jazzy" ]; then + export ROS_DISTRO=jazzy + export CORE_VERSION=core24 + else + echo "Unknown target: $target" + exit 1 + fi + + ./render_template.py ./snapcraft_template.yaml.jinja2 snap/snapcraft.yaml + snapcraft install: @@ -21,7 +39,7 @@ clean: export SNAPCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS=1 snapcraft clean -iterate: +iterate target="humble": #!/bin/bash start_time=$(date +%s) @@ -31,8 +49,20 @@ iterate: sudo rm -rf squashfs-root/ sudo rm -rf husarion-depthai*.snap export SNAPCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS=1 + + if [ {{target}} == "humble" ]; then + export ROS_DISTRO=humble + elif [ {{target}} == "jazzy" ]; then + export ROS_DISTRO=jazzy + else + echo "Unknown target: {{target}}" + exit 1 + fi + snapcraft clean + ./render_template.py ./snapcraft_template.yaml.jinja2 snap/snapcraft.yaml snapcraft + unsquashfs husarion-depthai*.snap sudo snap try squashfs-root/ sudo snap connect husarion-depthai:raw-usb diff --git a/render_template.py b/render_template.py new file mode 100755 index 0000000..8975a24 --- /dev/null +++ b/render_template.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 + +import sys +import os +from jinja2 import Environment, FileSystemLoader + +def render_template(template_path, output_path, context): + env = Environment(loader=FileSystemLoader(os.path.dirname(template_path))) + template = env.get_template(os.path.basename(template_path)) + + with open(output_path, 'w') as f: + f.write(template.render(context)) + +if __name__ == "__main__": + template_path = sys.argv[1] + output_path = sys.argv[2] + context = { + 'ros_distro': os.getenv('ROS_DISTRO'), + # 'core_version': os.getenv('CORE_VERSION') + } + + render_template(template_path, output_path, context) diff --git a/snap/gui/icon.png b/snap/gui/icon.png index 3adc622..befffb3 100644 Binary files a/snap/gui/icon.png and b/snap/gui/icon.png differ diff --git a/snap/hooks/configure b/snap/hooks/configure index 46c183d..1311156 100755 --- a/snap/hooks/configure +++ b/snap/hooks/configure @@ -19,26 +19,19 @@ VALID_DRIVER_KEYS=( "cam-roll" "cam-pitch" "cam-yaw" - "params-file" - "ffmpeg-image-transport" -) - -VALID_FFMPEG_IMAGE_TRANSPORT_KEYS=( - "encoding" - "preset" - "tune" + "camera-params" + "ffmpeg-params" ) # common validate_keys "driver" VALID_DRIVER_KEYS[@] -validate_keys "driver.ffmpeg-image-transport" VALID_FFMPEG_IMAGE_TRANSPORT_KEYS[@] # validate driver.name -validate_regex "driver.name" '^[a-z_-]{1,10}$' "Possible values are text with a maximum length of 10 characters, containing only lowercase letters (a-z), "-" or '_'." +validate_regex "driver.name" '^[a-z_-]{1,10}$' # validate driver.parent-frame -validate_regex "driver.parent-frame" '^[a-z_-]{1,40}$' "Possible values are text with a maximum length of 40 characters, containing only lowercase letters (a-z), "-" or '_'." +validate_regex "driver.parent-frame" '^[a-z_-]{1,40}$' # validate driver.camera-model VALID_CAMERA_MODEL_OPTIONS=("OAK-D" "OAK-D-LITE") @@ -52,38 +45,13 @@ validate_float "driver.cam-roll" validate_float "driver.cam-pitch" validate_float "driver.cam-yaw" -# validate driver.params-file -validate_path "driver.params-file" - -export LD_LIBRARY_PATH=$SNAP/usr/lib/$(uname -m)-linux-gnu/pulseaudio:$SNAP/usr/lib/$(uname -m)-linux-gnu/blas:$SNAP/usr/lib/$(uname -m)-linux-gnu/lapack:$LD_LIBRARY_PATH +# export LD_LIBRARY_PATH=$SNAP/usr/lib/$(uname -m)-linux-gnu/pulseaudio:$SNAP/usr/lib/$(uname -m)-linux-gnu/blas:$SNAP/usr/lib/$(uname -m)-linux-gnu/lapack:$LD_LIBRARY_PATH -export FFMPEG_ENCODING=$(snapctl get driver.ffmpeg-image-transport.encoding) - -# Check if FFMPEG_ENCODING is set -if [ -n "$FFMPEG_ENCODING" ]; then - # Run ffmpeg -codecs and check if the codec is available - if ! ffmpeg -encoders 2>/dev/null | awk '{print $2}' | grep -q "$FFMPEG_ENCODING"; then - log_and_echo "Error: Codec $FFMPEG_ENCODING is not available:" - log_and_echo "Find available codecs here: $SNAP_COMMON/ffmpeg_codecs.txt" - ffmpeg -encoders 2>/dev/null | awk '/^ V/ {print $0}' > $SNAP_COMMON/ffmpeg_codecs.txt - exit 1 - fi +# validate driver.camera-params +validate_config_param "driver.camera-params" "camera-params-VALUE.yaml" - cp $SNAP_COMMON/ffmpeg_params_template.yaml $SNAP_COMMON/ffmpeg_params.yaml - yq -i './**.ros__parameters.ffmpeg_image_transport = {}' $SNAP_COMMON/ffmpeg_params.yaml - - # Get all options in JSON format - OPTIONS=$(snapctl get driver.ffmpeg-image-transport) - keys=$(echo $OPTIONS | yq '. | to_entries | .[].key') - for key in $keys; do - export FFMPEG_KEY=$key - export FFMPEG_VALUE=$(snapctl get driver.ffmpeg-image-transport.$FFMPEG_KEY) - yq -i './**.ros__parameters.ffmpeg_image_transport += {env(FFMPEG_KEY): env(FFMPEG_VALUE)}' $SNAP_COMMON/ffmpeg_params.yaml - done -else - cp $SNAP_COMMON/ffmpeg_params_template.yaml $SNAP_COMMON/ffmpeg_params.yaml - yq -i './**.ros__parameters.ffmpeg_image_transport = {}' $SNAP_COMMON/ffmpeg_params.yaml -fi +# validate driver.ffmpeg-params +validate_config_param "driver.ffmpeg-params" "ffmpeg-params-VALUE.yaml" $SNAP/usr/bin/configure_hook_ros.sh diff --git a/snap/hooks/connect-plug-ros-humble-ros-base b/snap/hooks/connect-plug-ros-humble-ros-base deleted file mode 100755 index 39d5c18..0000000 --- a/snap/hooks/connect-plug-ros-humble-ros-base +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -e - -# now we can start the service -# if snapctl services ${SNAP_NAME}.${SNAP_NAME} | grep -q inactive; then -# snapctl start --enable ${SNAP_NAME}.${SNAP_NAME} 2>&1 || true -# fi - -logger -t ${SNAP_NAME} "Plug 'ros-humble-ros-base' connected" \ No newline at end of file diff --git a/snap/hooks/disconnect-plug-ros-humble-ros-base b/snap/hooks/disconnect-plug-ros-humble-ros-base deleted file mode 100755 index bc2c60d..0000000 --- a/snap/hooks/disconnect-plug-ros-humble-ros-base +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -e - -logger -t ${SNAP_NAME} "Plug 'ros-humble-ros-base' disconnected" -snapctl stop --disable ${SNAP_NAME}.daemon 2>&1 || true diff --git a/snap/hooks/install b/snap/hooks/install index b000830..3800fba 100755 --- a/snap/hooks/install +++ b/snap/hooks/install @@ -14,10 +14,8 @@ snapctl set driver.cam-pos-z=0.0 snapctl set driver.cam-roll=0.0 snapctl set driver.cam-pitch=0.0 snapctl set driver.cam-yaw=0.0 -snapctl set driver.params-file=$SNAP_COMMON/depthai_params.yaml -snapctl set driver.ffmpeg-image-transport.encoding=libx264 -snapctl set driver.ffmpeg-image-transport.preset=ultrafast -snapctl set driver.ffmpeg-image-transport.tune=zerolatency +snapctl set driver.camera-params=default +snapctl set driver.ffmpeg-params=default if ! snapctl is-connected raw-usb; then log "Plug 'raw-usb' isn't connected, please run:" diff --git a/snap/local/depthai_params.yaml b/snap/local/camera-params-default.yaml similarity index 100% rename from snap/local/depthai_params.yaml rename to snap/local/camera-params-default.yaml diff --git a/snap/local/ffmpeg_params_template.yaml b/snap/local/ffmpeg-params-default.yaml similarity index 100% rename from snap/local/ffmpeg_params_template.yaml rename to snap/local/ffmpeg-params-default.yaml diff --git a/snap/local/launcher.sh b/snap/local/launcher.sh index ecf3625..9dbcc1f 100755 --- a/snap/local/launcher.sh +++ b/snap/local/launcher.sh @@ -15,7 +15,7 @@ OPTIONS=( cam-roll cam-pitch cam-yaw - params-file + # params-file ) LAUNCH_OPTIONS="" @@ -28,9 +28,21 @@ for OPTION in "${OPTIONS[@]}"; do fi done +# Check if ros.namespace is set and not empty +ROS_NAMESPACE="$(snapctl get ros.namespace)" +if [ -n "${ROS_NAMESPACE}" ]; then + LAUNCH_OPTIONS+="namespace:=${ROS_NAMESPACE} " +fi + +CAMERA_PARAMS="$(snapctl get driver.camera-params)" +LAUNCH_OPTIONS+="params_file:=${SNAP_COMMON}/camera-params-${CAMERA_PARAMS}.yaml " + +FFMPEG_PARAMS="$(snapctl get driver.ffmpeg-params)" +LAUNCH_OPTIONS+="ffmpeg_params_file:=${SNAP_COMMON}/ffmpeg-params-${FFMPEG_PARAMS}.yaml " + if [ "${LAUNCH_OPTIONS}" ]; then - # watch the log with: "journalctl -t husarion-depthai" + # watch the log with: "journalctl -t husarion-astra" log_and_echo "Running with options: ${LAUNCH_OPTIONS}" fi -ros2 launch $SNAP/usr/bin/depthai.launch.py ${LAUNCH_OPTIONS} ffmpeg_params_file:=$SNAP_COMMON/ffmpeg_params.yaml +ros2 launch $SNAP/usr/bin/depthai.launch.py ${LAUNCH_OPTIONS} diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index b59678a..1327268 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -31,21 +31,13 @@ description: | * cam-roll: `0.0` * cam-pitch: `0.0` * cam-yaw: `0.0` - * params-file: `$SNAP_COMMON/depthai_params.yaml` - * ffmpeg-image-transport.encoding: `libx264` - * ffmpeg-image-transport.preset: `ultrafast` - * ffmpeg-image-transport.tune: `zerolatency` - + * camera-params: `default` - Sets the camera parameters based on `/var/snap/husarion-depthai/common/camera-params-.yaml` + * ffmpeg-params: `default` - Sets the FFMPEG parameters based on `/var/snap/husarion-camera/common/ffmpeg-params-.yaml` + To set the parameters, use the snap set command, e.g., snap set husarion-depthai driver.namespace=robot - Default values for `ffmpeg-image-transport`: - - * encoding: `libx264` - * preset: `ultrafast` - * tune: `zerolatency` - grade: stable confinement: strict base: core22 @@ -54,14 +46,6 @@ contact: https://github.com/husarion/depthai-snap/issues issues: https://github.com/husarion/depthai-snap/issues website: https://husarion.com/ -architectures: - - build-on: amd64 - build-for: amd64 - # - build-on: amd64 - # build-for: arm64 - - build-on: arm64 - build-for: arm64 - slots: shm-slot: interface: shared-memory @@ -106,16 +90,12 @@ apps: start: command: usr/bin/start_launcher.sh + restart: + command: usr/bin/restart_launcher.sh + stop: command: usr/bin/stop_launcher.sh - image-view: - command: usr/bin/image_view_launcher.sh - command-chain: [usr/bin/ros_setup.sh] - plugs: [network, network-bind, shm-plug, desktop, desktop-legacy, wayland, unity7, opengl] - slots: [shm-slot] - extensions: [ros2-humble-ros-base] - parts: husarion-depthai: @@ -138,14 +118,6 @@ parts: craftctl set version="$version" craftctl set grade="stable" - image-view: - plugin: nil - stage-packages: - - ros-humble-image-view - - libcanberra-gtk-module - - libcanberra-gtk3-module - - libglu1-mesa - local-files: plugin: dump source: snap/local/ @@ -159,7 +131,7 @@ parts: husarion-snap-common: plugin: dump source: https://github.com/husarion/husarion-snap-common - source-branch: "0.3.0" + source-branch: "0.5.0" source-type: git build-environment: - YQ_VERSION: "v4.35.1" diff --git a/snapcraft_template.yaml.jinja2 b/snapcraft_template.yaml.jinja2 new file mode 100644 index 0000000..e5f9f08 --- /dev/null +++ b/snapcraft_template.yaml.jinja2 @@ -0,0 +1,151 @@ +name: husarion-depthai +adopt-info: husarion-depthai +license: Apache-2.0 +summary: OAK-x cameras driver for Husarion robots +icon: snap/gui/icon.png +description: | + The `husarion-depthai` snap contains all the necessary software to bring the OAK-x cameras up. + + **Parameters** + + The snap provides the following configurable parameters (`param name`: `default value`): + + * `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/husarion-depthai/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: + + * name: `oak` + * parent-frame: `oak-d-base-frame` + * camera-model: `OAK-D` + * cam-pos-x: `0.0` + * cam-pos-y: `0.0` + * cam-pos-z: `0.0` + * cam-roll: `0.0` + * cam-pitch: `0.0` + * cam-yaw: `0.0` + * camera-params: `default` - Sets the camera parameters based on `/var/snap/husarion-depthai/common/camera-params-.yaml` + * ffmpeg-params: `default` - Sets the FFMPEG parameters based on `/var/snap/husarion-camera/common/ffmpeg-params-.yaml` + + To set the parameters, use the snap set command, e.g., + + snap set husarion-depthai driver.namespace=robot + +grade: stable +confinement: strict +base: {{ 'core22' if ros_distro == 'humble' else 'core24' }} + +contact: https://github.com/husarion/depthai-snap/issues +issues: https://github.com/husarion/depthai-snap/issues +website: https://husarion.com/ + +slots: + shm-slot: + interface: shared-memory + write: ['*'] # paths are relative to /dev/shm + # c189-slot: + # interface: custom-device + # custom-device: c189 + # files: + # write: + # - /run/udev/data/c189:* + +plugs: + shm-plug: + interface: shared-memory + shared-memory: shm-slot + private: false + + # c189-plug: + # interface: custom-device + # custom-device: c189 + +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-{{ ros_distro }}-ros-base] + + husarion-depthai: + 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, system-observe, hardware-observe, network-control, network-observe, camera, browser-support] + # block-devices, + slots: [shm-slot] + extensions: [ros2-{{ ros_distro }}-ros-base] + + start: + command: usr/bin/start_launcher.sh + + restart: + command: usr/bin/restart_launcher.sh + + stop: + command: usr/bin/stop_launcher.sh + +parts: + + husarion-depthai: + plugin: nil + stage-packages: + - ros-{{ ros_distro }}-depthai-ros + - ros-{{ ros_distro }}-image-transport + - ros-{{ ros_distro }}-image-transport-plugins + # https://index.ros.org/p/ffmpeg_image_transport/github-ros-misc-utilities-ffmpeg_image_transport/#humble + - ros-{{ ros_distro }}-ffmpeg-image-transport + - ffmpeg + - ros-{{ ros_distro }}-cv-bridge + # needed to run ffmpeg without errors: + - libpulse-dev + - libblas3 + - libjpeg-turbo8-dev + override-stage: | + craftctl default + version="$(apt-cache policy ros-{{ ros_distro }}-depthai-ros-driver | 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/ + '*.yaml': usr/share/husarion-depthai/config/ + # '*.xml': usr/share/husarion-depthai/config/ + # '*.json': usr/share/husarion-depthai/config/ + + 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