Skip to content

Commit 680ba20

Browse files
authored
Merge pull request #783 from bjsowa/feat/add-still-output
feat: Add an option to use still output in RGB node
2 parents 3170e87 + 6229dcf commit 680ba20

4 files changed

Lines changed: 55 additions & 2 deletions

File tree

depthai_ros_driver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ depthai
4040
depthai_bridge
4141
rclcpp
4242
std_msgs
43+
std_srvs
4344
sensor_msgs
4445
image_transport)
4546

depthai_ros_driver/include/depthai_ros_driver/dai_nodes/sensors/rgb.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#pragma once
22

33
#include "depthai_ros_driver/dai_nodes/base_node.hpp"
4+
#include "rclcpp/service.hpp"
5+
#include "std_srvs/srv/trigger.hpp"
46

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

5052
private:
51-
std::shared_ptr<sensor_helpers::ImagePublisher> rgbPub, previewPub;
53+
void triggerStillCB(std_srvs::srv::Trigger::Request::ConstSharedPtr req, std_srvs::srv::Trigger::Response::SharedPtr res);
54+
55+
std::shared_ptr<sensor_helpers::ImagePublisher> rgbPub, previewPub, stillPub;
56+
rclcpp::Service<std_srvs::srv::Trigger>::SharedPtr triggerStillService;
5257
std::shared_ptr<dai::node::ColorCamera> colorCamNode;
5358
std::unique_ptr<param_handlers::SensorParamHandler> ph;
5459
std::shared_ptr<dai::DataInputQueue> controlQ;
5560
std::shared_ptr<dai::node::XLinkIn> xinControl;
56-
std::string ispQName, previewQName, controlQName;
61+
std::string ispQName, previewQName, controlQName, stillQName;
5762
};
5863

5964
} // namespace dai_nodes

depthai_ros_driver/src/dai_nodes/sensors/rgb.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void RGB::setNames() {
3535
ispQName = getName() + "_isp";
3636
previewQName = getName() + "_preview";
3737
controlQName = getName() + "_control";
38+
stillQName = getName() + "_still";
3839
}
3940

4041
void RGB::setXinXout(std::shared_ptr<dai::Pipeline> pipeline) {
@@ -59,6 +60,9 @@ void RGB::setXinXout(std::shared_ptr<dai::Pipeline> pipeline) {
5960
if(ph->getParam<bool>("i_enable_preview")) {
6061
previewPub = setupOutput(pipeline, previewQName, [&](auto input) { colorCamNode->preview.link(input); });
6162
}
63+
if(ph->getParam<bool>("i_enable_still")) {
64+
stillPub = setupOutput(pipeline, stillQName, [&](auto input) { colorCamNode->still.link(input); });
65+
}
6266
xinControl = pipeline->create<dai::node::XLinkIn>();
6367
xinControl->setStreamName(controlQName);
6468
xinControl->out.link(colorCamNode->inputControl);
@@ -119,6 +123,33 @@ void RGB::setupQueues(std::shared_ptr<dai::Device> device) {
119123
previewPub->setup(device, convConfig, pubConfig);
120124
};
121125
controlQ = device->getInputQueue(controlQName);
126+
if(ph->getParam<bool>("i_enable_still")) {
127+
auto tfPrefix = getOpticalTFPrefix(getSocketName(static_cast<dai::CameraBoardSocket>(ph->getParam<int>("i_board_socket_id"))));
128+
utils::ImgConverterConfig convConfig;
129+
convConfig.tfPrefix = tfPrefix;
130+
convConfig.getBaseDeviceTimestamp = ph->getParam<bool>("i_get_base_device_timestamp");
131+
convConfig.updateROSBaseTimeOnRosMsg = ph->getParam<bool>("i_update_ros_base_time_on_ros_msg");
132+
convConfig.addExposureOffset = ph->getParam<bool>("i_add_exposure_offset");
133+
convConfig.expOffset = static_cast<dai::CameraExposureOffset>(ph->getParam<int>("i_exposure_offset"));
134+
135+
utils::ImgPublisherConfig pubConfig;
136+
pubConfig.daiNodeName = getName();
137+
pubConfig.topicName = "~/" + getName();
138+
pubConfig.lazyPub = ph->getParam<bool>("i_enable_lazy_publisher");
139+
pubConfig.socket = static_cast<dai::CameraBoardSocket>(ph->getParam<int>("i_board_socket_id"));
140+
pubConfig.calibrationFile = ph->getParam<std::string>("i_calibration_file");
141+
pubConfig.rectified = false;
142+
pubConfig.width = ph->getParam<int>("i_still_width");
143+
pubConfig.height = ph->getParam<int>("i_still_height");
144+
pubConfig.maxQSize = ph->getParam<int>("i_max_q_size");
145+
pubConfig.topicSuffix = "/still/image_raw";
146+
pubConfig.flipImage = ph->getParam<bool>("i_flip_published_image");
147+
148+
stillPub->setup(device, convConfig, pubConfig);
149+
150+
triggerStillService = getROSNode()->create_service<std_srvs::srv::Trigger>(
151+
"~/" + getName() + "/trigger_still", std::bind(&RGB::triggerStillCB, this, std::placeholders::_1, std::placeholders::_2));
152+
};
122153
}
123154

124155
void RGB::closeQueues() {
@@ -128,6 +159,10 @@ void RGB::closeQueues() {
128159
previewPub->closeQueue();
129160
}
130161
}
162+
if(ph->getParam<bool>("i_enable_still")) {
163+
triggerStillService.reset();
164+
stillPub->closeQueue();
165+
}
131166
controlQ->close();
132167
}
133168

@@ -156,5 +191,13 @@ void RGB::updateParams(const std::vector<rclcpp::Parameter>& params) {
156191
controlQ->send(ctrl);
157192
}
158193

194+
void RGB::triggerStillCB(std_srvs::srv::Trigger::Request::ConstSharedPtr /*req*/, std_srvs::srv::Trigger::Response::SharedPtr res) {
195+
dai::CameraControl ctrl;
196+
ctrl.setCaptureStill(true);
197+
controlQ->send(ctrl);
198+
res->success = true;
199+
res->message = "Still capture request sent";
200+
}
201+
159202
} // namespace dai_nodes
160203
} // namespace depthai_ros_driver

depthai_ros_driver/src/param_handlers/sensor_param_handler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ void SensorParamHandler::declareParams(std::shared_ptr<dai::node::ColorCamera> c
125125
colorCam->setBoardSocket(socketID);
126126
declareAndLogParam<bool>("i_output_isp", true);
127127
declareAndLogParam<bool>("i_enable_preview", false);
128+
declareAndLogParam<bool>("i_enable_still", false);
128129
declareAndLogParam<bool>("i_flip_published_image", false);
129130
colorCam->setFps(declareAndLogParam<double>("i_fps", 30.0));
130131
int preview_size = declareAndLogParam<int>("i_preview_size", 300);
@@ -175,6 +176,9 @@ void SensorParamHandler::declareParams(std::shared_ptr<dai::node::ColorCamera> c
175176
RCLCPP_ERROR(getROSNode()->get_logger(), "%s", err_stream.str().c_str());
176177
}
177178
}
179+
int stillWidth = declareAndLogParam<int>("i_still_width", width);
180+
int stillHeight = declareAndLogParam<int>("i_still_height", height);
181+
colorCam->setStillSize(stillWidth, stillHeight);
178182
int maxVideoWidth = 3840;
179183
int maxVideoHeight = 2160;
180184
int videoWidth = declareAndLogParam<int>("i_width", width);

0 commit comments

Comments
 (0)