Skip to content

Commit bdb6e0b

Browse files
authored
Merge pull request #23 from christophfroehlich/fix/API
Fix upstream API
2 parents df9711c + e354494 commit bdb6e0b

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

picknik_reset_fault_controller/src/picknik_reset_fault_controller.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,14 @@ CallbackReturn PicknikResetFaultController::on_init() { return CallbackReturn::S
6262
controller_interface::return_type PicknikResetFaultController::update(
6363
const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/)
6464
{
65-
if (realtime_publisher_ && realtime_publisher_->trylock())
65+
if (realtime_publisher_)
6666
{
67-
state_.data = static_cast<bool>(state_interfaces_[StateInterfaces::IN_FAULT].get_value());
68-
realtime_publisher_->msg_.data = state_.data;
69-
realtime_publisher_->unlockAndPublish();
67+
auto state_op = state_interfaces_[StateInterfaces::IN_FAULT].get_optional();
68+
if (state_op.has_value())
69+
{
70+
state_.data = static_cast<bool>(state_op.value());
71+
}
72+
realtime_publisher_->try_publish(state_);
7073
}
7174

7275
return controller_interface::return_type::OK;
@@ -121,14 +124,23 @@ bool PicknikResetFaultController::resetFault(
121124

122125
RCLCPP_INFO(get_node()->get_logger(), "Trying to reset faults on hardware controller.");
123126

124-
while (command_interfaces_[CommandInterfaces::RESET_FAULT_ASYNC_SUCCESS].get_value() ==
125-
ASYNC_WAITING)
127+
while (command_interfaces_[CommandInterfaces::RESET_FAULT_ASYNC_SUCCESS].get_optional().value_or(
128+
ASYNC_WAITING) == ASYNC_WAITING)
126129
{
127130
// Asynchronous wait until the hardware interface has set the io value
128131
std::this_thread::sleep_for(std::chrono::milliseconds(50));
129132
}
130-
resp->success = static_cast<bool>(
131-
command_interfaces_[CommandInterfaces::RESET_FAULT_ASYNC_SUCCESS].get_value());
133+
auto async_result_op =
134+
command_interfaces_[CommandInterfaces::RESET_FAULT_ASYNC_SUCCESS].get_optional();
135+
if (!async_result_op.has_value())
136+
{
137+
RCLCPP_ERROR(
138+
get_node()->get_logger(),
139+
"Failed to get result of fault reset command from hardware controller.");
140+
resp->success = false;
141+
return resp->success;
142+
}
143+
resp->success = static_cast<bool>(async_result_op.value());
132144

133145
RCLCPP_INFO(
134146
get_node()->get_logger(), "Resetting fault on hardware controller '%s'!",

0 commit comments

Comments
 (0)