Skip to content

Commit

Permalink
Merged two functions into one
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelthoren committed Nov 3, 2023
1 parent b8fac80 commit ab8b121
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 27 deletions.
29 changes: 3 additions & 26 deletions common/module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename Srv>
bool callService( const std::chrono::duration< double > &timeout,
std::shared_ptr<rclcpp::Client<Srv>> &client,
std::shared_ptr<typename Srv::Response> &response)
{
auto request = std::make_shared<typename Srv::Request>();
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
Expand All @@ -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 <typename Srv>
bool callService( const std::chrono::duration< double > &timeout,
std::shared_ptr<rclcpp::Client<Srv>> &client,
std::shared_ptr<typename Srv::Request> &request,
std::shared_ptr<typename Srv::Response> &response)
std::shared_ptr<typename Srv::Response> &response,
std::shared_ptr<typename Srv::Request> request = std::make_shared<typename Srv::Request>())
{
auto promise = client->async_send_request(request);
if (rclcpp::spin_until_future_complete(get_node_base_interface(), promise, timeout) ==
Expand Down
2 changes: 1 addition & 1 deletion modules/IntegrationTesting/src/scenarioexecution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ std::vector<std::pair<double, double>> ScenarioExecution::getTrajectoryPoints()
auto request = std::make_shared<atos_interfaces::srv::GetObjectTrajectory::Request>();
request->id = 1;
std::shared_ptr<atos_interfaces::srv::GetObjectTrajectory::Response> response;
this->callService(1000ms, getObjectTrajectoryClient, request, response);
this->callService(1000ms, getObjectTrajectoryClient, response, request);

std::vector<std::pair<double, double>> trajectory;
for (const auto& t : response->trajectory.points) {
Expand Down

0 comments on commit ab8b121

Please sign in to comment.