Skip to content

Commit

Permalink
handle cases when the value_ptr_ is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
saikishor committed Nov 29, 2024
1 parent 52310fd commit c312a9b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions hardware_interface/include/hardware_interface/handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ class StateInterface : public Handle
{
if (std::holds_alternative<double>(value_))
{
std::function<double()> f = [this]() { return *value_ptr_; };
std::function<double()> f = [this]()
{ return value_ptr_ ? *value_ptr_ : std::numeric_limits<double>::quiet_NaN(); };
REGISTER_ENTITY(DEFAULT_REGISTRY_KEY, "state_interface." + get_name(), f);
}
}
Expand Down Expand Up @@ -258,7 +259,8 @@ class CommandInterface : public Handle
{
RCLCPP_INFO_STREAM(
rclcpp::get_logger("command_interface"), "Registering handle: " << get_name());
std::function<double()> f = [this]() { return *value_ptr_; };
std::function<double()> f = [this]()
{ return value_ptr_ ? *value_ptr_ : std::numeric_limits<double>::quiet_NaN(); };
REGISTER_ENTITY(DEFAULT_REGISTRY_KEY, "command_interface." + get_name(), f);
}
}
Expand Down

0 comments on commit c312a9b

Please sign in to comment.