Compare commits

...

8 Commits

Author SHA1 Message Date
Dirk Thomas
f28bb11078 Merge pull request #255 from ros2/fix_cpplint
comply with stricter cpplint rules
2016-10-03 16:17:03 -07:00
Dirk Thomas
29a1bd44dc comply with stricter cpplint rules 2016-10-01 11:23:53 -07:00
William Woodall
4e74edf8d4 fixup comment 2016-09-15 15:41:48 -07:00
William Woodall
6ea435f743 Issue 251 wjwwood (#252)
* removed warning in windows

* removed warning in windows

* fixup
2016-09-06 16:35:10 -07:00
Rohan Agrawal
902d558e64 Get single parameter (#245)
* added function to get parameter by exact name

* added ros1 style get_parameter for parameter variant

* added ros1 style get_param for non-variant types

* Make the get_parameter functions call a private base function

* Parameter Variant requires name in constructor

* Cleaned up to no longer need private function

* Made exception message more clear
2016-08-01 19:49:21 -07:00
Rohan Agrawal
1402715d76 Added basic hook for parameter changes (#244)
* Added basic hook for parameter changes

* Rename hook and add docblock
2016-07-28 18:01:24 -07:00
Dirk Thomas
8c5f6e4e06 Merge pull request #242 from SantiagoMunoz/setparameters
Added missing variable initialization in Node constructor
2016-07-20 08:17:16 -07:00
Santiago Munoz
2401c0f197 Added missing variable initialization in Node constructor 2016-07-20 16:56:33 +02:00
19 changed files with 103 additions and 6 deletions

View File

@@ -74,6 +74,8 @@ rcl_allocator_t get_rcl_allocator(Alloc & allocator)
rcl_allocator.deallocate = &retyped_deallocate<T, Alloc>;
rcl_allocator.reallocate = &retyped_reallocate<T, Alloc>;
rcl_allocator.state = &allocator;
#else
(void)allocator; // Remove warning
#endif
return rcl_allocator;
}

View File

@@ -21,6 +21,7 @@
#include <memory>
#include <stdexcept>
#include <type_traits>
#include <utility>
#include "rclcpp/allocator/allocator_common.hpp"
#include "rclcpp/function_traits.hpp"

View File

@@ -21,6 +21,7 @@
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include "rclcpp/macros.hpp"
#include "rclcpp/visibility_control.hpp"

View File

@@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <memory>
#include <utility>
#ifndef RCLCPP__MACROS_HPP_
#define RCLCPP__MACROS_HPP_

View File

@@ -20,6 +20,7 @@
#include <cstdint>
#include <memory>
#include <mutex>
#include <utility>
#include <vector>
#include "rclcpp/allocator/allocator_common.hpp"

View File

@@ -253,6 +253,18 @@ public:
std::vector<rclcpp::parameter::ParameterVariant>
get_parameters(const std::vector<std::string> & names) const;
RCLCPP_PUBLIC
const rclcpp::parameter::ParameterVariant
get_parameter(const std::string & name) const;
RCLCPP_PUBLIC
bool get_parameter(
const std::string & name,
rclcpp::parameter::ParameterVariant & parameter) const;
template<typename ParameterT>
bool get_parameter(const std::string & name, ParameterT & parameter) const;
RCLCPP_PUBLIC
std::vector<rcl_interfaces::msg::ParameterDescriptor>
describe_parameters(const std::vector<std::string> & names) const;
@@ -353,6 +365,14 @@ public:
size_t
count_graph_users();
/// Register the callback for parameter changes
/**
* \param[in] User defined callback function, It is expected to atomically set parameters.
* \note Repeated invocations of this function will overwrite previous callbacks
*/
template<typename CallbackT>
void register_param_change_callback(CallbackT && callback);
std::atomic_bool has_executor;
private:
@@ -400,6 +420,10 @@ private:
/* graph_users_count_ is atomic so that it can be accessed without acquiring the graph_mutex_ */
std::atomic_size_t graph_users_count_;
std::function<typename rcl_interfaces::msg::SetParametersResult(
const typename std::vector<rclcpp::parameter::ParameterVariant> &
)> parameters_callback_ = nullptr;
std::map<std::string, rclcpp::parameter::ParameterVariant> parameters_;
publisher::Publisher<rcl_interfaces::msg::ParameterEvent>::SharedPtr events_publisher_;

View File

@@ -362,6 +362,22 @@ Node::create_service(
return serv;
}
template<typename CallbackT>
void Node::register_param_change_callback(CallbackT && callback)
{
this->parameters_callback_ = callback;
}
template<typename ParameterT>
bool Node::get_parameter(const std::string & name, ParameterT & parameter) const
{
rclcpp::parameter::ParameterVariant parameter_variant(name, parameter);
bool result = get_parameter(name, parameter_variant);
parameter = parameter_variant.get_value<ParameterT>();
return result;
}
} // namespace node
} // namespace rclcpp

View File

@@ -16,6 +16,7 @@
#define RCLCPP__PARAMETER_CLIENT_HPP_
#include <string>
#include <utility>
#include <vector>
#include "rcl_interfaces/msg/parameter.hpp"

View File

@@ -15,6 +15,8 @@
#ifndef RCLCPP__STRATEGIES__MESSAGE_POOL_MEMORY_STRATEGY_HPP_
#define RCLCPP__STRATEGIES__MESSAGE_POOL_MEMORY_STRATEGY_HPP_
#include <memory>
#include "rclcpp/macros.hpp"
#include "rclcpp/message_memory_strategy.hpp"
#include "rclcpp/visibility_control.hpp"

View File

@@ -21,6 +21,7 @@
#include <sstream>
#include <thread>
#include <type_traits>
#include <utility>
#include "rclcpp/function_traits.hpp"
#include "rclcpp/macros.hpp"

View File

@@ -16,6 +16,7 @@
#include <chrono>
#include <cstdio>
#include <memory>
#include <string>
#include "rcl/graph.h"
@@ -80,7 +81,8 @@ ClientBase::wait_for_service_nanoseconds(std::chrono::nanoseconds timeout)
throw InvalidNodeError();
}
auto event = node_ptr->get_graph_event();
// update the time even on the first loop to account for time in first server_is_read()
// update the time even on the first loop to account for time spent in the first call
// to this->server_is_ready()
std::chrono::nanoseconds time_to_wait = timeout - (std::chrono::steady_clock::now() - start);
if (timeout > std::chrono::nanoseconds(0) && time_to_wait < std::chrono::nanoseconds(0)) {
// Do not allow the time_to_wait to become negative when timeout was originally positive.

View File

@@ -13,6 +13,7 @@
// limitations under the License.
#include <algorithm>
#include <memory>
#include <string>
#include <type_traits>

View File

@@ -16,6 +16,7 @@
#include <cstdio>
#include <exception>
#include <memory>
#include <string>
#include <vector>

View File

@@ -14,6 +14,8 @@
#include "rclcpp/memory_strategies.hpp"
#include <memory>
#include "rclcpp/strategies/allocator_memory_strategy.hpp"
using rclcpp::memory_strategies::allocator_memory_strategy::AllocatorMemoryStrategy;

View File

@@ -15,6 +15,7 @@
#include <algorithm>
#include <limits>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
@@ -39,7 +40,7 @@ Node::Node(
rclcpp::context::Context::SharedPtr context,
bool use_intra_process_comms)
: name_(node_name), context_(context),
number_of_subscriptions_(0), number_of_timers_(0), number_of_services_(0),
number_of_subscriptions_(0), number_of_timers_(0), number_of_services_(0), number_of_clients_(0),
use_intra_process_comms_(use_intra_process_comms), notify_guard_condition_is_valid_(false),
graph_listener_(context->get_sub_context<rclcpp::graph_listener::GraphListener>()),
should_add_to_graph_listener_(true), graph_users_count_(0)
@@ -189,6 +190,18 @@ Node::set_parameters_atomically(
std::map<std::string, rclcpp::parameter::ParameterVariant> tmp_map;
auto parameter_event = std::make_shared<rcl_interfaces::msg::ParameterEvent>();
// TODO(jacquelinekay): handle parameter constraints
rcl_interfaces::msg::SetParametersResult result;
if (parameters_callback_) {
result = parameters_callback_(parameters);
} else {
result.successful = true;
}
if (!result.successful) {
return result;
}
for (auto p : parameters) {
if (parameters_.find(p.get_name()) == parameters_.end()) {
if (p.get_type() != rclcpp::parameter::ParameterType::PARAMETER_NOT_SET) {
@@ -206,10 +219,6 @@ Node::set_parameters_atomically(
tmp_map.insert(parameters_.begin(), parameters_.end());
std::swap(tmp_map, parameters_);
// TODO(jacquelinekay): handle parameter constraints
rcl_interfaces::msg::SetParametersResult result;
result.successful = true;
events_publisher_->publish(parameter_event);
return result;
@@ -234,6 +243,31 @@ Node::get_parameters(
return results;
}
const rclcpp::parameter::ParameterVariant
Node::get_parameter(const std::string & name) const
{
rclcpp::parameter::ParameterVariant parameter;
if (get_parameter(name, parameter)) {
return parameter;
} else {
throw std::out_of_range("Parameter '" + name + "' not set");
}
}
bool Node::get_parameter(const std::string & name,
rclcpp::parameter::ParameterVariant & parameter) const
{
std::lock_guard<std::mutex> lock(mutex_);
if (parameters_.count(name)) {
parameter = parameters_.at(name);
return true;
} else {
return false;
}
}
std::vector<rcl_interfaces::msg::ParameterDescriptor>
Node::describe_parameters(
const std::vector<std::string> & names) const

View File

@@ -15,6 +15,7 @@
#include "rclcpp/parameter_client.hpp"
#include <algorithm>
#include <memory>
#include <string>
#include <vector>

View File

@@ -15,6 +15,7 @@
#include "rclcpp/parameter_service.hpp"
#include <algorithm>
#include <memory>
#include <vector>
using rclcpp::parameter_service::ParameterService;

View File

@@ -15,6 +15,7 @@
#include "rclcpp/subscription.hpp"
#include <cstdio>
#include <memory>
#include <string>
#include "rmw/error_handling.h"

View File

@@ -17,6 +17,8 @@
#define RCLCPP_BUILDING_LIBRARY 1 // Prevent including unavailable symbols
#include <rclcpp/mapped_ring_buffer.hpp>
#include <memory>
/*
Tests get_copy and pop on an empty mrb.
*/