Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions depthai_ros_driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ depthai
depthai_bridge
rclcpp
std_msgs
std_srvs
sensor_msgs
image_transport)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include "depthai_ros_driver/dai_nodes/base_node.hpp"
#include "rclcpp/service.hpp"
#include "std_srvs/srv/trigger.hpp"

namespace dai {
class Pipeline;
Expand Down Expand Up @@ -48,12 +50,15 @@ class RGB : public BaseNode {
std::vector<std::shared_ptr<sensor_helpers::ImagePublisher>> getPublishers() override;

private:
std::shared_ptr<sensor_helpers::ImagePublisher> rgbPub, previewPub;
void triggerStillCB(std_srvs::srv::Trigger::Request::ConstSharedPtr req, std_srvs::srv::Trigger::Response::SharedPtr res);

std::shared_ptr<sensor_helpers::ImagePublisher> rgbPub, previewPub, stillPub;
rclcpp::Service<std_srvs::srv::Trigger>::SharedPtr triggerStillService;
std::shared_ptr<dai::node::ColorCamera> colorCamNode;
std::unique_ptr<param_handlers::SensorParamHandler> ph;
std::shared_ptr<dai::DataInputQueue> controlQ;
std::shared_ptr<dai::node::XLinkIn> xinControl;
std::string ispQName, previewQName, controlQName;
std::string ispQName, previewQName, controlQName, stillQName;
};

} // namespace dai_nodes
Expand Down
41 changes: 41 additions & 0 deletions depthai_ros_driver/src/dai_nodes/sensors/rgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void RGB::setNames() {
ispQName = getName() + "_isp";
previewQName = getName() + "_preview";
controlQName = getName() + "_control";
stillQName = getName() + "_still";
}

void RGB::setXinXout(std::shared_ptr<dai::Pipeline> pipeline) {
Expand All @@ -59,6 +60,9 @@ void RGB::setXinXout(std::shared_ptr<dai::Pipeline> pipeline) {
if(ph->getParam<bool>("i_enable_preview")) {
previewPub = setupOutput(pipeline, previewQName, [&](auto input) { colorCamNode->preview.link(input); });
}
if(ph->getParam<bool>("i_enable_still")) {
stillPub = setupOutput(pipeline, stillQName, [&](auto input) { colorCamNode->still.link(input); });
}
xinControl = pipeline->create<dai::node::XLinkIn>();
xinControl->setStreamName(controlQName);
xinControl->out.link(colorCamNode->inputControl);
Expand Down Expand Up @@ -119,6 +123,31 @@ void RGB::setupQueues(std::shared_ptr<dai::Device> device) {
previewPub->setup(device, convConfig, pubConfig);
};
controlQ = device->getInputQueue(controlQName);
if(ph->getParam<bool>("i_enable_still")) {
auto tfPrefix = getOpticalTFPrefix(getSocketName(static_cast<dai::CameraBoardSocket>(ph->getParam<int>("i_board_socket_id"))));
utils::ImgConverterConfig convConfig;
convConfig.tfPrefix = tfPrefix;
convConfig.getBaseDeviceTimestamp = ph->getParam<bool>("i_get_base_device_timestamp");
convConfig.updateROSBaseTimeOnRosMsg = ph->getParam<bool>("i_update_ros_base_time_on_ros_msg");

Comment on lines +128 to +134

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The encoding option has only effect when i_low_bandwidth is enabled which I purposefully omitted for still output. For raw frames, Image converter always outputs it in BGR color order.

utils::ImgPublisherConfig pubConfig;
pubConfig.daiNodeName = getName();
pubConfig.topicName = "~/" + getName();
pubConfig.lazyPub = ph->getParam<bool>("i_enable_lazy_publisher");
pubConfig.socket = static_cast<dai::CameraBoardSocket>(ph->getParam<int>("i_board_socket_id"));
pubConfig.calibrationFile = ph->getParam<std::string>("i_calibration_file");
pubConfig.rectified = false;
pubConfig.width = ph->getParam<int>("i_still_width");
pubConfig.height = ph->getParam<int>("i_still_height");
pubConfig.maxQSize = ph->getParam<int>("i_max_q_size");
pubConfig.topicSuffix = "/still/image_raw";
pubConfig.flipImage = ph->getParam<bool>("i_flip_published_image");
Comment on lines +142 to +146

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about that. Adding this option would make it so that enabling compression for video output would also enable lossy compression for still output which is often not wanted.


stillPub->setup(device, convConfig, pubConfig);

triggerStillService = getROSNode()->create_service<std_srvs::srv::Trigger>(
"~/" + getName() + "/trigger_still", std::bind(&RGB::triggerStillCB, this, std::placeholders::_1, std::placeholders::_2));
};
}

void RGB::closeQueues() {
Expand All @@ -128,6 +157,10 @@ void RGB::closeQueues() {
previewPub->closeQueue();
}
}
if(ph->getParam<bool>("i_enable_still")) {
triggerStillService.reset();
stillPub->closeQueue();
}
controlQ->close();
}

Expand Down Expand Up @@ -156,5 +189,13 @@ void RGB::updateParams(const std::vector<rclcpp::Parameter>& params) {
controlQ->send(ctrl);
}

void RGB::triggerStillCB(std_srvs::srv::Trigger::Request::ConstSharedPtr /*req*/, std_srvs::srv::Trigger::Response::SharedPtr res) {
dai::CameraControl ctrl;
ctrl.setCaptureStill(true);
controlQ->send(ctrl);
res->success = true;
res->message = "Still capture request sent";
}

} // namespace dai_nodes
} // namespace depthai_ros_driver
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ void SensorParamHandler::declareParams(std::shared_ptr<dai::node::ColorCamera> c
colorCam->setBoardSocket(socketID);
declareAndLogParam<bool>("i_output_isp", true);
declareAndLogParam<bool>("i_enable_preview", false);
declareAndLogParam<bool>("i_enable_still", false);
declareAndLogParam<bool>("i_flip_published_image", false);
colorCam->setFps(declareAndLogParam<double>("i_fps", 30.0));
int preview_size = declareAndLogParam<int>("i_preview_size", 300);
Expand Down Expand Up @@ -175,6 +176,9 @@ void SensorParamHandler::declareParams(std::shared_ptr<dai::node::ColorCamera> c
RCLCPP_ERROR(getROSNode()->get_logger(), "%s", err_stream.str().c_str());
}
}
int stillWidth = declareAndLogParam<int>("i_still_width", width);
int stillHeight = declareAndLogParam<int>("i_still_height", height);
colorCam->setStillSize(stillWidth, stillHeight);
Comment on lines +179 to +181

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, still should use the sensor size by default

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still resolution cannot be larger than isp output resolution (which is held in width and height variables at this point in code). Running the driver with default parameters out with this modification results in:

what():  ColorCamera(0) - 'still' width or height (1920, 1080) bigger than maximum at current sensor resolution (1280, 720)

int maxVideoWidth = 3840;
int maxVideoHeight = 2160;
int videoWidth = declareAndLogParam<int>("i_width", width);
Expand Down