Skip to content

Commit 1b3a4fd

Browse files
committed
add no semantic data receiver
1 parent 605769d commit 1b3a4fd

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

hydra_ros/include/hydra_ros/input/image_receiver.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,30 @@ void ImageReceiverImpl<SemanticT>::callback(
182182
queue.push(packet);
183183
}
184184

185+
class NoSemanticImageReceiver : public RosDataReceiver {
186+
public:
187+
struct Config : RosDataReceiver::Config {};
188+
using Policy =
189+
message_filters::sync_policies::ApproximateTime<sensor_msgs::msg::Image,
190+
sensor_msgs::msg::Image>;
191+
using Synchronizer = message_filters::Synchronizer<Policy>;
192+
193+
NoSemanticImageReceiver(const Config& config, const std::string& sensor_name);
194+
virtual ~NoSemanticImageReceiver() = default;
195+
196+
protected:
197+
bool initImpl() override;
198+
199+
void callback(const sensor_msgs::msg::Image::ConstSharedPtr& color,
200+
const sensor_msgs::msg::Image::ConstSharedPtr& depth);
201+
202+
ColorSubscriber color_sub_;
203+
DepthSubscriber depth_sub_;
204+
std::unique_ptr<Synchronizer> sync_;
205+
};
206+
207+
void declare_config(NoSemanticImageReceiver::Config& config);
208+
185209
class ClosedSetImageReceiver : public ImageReceiverImpl<LabelSubscriber> {
186210
public:
187211
struct Config : RosDataReceiver::Config {};

hydra_ros/src/input/image_receiver.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,39 @@ void FeatureSubscriber::fillInput(const MsgType& msg, ImageInputPacket& packet)
130130
}
131131
}
132132

133+
void declare_config(NoSemanticImageReceiver::Config& config) {
134+
using namespace config;
135+
name("NoSemanticImageReceiver::Config");
136+
base<RosDataReceiver::Config>(config);
137+
}
138+
139+
NoSemanticImageReceiver::NoSemanticImageReceiver(const Config& config,
140+
const std::string& sensor_name)
141+
: RosDataReceiver(config, sensor_name) {}
142+
143+
bool NoSemanticImageReceiver::initImpl() {
144+
color_sub_ = ColorSubscriber(ianvs::NodeHandle::this_node(ns_));
145+
depth_sub_ = DepthSubscriber(ianvs::NodeHandle::this_node(ns_));
146+
sync_.reset(new Synchronizer(
147+
Policy(config.queue_size), color_sub_.getFilter(), depth_sub_.getFilter()));
148+
sync_->registerCallback(&NoSemanticImageReceiver::callback, this);
149+
return true;
150+
}
151+
152+
void NoSemanticImageReceiver::callback(
153+
const sensor_msgs::msg::Image::ConstSharedPtr& color,
154+
const sensor_msgs::msg::Image::ConstSharedPtr& depth) {
155+
const auto timestamp_ns = rclcpp::Time(color->header.stamp).nanoseconds();
156+
if (!checkInputTimestamp(timestamp_ns)) {
157+
return;
158+
}
159+
160+
auto packet = std::make_shared<ImageInputPacket>(timestamp_ns, sensor_name_);
161+
color_sub_.fillInput(*color, *packet);
162+
depth_sub_.fillInput(*depth, *packet);
163+
queue.push(packet);
164+
}
165+
133166
void declare_config(ClosedSetImageReceiver::Config& config) {
134167
using namespace config;
135168
name("ClosedSetImageReceiver::Config");
@@ -152,6 +185,12 @@ OpenSetImageReceiver::OpenSetImageReceiver(const Config& config,
152185

153186
namespace {
154187

188+
static const auto no_semantic_registration =
189+
config::RegistrationWithConfig<DataReceiver,
190+
NoSemanticImageReceiver,
191+
NoSemanticImageReceiver::Config,
192+
std::string>("NoSemanticImageReceiver");
193+
155194
static const auto closed_registration =
156195
config::RegistrationWithConfig<DataReceiver,
157196
ClosedSetImageReceiver,

0 commit comments

Comments
 (0)