Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
Signed-off-by: anhnv3991 <[email protected]>
  • Loading branch information
anhnv3991 committed May 21, 2024
1 parent 22beb28 commit 3118a09
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions localization/ndt_scan_matcher/src/map_update_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,31 +217,25 @@ bool MapUpdateModule::update_ndt(

// Wait for maximum 10 milliseconds
std::chrono::milliseconds timeout(10);
auto start = std::chrono::system_clock::now();
std::future_status status = result.wait_for(timeout);

std::future_status status = result.wait_for(std::chrono::seconds(0));
while (status != std::future_status::ready) {
// check is_succeed_call_pcd_loader
if (!rclcpp::ok()) {
diagnostics_ptr->addKeyValue("is_succeed_call_pcd_loader", false);

std::stringstream message;
message << "pcd_loader service is not working.";
diagnostics_ptr->updateLevelAndMessage(
diagnostic_msgs::msg::DiagnosticStatus::WARN, message.str());
return false; // No update
}

auto cur = std::chrono::system_clock::now();
if (status == std::future_status::timeout)
{
RCLCPP_WARN_STREAM_THROTTLE(logger_, *clock_, 1000, "Waited for incoming PCDs for too long!");
}

// Report an error if wait for too long
if (cur - start >= timeout) {
RCLCPP_WARN_STREAM_THROTTLE(
logger_, *clock_, 1000, "Waited for incoming PCDs for too long...");
}
if (status != std::future_status::ready)
{
diagnostics_ptr->addKeyValue("is_succeed_call_pcd_loader", false);

status = result.wait_for(std::chrono::seconds(1));
std::stringstream message;
message << "pcd_loader service is not working.";
diagnostics_ptr->updateLevelAndMessage(
diagnostic_msgs::msg::DiagnosticStatus::WARN, message.str());

return false;
}

diagnostics_ptr->addKeyValue("is_succeed_call_pcd_loader", true);

auto & maps_to_add = result.get()->new_pointcloud_with_ids;
Expand Down

0 comments on commit 3118a09

Please sign in to comment.