Comments (2)
Hi, since by default depthai_ros_driver
is loaded as a Component(shared library), to use custom nodes you also need to "load" them from a shared library so that they retain their identity (without that, they are loaded as a BaseNode class and that slices off overriden virtual functions, which causes segfault when the driver tries to call them).
A quick test example to mitigate that:
- In
rgb_test.cpp
, add following line:
extern "C" {
std::unique_ptr<depthai_ros_driver::dai_nodes::BaseNode> create(const std::string& daiNodeName,
rclcpp::Node* node,
std::shared_ptr<dai::Pipeline> pipeline,
dai::CameraBoardSocket socket,
depthai_ros_driver::dai_nodes::sensor_helpers::ImageSensor sensor,
bool publish) {
return std::make_unique<RGB_test>(daiNodeName, node, pipeline, socket, sensor, publish);
}
}
Then modify the test_pipeline.cpp
to load the library via dlopen
#include "depthai_test_plugin/pipeline/test_base_types.hpp"
#include <dlfcn.h>
#include "depthai/device/Device.hpp"
#include "depthai/pipeline/Pipeline.hpp"
#include "depthai_ros_driver/dai_nodes/base_node.hpp"
#include "depthai_ros_driver/dai_nodes/nn/nn_helpers.hpp"
#include "depthai_ros_driver/dai_nodes/nn/nn_wrapper.hpp"
#include "depthai_ros_driver/dai_nodes/nn/spatial_nn_wrapper.hpp"
#include "depthai_ros_driver/dai_nodes/sensors/imu.hpp"
#include "depthai_ros_driver/dai_nodes/sensors/sensor_helpers.hpp"
#include "depthai_test_plugin/dai_nodes/sensors/rgb_test.hpp"
#include "depthai_ros_driver/dai_nodes/sensors/rgb.hpp"
#include "depthai_ros_driver/dai_nodes/stereo.hpp"
#include "depthai_ros_driver/pipeline/base_pipeline.hpp"
#include "depthai_ros_driver/utils.hpp"
#include "rclcpp/node.hpp"
using RGB_test_creator_t = std::function<std::unique_ptr<depthai_ros_driver::dai_nodes::BaseNode>(const std::string &,
rclcpp::Node *,
std::shared_ptr<dai::Pipeline>,
dai::CameraBoardSocket,
depthai_ros_driver::dai_nodes::sensor_helpers::ImageSensor,
bool)>;
using RGB_test_raw_creator_t = std::unique_ptr<depthai_ros_driver::dai_nodes::BaseNode> (*)(const std::string &,
rclcpp::Node *,
std::shared_ptr<dai::Pipeline>,
dai::CameraBoardSocket,
depthai_ros_driver::dai_nodes::sensor_helpers::ImageSensor,
bool);
namespace depthai_test_plugin
{
namespace pipeline_gen
{
std::vector<std::unique_ptr<depthai_ros_driver::dai_nodes::BaseNode>> RGB_test_pipeline::createPipeline(rclcpp::Node *node,
std::shared_ptr<dai::Device> device,
std::shared_ptr<dai::Pipeline> pipeline,
const std::string &nnType)
{
auto sensorName = device->getCameraSensorNames().at(dai::CameraBoardSocket::CAM_A);
std::vector<std::unique_ptr<depthai_ros_driver::dai_nodes::BaseNode>> daiNodes;
std::vector<depthai_ros_driver::dai_nodes::sensor_helpers::ImageSensor>::iterator sensorIt =
std::find_if(depthai_ros_driver::dai_nodes::sensor_helpers::availableSensors.begin(), depthai_ros_driver::dai_nodes::sensor_helpers::availableSensors.end(), [&sensorName](const depthai_ros_driver::dai_nodes::sensor_helpers::ImageSensor &s)
{ return s.name == sensorName; });
if (sensorIt == depthai_ros_driver::dai_nodes::sensor_helpers::availableSensors.end())
{
RCLCPP_ERROR(node->get_logger(), "Sensor %s not supported!", sensorName.c_str());
throw std::runtime_error("Sensor not supported!");
}
void *handle = dlopen("libdepthai_test_plugin.so", RTLD_LAZY);
if (!handle)
{
throw std::runtime_error(dlerror());
}
dlerror(); //
RGB_test_raw_creator_t raw_creator = reinterpret_cast<RGB_test_raw_creator_t>(dlsym(handle, "create"));
RGB_test_creator_t creator = raw_creator;
const char *dlsym_error = dlerror();
if (dlsym_error)
{
std::cerr << "Cannot load symbol 'create': " << dlsym_error << '\n';
dlclose(handle);
throw std::runtime_error(dlsym_error);
}
auto rgb = creator("rgb", node, pipeline, dai::CameraBoardSocket::CAM_A, (*sensorIt), true);
dlopen("libdepthai_test_plugin.so", RTLD_LAZY);
daiNodes.push_back(std::move(rgb));
return daiNodes;
}
}
}
#include <pluginlib/class_list_macros.hpp>
PLUGINLIB_EXPORT_CLASS(depthai_test_plugin::pipeline_gen::RGB_test_pipeline, depthai_ros_driver::pipeline_gen::BasePipeline)
from depthai-ros.
That fixed it for me, thank you.
from depthai-ros.
Related Issues (20)
- 'camera.yaml' parameters not being used when launch 'camera.launch.py' HOT 2
- [BUG] ROS Documentation link goes to 404 Error page HOT 4
- [Performance] Oak-D camera not able to reach desired publish rates HOT 4
- Wants depthai-core v2.24.0 in ROS repository HOT 3
- Option to sync raw left/right streams HOT 2
- Mapping approaches for spatial object detection HOT 2
- [BUG] {colcon build fail - opencv version stderr} HOT 5
- [BUG] rgbd_pcl inconsistent Resolution configuration HOT 2
- [BUG] Right stereo camera is not detected with OAK-D SR PoE HOT 2
- How can I compress the camera data ? HOT 6
- [BUG] Depthai version in ROS Humble repos does not work with OAK-D SR PoE HOT 1
- When launch the OAK-D LR camera, it stops other USB device from working HOT 3
- exit code -11, cmd when running stereo_inertial_node on RPI4 HOT 2
- [BUG] {camera.launch.py not working} HOT 7
- URDF Plugin HOT 1
- [BUG] Cameras on different subnets cannot be launched HOT 2
- [Feature-Request] ROS Support for Sensor S5K33D HOT 2
- [BUG] Directions for low bandwidth for POE cameras are not easy to find from error message HOT 2
- [BUG] {Max 250hz IMU publish rate with rotation vector rate active} HOT 5
- Got a particular warning and 3D map didn't show up when trying to launch the rtabmap.launch.py with low_bandwidth parameter is set to be true HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from depthai-ros.