Skip to content

Instantly share code, notes, and snippets.

@cwyark
Created July 10, 2019 01:56
Show Gist options
  • Save cwyark/7d032d3a0672d4418505474d90819900 to your computer and use it in GitHub Desktop.
Save cwyark/7d032d3a0672d4418505474d90819900 to your computer and use it in GitHub Desktop.
#include <chrono>
#include <iostream>
#include <memory>
#include <string>
#include "rclcpp/rclcpp.hpp"
#include "rcl_interfaces/srv/describe_parameters.hpp"
#include "rcl_interfaces/srv/get_parameter_types.hpp"
#include "rcl_interfaces/srv/get_parameters.hpp"
#include "rcl_interfaces/srv/list_parameters.hpp"
#include "rcl_interfaces/srv/set_parameters.hpp"
#include "rcl_interfaces/srv/set_parameter_types.hpp"
#include "rcl_interfaces/srv/set_parameters_atomically.hpp"
using namespace std::chrono_literals;
rcl_interfaces::srv::GetParameters::Response::SharedPtr send_request(
rclcpp::Node::SharedPtr node,
rclcpp::Client<rcl_interfaces::srv::GetParameters>::SharedPtr client,
rcl_interfaces::srv::GetParameters::Request::SharedPtr request)
{
auto result = client->async_send_request(request);
// Wait for the result.
if (rclcpp::spin_until_future_complete(node, result) ==
rclcpp::executor::FutureReturnCode::SUCCESS)
{
return result.get();
} else {
return NULL;
}
}
int main(int argc, char ** argv)
{
// Force flush of the stdout buffer.
setvbuf(stdout, NULL, _IONBF, BUFSIZ);
rclcpp::init(argc, argv);
auto node = rclcpp::Node::make_shared("param_client");
auto client = node->create_client<rcl_interfaces::srv::GetParameters>("get_parameters");
auto request = std::make_shared<rcl_interfaces::srv::GetParameters::Request>();
//request->depth = 3;
while (!client->wait_for_service(1s)) {
if (!rclcpp::ok()) {
RCLCPP_ERROR(node->get_logger(), "Interrupted while waiting for the service. Exiting.");
return 0;
}
RCLCPP_INFO(node->get_logger(), "service not available, waiting again...");
}
auto result = send_request(node, client, request);
rclcpp::shutdown();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment