Skip to content

Commit

Permalink
Pipeline generation as plugins (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serafadam authored Jun 16, 2023
1 parent 40dec09 commit e8defa1
Show file tree
Hide file tree
Showing 38 changed files with 538 additions and 274 deletions.
15 changes: 15 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Overview
Author:

## Issue
Issue link (if present):
Issue description:
Related PRs

## Changes
ROS distro:
List of changes:

## Testing
Hardware used:
Depthai library version:
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,26 @@ As for the parameters themselves, there are a few crucial ones that decide on ho
* `Depth` - Publishes only depth stream, no NN available
* `CamArray` - Publishes streams for all detected sensors, no NN available
This tells the camera whether it should load stereo components. Default set to `RGBD`.
It is also possible to create a custom pipeline since all types are defined as plugins.

To do that, you can create a custom package (let's say `test_plugins`), create an executable in that package (`test_plugins.cpp`). Inside that file, define a cusom plugin that inherits from `depthai_ros_driver::pipeline_gen::BasePipeline` and overrides `createPipeline` method.

After that export plugin, for example:

```c++
#include <pluginlib/class_list_macros.hpp>
PLUGINLIB_EXPORT_CLASS(test_plugins::Test, depthai_ros_driver::pipeline_gen::BasePipeline)
```
Add plugin definition:
```xml
<library path="test_plugins">
<class type="test_plugins::Test" base_class_type="depthai_ros_driver::pipeline_gen::BasePipeline">
<description>Test Pipeline.</description>
</class>
</library>
```

Now you can use created plugin as pipeline, just set `camera.i_pipeline_type` to `test_plugins::Test`.

* `camera.i_nn_type` can be either `none`, `rgb` or `spatial`. This is responsible for whether the NN that we load should also take depth information (and for example provide detections in 3D format). Default set to `spatial`
* `camera.i_mx_id`/`camera.i_ip`/`camera.i_usb_port_id` are for connecting to a specific camera. If not set, it automatically connects to the next available device. You can get those parameters from logs by running the default launch file.
Expand Down
10 changes: 9 additions & 1 deletion depthai-ros/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
Changelog for package depthai-ros
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2.7.2 (20230-5-08)
2.7.3 (20230-06-16)

* Pipeline generation as a plugin
* Fixed bounding box generation issue
* Stereo rectified streams publishing
* Camera trigger mechanisms
* Brightness filter

2.7.2 (20230-05-08)
* IMU improvements

2.7.1 (2023-03-29)
Expand Down
2 changes: 1 addition & 1 deletion depthai-ros/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10.2) # CMake version in Ubuntu 18.04 LTS

project(depthai-ros VERSION 2.7.2 LANGUAGES CXX C)
project(depthai-ros VERSION 2.7.3 LANGUAGES CXX C)

set(CMAKE_CXX_STANDARD 14)

Expand Down
2 changes: 1 addition & 1 deletion depthai-ros/package.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<package format="3">
<name>depthai-ros</name>
<version>2.7.2</version>
<version>2.7.3</version>
<description>The depthai-ros package</description>

<!-- One maintainer tag required, multiple allowed, one person per tag -->
Expand Down
2 changes: 1 addition & 1 deletion depthai_bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.10.2) # CMake version in Ubuntu 18.04 LTS
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

project(depthai_bridge VERSION 2.7.2 LANGUAGES CXX C)
project(depthai_bridge VERSION 2.7.3 LANGUAGES CXX C)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
15 changes: 11 additions & 4 deletions depthai_bridge/include/depthai_bridge/ImuConverter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class ImuConverter {
double angular_velocity_cov = 0.0,
double rotation_cov = 0.0,
double magnetic_field_cov = 0.0,
bool enable_rotation = false);
bool enable_rotation = false,
bool getBaseDeviceTimestamp = false);
~ImuConverter();
void toRosMsg(std::shared_ptr<dai::IMUData> inData, std::deque<ImuMsgs::Imu>& outImuMsgs);
void toRosDaiMsg(std::shared_ptr<dai::IMUData> inData, std::deque<depthai_ros_msgs::msg::ImuWithMagneticField>& outImuMsgs);
Expand Down Expand Up @@ -112,6 +113,7 @@ class ImuConverter {
ImuSyncMethod _syncMode;
std::chrono::time_point<std::chrono::steady_clock> _steadyBaseTime;
rclcpp::Time _rosBaseTime;
bool _getBaseDeviceTimestamp;

void fillImuMsg(dai::IMUReportAccelerometer report, ImuMsgs::Imu& msg);
void fillImuMsg(dai::IMUReportGyroscope report, ImuMsgs::Imu& msg);
Expand All @@ -124,15 +126,15 @@ class ImuConverter {
void fillImuMsg(dai::IMUReportMagneticField report, depthai_ros_msgs::msg::ImuWithMagneticField& msg);

template <typename I, typename S, typename T, typename F, typename M>
void CreateUnitMessage(I first, S second, T third, F fourth, M& msg, dai::Timestamp timestamp) {
void CreateUnitMessage(I first, S second, T third, F fourth, M& msg, std::chrono::_V2::steady_clock::time_point timestamp) {
fillImuMsg(first, msg);
fillImuMsg(second, msg);
fillImuMsg(third, msg);
fillImuMsg(fourth, msg);

msg.header.frame_id = _frameName;

msg.header.stamp = getFrameTime(_rosBaseTime, _steadyBaseTime, timestamp.get());
msg.header.stamp = getFrameTime(_rosBaseTime, _steadyBaseTime, timestamp);
}

template <typename I, typename S, typename T, typename F, typename M>
Expand Down Expand Up @@ -162,7 +164,12 @@ class ImuConverter {
const double alpha = diff.count() / dt;
I interp = lerpImu(interp0, interp1, alpha);
M msg;
CreateUnitMessage(interp, currSecond, currThird, currFourth, msg, currSecond.timestamp);
std::chrono::_V2::steady_clock::time_point tstamp;
if(_getBaseDeviceTimestamp)
tstamp = currSecond.getTimestampDevice();
else
tstamp = currSecond.getTimestamp();
CreateUnitMessage(interp, currSecond, currThird, currFourth, msg, tstamp);
imuMsgs.push_back(msg);
second.pop_front();
third.pop_front();
Expand Down
2 changes: 1 addition & 1 deletion depthai_bridge/package.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<package format="3">
<name>depthai_bridge</name>
<version>2.7.2</version>
<version>2.7.3</version>
<description>The depthai_bridge package</description>

<maintainer email="[email protected]">Sachin Guruswamy</maintainer>
Expand Down
22 changes: 18 additions & 4 deletions depthai_bridge/src/ImuConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ ImuConverter::ImuConverter(const std::string& frameName,
double angular_velocity_cov,
double rotation_cov,
double magnetic_field_cov,
bool enable_rotation)
bool enable_rotation,
bool getBaseDeviceTimestamp)
: _frameName(frameName),
_syncMode(syncMode),
_linear_accel_cov(linear_accel_cov),
Expand All @@ -22,7 +23,8 @@ ImuConverter::ImuConverter(const std::string& frameName,
_magnetic_field_cov(magnetic_field_cov),
_enable_rotation(enable_rotation),
_sequenceNum(0),
_steadyBaseTime(std::chrono::steady_clock::now()) {
_steadyBaseTime(std::chrono::steady_clock::now()),
_getBaseDeviceTimestamp(getBaseDeviceTimestamp) {
_rosBaseTime = rclcpp::Clock().now();
}

Expand Down Expand Up @@ -91,7 +93,13 @@ void ImuConverter::toRosMsg(std::shared_ptr<dai::IMUData> inData, std::deque<Imu
auto rot = inData->packets[i].rotationVector;
auto magn = inData->packets[i].magneticField;
ImuMsgs::Imu msg;
CreateUnitMessage(accel, gyro, rot, magn, msg, accel.timestamp);
std::chrono::_V2::steady_clock::time_point tstamp;
if(_getBaseDeviceTimestamp)
tstamp = accel.getTimestampDevice();
else
tstamp = accel.getTimestamp();

CreateUnitMessage(accel, gyro, rot, magn, msg, tstamp);
outImuMsgs.push_back(msg);
}
}
Expand All @@ -107,7 +115,13 @@ void ImuConverter::toRosDaiMsg(std::shared_ptr<dai::IMUData> inData, std::deque<
auto rot = inData->packets[i].rotationVector;
auto magn = inData->packets[i].magneticField;
depthai_ros_msgs::msg::ImuWithMagneticField msg;
CreateUnitMessage(accel, gyro, rot, magn, msg, accel.timestamp);
std::chrono::_V2::steady_clock::time_point tstamp;
if(_getBaseDeviceTimestamp)
tstamp = accel.getTimestampDevice();
else
tstamp = accel.getTimestamp();

CreateUnitMessage(accel, gyro, rot, magn, msg, tstamp);
outImuMsgs.push_back(msg);
}
}
Expand Down
2 changes: 1 addition & 1 deletion depthai_descriptions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.8)
project(depthai_descriptions VERSION 2.7.2)
project(depthai_descriptions VERSION 2.7.3)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
Expand Down
33 changes: 0 additions & 33 deletions depthai_descriptions/launch/urdf.launch

This file was deleted.

2 changes: 1 addition & 1 deletion depthai_descriptions/package.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<package format="3">
<name>depthai_descriptions</name>
<version>2.7.2</version>
<version>2.7.3</version>
<description>The depthai_descriptions package</description>

<maintainer email="[email protected]">Sachin Guruswamy</maintainer>
Expand Down
1 change: 0 additions & 1 deletion depthai_descriptions/urdf/include/depthai_macro.urdf.xacro
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<xacro:property name="imu_y" value="0" />
</xacro:if>


<!-- base_link of the sensor-->
<link name="${base_frame}"/>

Expand Down
Binary file added depthai_descriptions/urdf/models/OAK-D-PRO-W.stl
Binary file not shown.
2 changes: 1 addition & 1 deletion depthai_examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.10.2) # CMake version in Ubuntu 18.04 LTS
project(depthai_examples VERSION 2.7.2 LANGUAGES CXX C)
project(depthai_examples VERSION 2.7.3 LANGUAGES CXX C)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
2 changes: 2 additions & 0 deletions depthai_examples/launch/stereo_inertial_node.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def generate_launch_description():
'cam_yaw',
default_value=cam_yaw,
description='Yaw orientation of the camera with respect to the base frame.')


declare_lrcheck_cmd = DeclareLaunchArgument(
'lrcheck',
Expand Down Expand Up @@ -298,6 +299,7 @@ def generate_launch_description():
'enableRviz',
default_value=enableRviz,
description='When True create a RVIZ window.')



urdf_launch = IncludeLaunchDescription(
Expand Down
2 changes: 1 addition & 1 deletion depthai_examples/package.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<package format="3">
<name>depthai_examples</name>
<version>2.7.2</version>
<version>2.7.3</version>
<description>The depthai_examples package</description>

<!-- One maintainer tag required, multiple allowed, one person per tag -->
Expand Down
2 changes: 1 addition & 1 deletion depthai_filters/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.8)
project(depthai_filters VERSION 2.7.2 LANGUAGES CXX C)
project(depthai_filters VERSION 2.7.3 LANGUAGES CXX C)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
Expand Down
2 changes: 1 addition & 1 deletion depthai_filters/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>depthai_filters</name>
<version>2.7.2</version>
<version>2.7.3</version>
<description>Depthai filters package</description>
<maintainer email="[email protected]">Adam Serafin</maintainer>
<license>MIT</license>
Expand Down
29 changes: 21 additions & 8 deletions depthai_ros_driver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.22)
project(depthai_ros_driver VERSION 2.7.2)
project(depthai_ros_driver VERSION 2.7.3)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_BUILD_SHARED_LIBS ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand Down Expand Up @@ -52,6 +52,7 @@ depthai
rclcpp
rclcpp_components
std_srvs
pluginlib
)


Expand Down Expand Up @@ -103,7 +104,8 @@ target_link_libraries(
add_library(
${PROJECT_NAME} SHARED
src/camera.cpp
src/pipeline_generator.cpp
src/pipeline/pipeline_generator.cpp
src/pipeline/base_types.cpp
)

ament_target_dependencies(${PROJECT_NAME} ${CAM_DEPS})
Expand All @@ -116,18 +118,28 @@ target_link_libraries(


rclcpp_components_register_nodes(${PROJECT_NAME} "${PROJECT_NAME}::Camera")
pluginlib_export_plugin_description_file(${PROJECT_NAME} plugins.xml)
ament_export_include_directories(include)

ament_export_targets(${PROJECT_NAME}Targets HAS_LIBRARY_TARGET)
ament_export_libraries(${PROJECT_NAME})
ament_export_dependencies(${COMMON_DEPS} ${SENSOR_DEPS} ${NN_DEPS} ${CAM_DEPS})

install(DIRECTORY launch config DESTINATION share/${PROJECT_NAME})

install(
TARGETS
${PROJECT_NAME} ${COMMON_LIB_NAME} ${SENSOR_LIB_NAME} ${NN_LIB_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
install(TARGETS ${PROJECT_NAME} ${SENSOR_LIB_NAME}
${NN_LIB_NAME}
${COMMON_LIB_NAME}
EXPORT ${PROJECT_NAME}Targets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)

install(EXPORT ${PROJECT_NAME}Targets
DESTINATION share/${PROJECT_NAME}/cmake)

ament_python_install_package(${PROJECT_NAME})
# Install Python executables
install(
Expand All @@ -139,6 +151,7 @@ install(
ament_export_include_directories(
include
)

install(
DIRECTORY include/
DESTINATION include
Expand Down
Loading

0 comments on commit e8defa1

Please sign in to comment.