From cf47e467fd9192c089b2611e66b643bd840bd5eb Mon Sep 17 00:00:00 2001 From: vicmassy Date: Mon, 29 Jan 2024 12:43:31 +0100 Subject: [PATCH 1/7] Prepare for ROS Index --- psdk_wrapper/CMakeLists.txt | 35 +++++++++++++++++++++++++++-------- psdk_wrapper/package.xml | 3 +++ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/psdk_wrapper/CMakeLists.txt b/psdk_wrapper/CMakeLists.txt index daa241c0..9c5b9a21 100644 --- a/psdk_wrapper/CMakeLists.txt +++ b/psdk_wrapper/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.14) project(psdk_wrapper) SET(BUILD_SHARED_LIBS ON) @@ -31,10 +31,29 @@ find_package(tf2_ros REQUIRED) find_package(psdk_interfaces REQUIRED) find_package(std_srvs REQUIRED) +# FetchContent module +include(FetchContent) + +# Declare the content to fetch +FetchContent_Declare( + Payload_SDK + GIT_REPOSITORY https://github.com/dji-sdk/Payload-SDK.git + GIT_TAG 3.5 +) + +FetchContent_GetProperties(Payload_SDK) +if(NOT Payload_SDK_POPULATED) + FetchContent_Populate(Payload_SDK) + message(STATUS "Payload_SDK_SOURCE_DIR: ${payload_sdk_SOURCE_DIR}") +endif() + +# Set the path to the fetched content +set(PSDK_PATH ${payload_sdk_SOURCE_DIR}) + +message(STATUS "PSDK_PATH: ${PSDK_PATH}") + # Add path to FindFFMPEG.cmake and FindLIBUSB.cmake files -set(PSDK_PATH ${PROJECT_SOURCE_DIR}/../../Payload-SDK) -set(CMAKE_MODULE_PATH -${PSDK_PATH}/samples/sample_c++/platform/linux/common/3rdparty) +set(CMAKE_MODULE_PATH ${PSDK_PATH}/samples/sample_c++/platform/linux/common/3rdparty) find_package(FFMPEG REQUIRED) find_package(LIBUSB REQUIRED) @@ -75,9 +94,9 @@ if (FFMPEG_FOUND) OUTPUT_VARIABLE ffmpeg_version_psdk_libput OUTPUT_STRIP_TRAILING_WHITESPACE ) - string(REGEX MATCH "version.*Copyright" ffmpeg_version_line ${ffmpeg_version_psdk_libput}) - string(REGEX MATCH " .* " ffmpeg_version ${ffmpeg_version_line}) - string(REGEX MATCH "^ 5.*$" ffmpeg_major_version ${ffmpeg_version}) + string(REGEX MATCH "version.*Copyright" ffmpeg_version_line "${ffmpeg_version_psdk_libput}") + string(REGEX MATCH " .* " ffmpeg_version "${ffmpeg_version_line}") + string(REGEX MATCH "^ 5.*$" ffmpeg_major_version "${ffmpeg_version}") if (HEAD${ffmpeg_major_version} STREQUAL "HEAD") message(STATUS " - Version: ${ffmpeg_version}") @@ -108,7 +127,7 @@ include_directories(${FFMPEG_INCLUDE_DIR}) include_directories(${DJI_OSAL_PATH}) include_directories(${DJI_HAL_PATH}) include_directories(${DJI_STREAMING_PATH}) -include_directories(${PROJECT_SOURCE_DIR}/../../Payload-SDK/psdk_lib/include) +include_directories(${PSDK_PATH}/psdk_lib/include) include_directories(include) include_directories(src/3rdparty) diff --git a/psdk_wrapper/package.xml b/psdk_wrapper/package.xml index b178e39e..eccd4f6b 100644 --- a/psdk_wrapper/package.xml +++ b/psdk_wrapper/package.xml @@ -13,6 +13,9 @@ ament_lint_auto ament_lint_common + ffmpeg-dev + libusb-1.0-dev + libopus-dev rclcpp rclcpp_lifecycle tf2 From d72e0f62472ed26a5cc2bed7410d1a5985979ebb Mon Sep 17 00:00:00 2001 From: vicmassy Date: Mon, 29 Jan 2024 12:44:36 +0100 Subject: [PATCH 2/7] Update create_debians --- debian/create_debians.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/debian/create_debians.sh b/debian/create_debians.sh index 40a149c8..42aea475 100755 --- a/debian/create_debians.sh +++ b/debian/create_debians.sh @@ -14,14 +14,12 @@ curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null - apt update -apt install -y --no-install-recommends python3-pip python3-bloom python3-catkin-pkg dpkg-dev debhelper dh-python libopus-dev ffmpeg libavcodec-dev libavformat-dev libavfilter-dev libusb-1.0-0-dev -ln -snf /usr/lib/x86_64-linux-gnu/libopus.a /usr/local/lib +apt install -y --no-install-recommends python3-pip python3-bloom python3-catkin-pkg dpkg-dev debhelper dh-python pip3 install rosdep rosdep init -mv psdk_ros2/debian/50-my-packages.list /etc/ros/rosdep/sources.list.d -mv psdk_ros2/debian/rosdep.yaml / +cp psdk_ros2/debian/50-my-packages.list /etc/ros/rosdep/sources.list.d +cp psdk_ros2/debian/rosdep.yaml / # store the current dir CUR_DIR=$(pwd) From 69755efa96a28cf47a1c871e1d1de77bc404229e Mon Sep 17 00:00:00 2001 From: vicmassy Date: Mon, 29 Jan 2024 12:48:53 +0100 Subject: [PATCH 3/7] Add git to industrial ci --- .github/workflows/industrial_ci.yaml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/industrial_ci.yaml b/.github/workflows/industrial_ci.yaml index 61d14629..f762a327 100644 --- a/.github/workflows/industrial_ci.yaml +++ b/.github/workflows/industrial_ci.yaml @@ -11,16 +11,9 @@ jobs: - uses: actions/checkout@v4 with: path: psdk_ros2 - - uses: actions/checkout@v4 - with: - repository: dji-sdk/Payload-SDK - ref: 3.5 - path: Payload-SDK - uses: 'ros-industrial/industrial_ci@master' env: ROS_DISTRO: humble ROS_REPO: main - ADDITIONAL_DEBS: libopus-dev ffmpeg libavcodec-dev libavformat-dev libavfilter-dev libusb-1.0-0-dev - TARGET_WORKSPACE: '. -Payload-SDK/CMakeLists.txt -Payload-SDK/samples/sample_c -Payload-SDK/samples/sample_c++/platform/linux/manifold2/CMakeLists.txt -Payload-SDK/samples/sample_c++/platform/linux/nvidia_jetson' + ADDITIONAL_DEBS: git NOT_TEST_BUILD: true - # UPSTREAM_WORKSPACE: github:dji-sdk/Payload-SDK#3.5 \ No newline at end of file From e074bdc435862b06fc4ff468725b6594adf3570f Mon Sep 17 00:00:00 2001 From: vicmassy Date: Mon, 29 Jan 2024 13:05:12 +0100 Subject: [PATCH 4/7] Use new ROS CI workflow --- .github/workflows/industrial_ci.yaml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/industrial_ci.yaml b/.github/workflows/industrial_ci.yaml index f762a327..54bd51d9 100644 --- a/.github/workflows/industrial_ci.yaml +++ b/.github/workflows/industrial_ci.yaml @@ -1,19 +1,21 @@ -name: Build +name: ROS2 Build on: pull_request: types: [opened, synchronize, reopened] jobs: - industrial_ci: + ros2_build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: path: psdk_ros2 - - uses: 'ros-industrial/industrial_ci@master' - env: - ROS_DISTRO: humble - ROS_REPO: main - ADDITIONAL_DEBS: git - NOT_TEST_BUILD: true + - uses: ros-tooling/setup-ros@0.7.1 + with: + required-ros-distributions: humble + - uses: ros-tooling/action-ros-ci@0.3.6 + with: + package-name: psdk_interfaces psdk_wrapper + target-ros2-distro: humble + skip-tests: true From 095e36617825e48809831ea4caff38ee2af9fe4f Mon Sep 17 00:00:00 2001 From: vicmassy Date: Mon, 29 Jan 2024 13:05:14 +0100 Subject: [PATCH 5/7] Use new ROS CI workflow --- .github/workflows/{industrial_ci.yaml => ros_build.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{industrial_ci.yaml => ros_build.yaml} (100%) diff --git a/.github/workflows/industrial_ci.yaml b/.github/workflows/ros_build.yaml similarity index 100% rename from .github/workflows/industrial_ci.yaml rename to .github/workflows/ros_build.yaml From 57b533bdd73b3ac6649c36ebf56509fe5973119d Mon Sep 17 00:00:00 2001 From: vicmassy Date: Mon, 29 Jan 2024 14:23:24 +0100 Subject: [PATCH 6/7] Update documentation --- docs/documentation/GettingStarted.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/documentation/GettingStarted.md b/docs/documentation/GettingStarted.md index 6dad6102..4d54cda5 100644 --- a/docs/documentation/GettingStarted.md +++ b/docs/documentation/GettingStarted.md @@ -5,18 +5,20 @@ To use the psdk_ros2 wrapper you will need to create a new workspace in which yo ```bash mkdir -p ~/psdk_ros2_ws/src cd ~/psdk_ros2_ws/src -# Clone the psdk_ros2 wrapper and the Payload-SDK +# Clone the psdk_ros2 wrapper git clone https://github.com/umdlife/psdk_ros2.git -git clone https://github.com/dji-sdk/Payload-SDK.git - -# Checkout the proper version of the Payload-SDK (currently the wrapper is compatible with the latest release v3.5) -cd Payload-SDK -git checkout release/v3.5 # Before building, check the Dependencies section and make sure you have everything installed +# You can also run rosdep to automatically install the dependencies +rosdep update +rosdep keys --from-paths . --ignore-src --rosdistro humble | \ + xargs rosdep resolve --rosdistro humble | \ + awk '/#apt/{getline; print}' > ./rosdep_requirements.txt +sudo apt install -y --no-install-recommends $(cat ./rosdep_requirements.txt) + # Build the code cd ~/psdk_ros2_ws -colcon build --packages-skip entry # Skip the build corresponding to DJI PSDK sample code +colcon build # Launch the node ros2 launch psdk_wrapper wrapper.launch.py From 58b387b26dc26d652c8e7954fdb035bff470ca46 Mon Sep 17 00:00:00 2001 From: biancabnd Date: Mon, 29 Jan 2024 14:46:04 +0100 Subject: [PATCH 7/7] Reorder method call in lifecycle to avoid node crashes + increase nr. of retries for psdk init --- .../include/psdk_wrapper/psdk_wrapper_utils.hpp | 2 +- psdk_wrapper/src/psdk_wrapper.cpp | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/psdk_wrapper/include/psdk_wrapper/psdk_wrapper_utils.hpp b/psdk_wrapper/include/psdk_wrapper/psdk_wrapper_utils.hpp index 9032d4f8..ea9442fe 100644 --- a/psdk_wrapper/include/psdk_wrapper/psdk_wrapper_utils.hpp +++ b/psdk_wrapper/include/psdk_wrapper/psdk_wrapper_utils.hpp @@ -41,7 +41,7 @@ #define CONTROL_DATA_TOPICS_MAX_FREQ 50 #define GOOD_GPS_SIGNAL_LEVEL 5 -#define MAX_NUMBER_OF_RETRIES 3 +#define MAX_NUMBER_OF_RETRIES 5 namespace psdk_ros2 { diff --git a/psdk_wrapper/src/psdk_wrapper.cpp b/psdk_wrapper/src/psdk_wrapper.cpp index 1a758961..94ae5016 100644 --- a/psdk_wrapper/src/psdk_wrapper.cpp +++ b/psdk_wrapper/src/psdk_wrapper.cpp @@ -73,7 +73,6 @@ PSDKWrapper::on_configure(const rclcpp_lifecycle::State &state) { return CallbackReturn::FAILURE; } - initialize_ros_elements(); return CallbackReturn::SUCCESS; } @@ -89,17 +88,22 @@ PSDKWrapper::on_activate(const rclcpp_lifecycle::State &state) if (!init(&user_info)) { + rclcpp::shutdown(); return CallbackReturn::FAILURE; } - activate_ros_elements(); - if (!init_telemetry() || !init_flight_control() || !init_camera_manager() || !init_gimbal_manager() || !init_liveview()) { + rclcpp::shutdown(); return CallbackReturn::FAILURE; } + // Initialize and activate ROS elements only after the DJI modules are + // initialized + initialize_ros_elements(); + activate_ros_elements(); + if (params_.publish_transforms) { publish_static_transforms();