Skip to content

Commit 8a7fb3a

Browse files
committed
cleanup complex non-castable interfaces on activate
1 parent de8fa48 commit 8a7fb3a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

joint_state_broadcaster/src/joint_state_broadcaster.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,29 @@ controller_interface::CallbackReturn JointStateBroadcaster::on_activate(
201201
return CallbackReturn::ERROR;
202202
}
203203

204+
// Erase the interfaces that are not castable to double
205+
std::vector<hardware_interface::LoanedStateInterface> state_interfaces_to_keep;
206+
std::for_each(
207+
state_interfaces_.begin(), state_interfaces_.end(),
208+
[&state_interfaces_to_keep](hardware_interface::LoanedStateInterface & si)
209+
{
210+
if (si.is_castable_to_double())
211+
{
212+
state_interfaces_to_keep.push_back(std::move(si));
213+
}
214+
else
215+
{
216+
RCLCPP_ERROR(
217+
rclcpp::get_logger("JointStateBroadcaster"),
218+
"State interface '%s' is not castable to double. "
219+
"It will not be used in JointStateBroadcaster.",
220+
si.get_name().c_str());
221+
}
222+
});
223+
224+
state_interfaces_.clear();
225+
state_interfaces_ = std::move(state_interfaces_to_keep);
226+
204227
init_auxiliary_data();
205228
init_joint_state_msg();
206229
init_dynamic_joint_state_msg();

0 commit comments

Comments
 (0)