From ab8b12157b2e4e85de2fc47f41bcc9b485315094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Thor=C3=A9n?= Date: Fri, 3 Nov 2023 10:40:00 +0100 Subject: [PATCH] Merged two functions into one --- common/module.hpp | 29 ++----------------- .../src/scenarioexecution.cpp | 2 +- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/common/module.hpp b/common/module.hpp index 35de8a0eb..b3c933d71 100644 --- a/common/module.hpp +++ b/common/module.hpp @@ -82,29 +82,6 @@ class Module : public rclcpp::Node { const std::string& topic, const rclcpp::Logger& logger); - /*! \brief This helper function is performs a service call given a client and yields a response. - * \tparam Srv The name of the service to request. - * \param timeout The timeout for the service call. - * \param client The client to use to request the service. - * \param response The response of the service. - * \return The response of the service. - */ - template - bool callService( const std::chrono::duration< double > &timeout, - std::shared_ptr> &client, - std::shared_ptr &response) -{ - auto request = std::make_shared(); - auto promise = client->async_send_request(request); - if (rclcpp::spin_until_future_complete(get_node_base_interface(), promise, timeout) == - rclcpp::FutureReturnCode::SUCCESS) { - response = promise.get(); - return true; - } else { - RCLCPP_ERROR(get_logger(), "Failed to call service %s", client->get_service_name()); - return false; - } - } /** * @brief This helper function is performs a service call given a client and yields a response. This @@ -113,15 +90,15 @@ class Module : public rclcpp::Node { * @tparam Srv Srv The name of the service to request. * @param timeout The timeout for the service call. * @param client The client to use to request the service. - * @param request The request of the service, with the data to be sent. * @param response The response of the service. + * @param request The request of the service, with the data to be sent. Defaults to an empty request. * @return The response of the service. */ template bool callService( const std::chrono::duration< double > &timeout, std::shared_ptr> &client, - std::shared_ptr &request, - std::shared_ptr &response) + std::shared_ptr &response, + std::shared_ptr request = std::make_shared()) { auto promise = client->async_send_request(request); if (rclcpp::spin_until_future_complete(get_node_base_interface(), promise, timeout) == diff --git a/modules/IntegrationTesting/src/scenarioexecution.cpp b/modules/IntegrationTesting/src/scenarioexecution.cpp index 86a7495e6..13e0e6b2c 100644 --- a/modules/IntegrationTesting/src/scenarioexecution.cpp +++ b/modules/IntegrationTesting/src/scenarioexecution.cpp @@ -68,7 +68,7 @@ std::vector> ScenarioExecution::getTrajectoryPoints() auto request = std::make_shared(); request->id = 1; std::shared_ptr response; - this->callService(1000ms, getObjectTrajectoryClient, request, response); + this->callService(1000ms, getObjectTrajectoryClient, response, request); std::vector> trajectory; for (const auto& t : response->trajectory.points) {