Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Developer parameters api #20

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rclcpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ cmake_minimum_required(VERSION 2.8.3)
project(rclcpp)

find_package(ament_cmake REQUIRED)
find_package(rcl_interfaces REQUIRED)

ament_export_dependencies(rmw)
ament_export_dependencies(rcl_interfaces)

ament_export_include_directories(include)

Expand Down
14 changes: 14 additions & 0 deletions rclcpp/include/rclcpp/executors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ namespace executors
using rclcpp::executors::multi_threaded_executor::MultiThreadedExecutor;
using rclcpp::executors::single_threaded_executor::SingleThreadedExecutor;

template<typename FutureT>
std::shared_future<FutureT> &
spin_node_until_future_complete(
rclcpp::executor::Executor & executor, Node::SharedPtr & node_ptr,
std::shared_future<FutureT> & future)
{
std::future_status status;
do {
executor.spin_node_some(node_ptr);
status = future.wait_for(std::chrono::seconds(0));
} while (status != std::future_status::ready && rclcpp::utilities::ok());
return future;
}

} // namespace executors
} // namespace rclcpp

Expand Down
52 changes: 51 additions & 1 deletion rclcpp/include/rclcpp/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
#include <list>
#include <memory>
#include <string>
#include <thread>

#include <rclcpp/callback_group.hpp>
#include <rclcpp/client.hpp>
#include <rclcpp/context.hpp>
#include <rclcpp/macros.hpp>
#include <rclcpp/parameter.hpp>
#include <rclcpp/publisher.hpp>
#include <rclcpp/service.hpp>
#include <rclcpp/subscription.hpp>
Expand Down Expand Up @@ -64,7 +66,7 @@ class Node

/* Get the name of the node. */
std::string
get_name();
get_name() const {return this->name_; }

/* Create and return a callback group. */
rclcpp::callback_group::CallbackGroup::SharedPtr
Expand Down Expand Up @@ -124,6 +126,40 @@ class Node
typename rclcpp::service::Service<ServiceT>::CallbackWithHeaderType callback_with_header,
rclcpp::callback_group::CallbackGroup::SharedPtr group = nullptr);

template<typename ParamTypeT>
std::shared_future<ParamTypeT>
async_get_parameter(
const std::string & node_name, const parameter::ParameterName & key,
std::function<void(std::shared_future<ParamTypeT>)> callback = nullptr);

std::shared_future<std::vector<parameter::ParameterContainer>>
async_get_parameters(
const std::string & node_name, const std::vector<parameter::ParameterName> & parameter_names,
std::function<void(std::shared_future<std::vector<parameter::ParameterContainer>>)> callback =
nullptr);

std::shared_future<bool>
async_has_parameter(
const std::string & node_name, const parameter::ParameterName & parameter_name,
std::function<void(std::shared_future<bool>)> callback = nullptr);

std::shared_future<std::vector<bool>>
async_has_parameters(
const std::string & node_name, const std::vector<parameter::ParameterName> & parameter_names,
std::function<void(std::shared_future<std::vector<bool>>)> callback = nullptr);

template<typename ParamTypeT>
std::shared_future<bool>
async_set_parameter(
const std::string & node_name, const parameter::ParameterName & key,
const ParamTypeT & value, std::function<void(std::shared_future<bool>)> callback = nullptr);

std::shared_future<bool>
async_set_parameters(
const std::string & node_name,
const std::vector<parameter::ParameterContainer> & key_values,
std::function<void(std::shared_future<bool>)> callback = nullptr);

private:
RCLCPP_DISABLE_COPY(Node);

Expand All @@ -148,6 +184,20 @@ class Node
const std::string & service_name,
std::shared_ptr<rclcpp::service::ServiceBase> serv_base_ptr,
rclcpp::callback_group::CallbackGroup::SharedPtr group);

std::map<parameter::ParameterName, parameter::ParameterContainer> parameters_;

template<typename ParamTypeT>
ParamTypeT get_parameter(const parameter::ParameterName & key) const;

std::vector<parameter::ParameterContainer>
get_parameters(const std::vector<parameter::ParameterQuery> & query) const;

bool
has_parameter(const parameter::ParameterName & parameter_name) const;

template<typename ParamTypeT>
void set_parameter(const parameter::ParameterName & key, const ParamTypeT & value);
};

} /* namespace node */
Expand Down
Loading