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); } }