Skip to content

Commit

Permalink
add minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
saikishor committed Jan 2, 2025
1 parent 37964b7 commit 169ba83
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions hardware_interface/include/hardware_interface/handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class Handle
{
return std::nullopt;
}
return std::get<T>(value_);
return value_ptr_ != nullptr ? *value_ptr_ : std::get<T>(value_);
}

template <typename T = double>
Expand All @@ -181,7 +181,7 @@ class Handle
return T();
}
status = true;
return std::get<T>(value_);
return value_ptr_ != nullptr ? *value_ptr_ : std::get<T>(value_);
}

[[nodiscard]] bool get_value(double & value) const
Expand Down
5 changes: 4 additions & 1 deletion hardware_interface/test/test_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ TEST(TestHandle, command_interface)
double value = 1.337;
CommandInterface interface{JOINT_NAME, FOO_INTERFACE, &value};
EXPECT_DOUBLE_EQ(interface.get_value(), value);
ASSERT_TRUE(interface.get_value<double>().has_value());
EXPECT_DOUBLE_EQ(interface.get_value<double>().value(), value);
EXPECT_DOUBLE_EQ(interface.get_value(), value);
EXPECT_NO_THROW(bool status = interface.set_value(0.0));
bool status;
EXPECT_DOUBLE_EQ(interface.get_value(status), 0.0);
Expand Down Expand Up @@ -64,7 +66,8 @@ TEST(TestHandle, name_getters_work)
TEST(TestHandle, value_methods_throw_for_nullptr)
{
CommandInterface handle{JOINT_NAME, FOO_INTERFACE};
EXPECT_ANY_THROW(handle.get_value<double>());
double value;
EXPECT_ANY_THROW(handle.get_value(value));
EXPECT_ANY_THROW(bool status = handle.set_value(0.0));
}

Expand Down

0 comments on commit 169ba83

Please sign in to comment.