|
| 1 | +// Copyright 2022 The Autoware Contributors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include "yabloc_module.hpp" |
| 16 | + |
| 17 | +#include <component_interface_specs/localization.hpp> |
| 18 | +#include <component_interface_utils/rclcpp/exceptions.hpp> |
| 19 | + |
| 20 | +#include <memory> |
| 21 | + |
| 22 | +using ServiceException = component_interface_utils::ServiceException; |
| 23 | +using Initialize = localization_interface::Initialize; |
| 24 | +using PoseWithCovarianceStamped = geometry_msgs::msg::PoseWithCovarianceStamped; |
| 25 | + |
| 26 | +YabLocModule::YabLocModule(rclcpp::Node * node) : logger_(node->get_logger()) |
| 27 | +{ |
| 28 | + cli_align_ = node->create_client<RequestPoseAlignment>("yabloc_align"); |
| 29 | +} |
| 30 | + |
| 31 | +PoseWithCovarianceStamped YabLocModule::align_pose(const PoseWithCovarianceStamped & pose) |
| 32 | +{ |
| 33 | + const auto req = std::make_shared<RequestPoseAlignment::Request>(); |
| 34 | + req->pose_with_covariance = pose; |
| 35 | + |
| 36 | + if (!cli_align_->service_is_ready()) { |
| 37 | + throw component_interface_utils::ServiceUnready("YabLoc align server is not ready."); |
| 38 | + } |
| 39 | + |
| 40 | + RCLCPP_INFO(logger_, "Call YabLoc align server."); |
| 41 | + const auto res = cli_align_->async_send_request(req).get(); |
| 42 | + if (!res->success) { |
| 43 | + RCLCPP_INFO(logger_, "YabLoc align server failed."); |
| 44 | + throw ServiceException( |
| 45 | + Initialize::Service::Response::ERROR_ESTIMATION, "YabLoc align server failed."); |
| 46 | + } |
| 47 | + RCLCPP_INFO(logger_, "YabLoc align server succeeded."); |
| 48 | + |
| 49 | + // Overwrite the covariance. |
| 50 | + return res->pose_with_covariance; |
| 51 | +} |
0 commit comments