From 7117fedced0a29b63200e3b180c98929232ddca1 Mon Sep 17 00:00:00 2001 From: Sai Kishor Kothakota Date: Fri, 29 Nov 2024 00:09:57 +0100 Subject: [PATCH] handle cases when the value_ptr_ is invalid --- hardware_interface/include/hardware_interface/handle.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hardware_interface/include/hardware_interface/handle.hpp b/hardware_interface/include/hardware_interface/handle.hpp index 537269f382..015cca3ebb 100644 --- a/hardware_interface/include/hardware_interface/handle.hpp +++ b/hardware_interface/include/hardware_interface/handle.hpp @@ -212,7 +212,8 @@ class StateInterface : public Handle { if (std::holds_alternative(value_)) { - std::function f = [this]() { return *value_ptr_; }; + std::function f = [this]() + { return value_ptr_ ? *value_ptr_ : std::numeric_limits::quiet_NaN(); }; REGISTER_ENTITY(DEFAULT_REGISTRY_KEY, "state_interface." + get_name(), f); } } @@ -258,7 +259,8 @@ class CommandInterface : public Handle { RCLCPP_INFO_STREAM( rclcpp::get_logger("command_interface"), "Registering handle: " << get_name()); - std::function f = [this]() { return *value_ptr_; }; + std::function f = [this]() + { return value_ptr_ ? *value_ptr_ : std::numeric_limits::quiet_NaN(); }; REGISTER_ENTITY(DEFAULT_REGISTRY_KEY, "command_interface." + get_name(), f); } }