Skip to content

Commit 0ee6cfb

Browse files
set latching by config to avoid invalid zenoh qos value (#40)
1 parent 6853db3 commit 0ee6cfb

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

hydra_ros/include/hydra_ros/input/ros_sensors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ struct RosCamera : InvalidSensor {
8787
double warning_timeout_s = 10.0;
8888
//! @brief Amount of time to wait before forcing Hydra to exit (0 disables exit)
8989
double error_timeout_s = 0.0;
90+
//! @brief Whether or not to use latching for subscriber
91+
bool latch_info_sub = false;
9092
} const config;
9193

9294
explicit RosCamera(const Config& config);

hydra_ros/src/input/ros_sensors.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,18 @@ void fillConfigFromInfo(const CameraInfo& msg, Camera::Config& cam_config) {
6969
cam_config.cy = msg.k[5];
7070
}
7171

72-
std::optional<sensor_msgs::msg::CameraInfo> getCameraInfo(const RosCamera::Config& c,
73-
const std::string& ns) {
72+
std::optional<sensor_msgs::msg::CameraInfo> getCameraInfo(
73+
const RosCamera::Config& config, const std::string& ns) {
7474
auto nh = ianvs::NodeHandle::this_node(ns);
7575
const auto resolved_topic = nh.resolve_name("camera_info", false);
7676
LOG(INFO) << "Waiting for CameraInfo on " << resolved_topic
7777
<< " to initialize sensor model";
7878

7979
const auto start = nh.now();
80-
const auto qos = rclcpp::QoS(1).durability(rclcpp::DurabilityPolicy::BestAvailable);
81-
const size_t timeout = std::floor(c.warning_timeout_s * 1000);
80+
const auto qos = rclcpp::QoS(1).durability(
81+
config.latch_info_sub ? rclcpp::DurabilityPolicy::TransientLocal
82+
: rclcpp::DurabilityPolicy::Volatile);
83+
const size_t timeout = std::floor(config.warning_timeout_s * 1000);
8284

8385
std::optional<sensor_msgs::msg::CameraInfo> msg;
8486
while (!msg && rclcpp::ok()) {
@@ -88,7 +90,7 @@ std::optional<sensor_msgs::msg::CameraInfo> getCameraInfo(const RosCamera::Confi
8890
}
8991

9092
const auto diff = nh.now() - start;
91-
if (c.error_timeout_s && (diff.seconds() > c.error_timeout_s)) {
93+
if (config.error_timeout_s && (diff.seconds() > config.error_timeout_s)) {
9294
LOG(ERROR) << "Sensor intrinsics lookup timed out on '" << resolved_topic << "'";
9395
break;
9496
}
@@ -170,6 +172,7 @@ void declare_config(RosCamera::Config& config) {
170172
field(config.ns, "ns");
171173
field(config.warning_timeout_s, "warning_timeout_s", "s");
172174
field(config.error_timeout_s, "error_timeout_s", "s");
175+
field(config.latch_info_sub, "latch_info_sub");
173176
check(config.warning_timeout_s, GE, 0.0, "warning_timeout_s");
174177
check(config.error_timeout_s, GE, 0.0, "error_timeout_s");
175178
}

hydra_ros/tests/test_ros_sensors.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ TEST_F(RosSensors, Camera) {
169169
config.max_range = 15;
170170
config.warning_timeout_s = 1.0;
171171
config.error_timeout_s = 5.0;
172+
config.latch_info_sub = true;
172173
config.extrinsics = IdentitySensorExtrinsics::Config();
173174

174175
{ // should be able to parse intrinsics and extrinsics separately

0 commit comments

Comments
 (0)