Skip to content

Commit 4a1364b

Browse files
committed
Handle cases of state interfaces with different data types
1 parent d7eca59 commit 4a1364b

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

joint_state_broadcaster/src/joint_state_broadcaster.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,29 @@ controller_interface::return_type JointStateBroadcaster::update(
414414
for (auto i = 0u; i < state_interfaces_.size(); ++i)
415415
{
416416
// no retries, just try to get the latest value once
417-
const auto & opt = state_interfaces_[i].get_optional(0);
418-
if (opt.has_value())
417+
if (state_interfaces_[i].get_data_type() == hardware_interface::HandleDataType::DOUBLE)
419418
{
420-
*mapped_values_[i] = opt.value();
419+
const auto & opt = state_interfaces_[i].get_optional(0);
420+
if (opt.has_value())
421+
{
422+
*mapped_values_[i] = opt.value();
423+
}
424+
}
425+
else if (state_interfaces_[i].get_data_type() == hardware_interface::HandleDataType::BOOL)
426+
{
427+
const auto & opt = state_interfaces_[i].get_optional<bool>(0);
428+
if (opt.has_value())
429+
{
430+
*mapped_values_[i] = static_cast<double>(opt.value());
431+
}
432+
}
433+
else
434+
{
435+
RCLCPP_DEBUG(
436+
get_node()->get_logger(),
437+
"Unsupported data type for state interface '%s'. "
438+
"Only double and bool are supported.",
439+
state_interfaces_[i].get_name().c_str());
421440
}
422441
}
423442

0 commit comments

Comments
 (0)