Skip to content

Commit f8976fc

Browse files
committed
add helper for evaluation (qos, publish, publish qos)
1 parent 6241a0e commit f8976fc

File tree

10 files changed

+252
-6
lines changed

10 files changed

+252
-6
lines changed

controller_manager/include/controller_manager/controller_manager.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ class ControllerManager : public rclcpp::Node
201201
CONTROLLER_MANAGER_PUBLIC
202202
unsigned int get_update_rate() const;
203203

204+
CONTROLLER_MANAGER_PUBLIC
205+
rmw_qos_profile_t determine_qos_profile(const std::string & key) const;
206+
204207
CONTROLLER_MANAGER_PUBLIC
205208
bool is_central_controller_manager() const;
206209

@@ -478,6 +481,10 @@ class ControllerManager : public rclcpp::Node
478481
bool sub_controller_manager_ = false;
479482
bool central_controller_manager_ = false;
480483
bool use_multiple_nodes_ = false;
484+
std::shared_ptr<evaluation_helper::Evaluation_Helper> qos_helper_;
485+
std::string handles_qos_key_ = "system_default";
486+
bool publish_evaluation_msg_ = true;
487+
std::string evaluation_qos_key_ = "system_default";
481488
std::vector<std::string> command_interfaces_to_export_ = std::vector<std::string>({});
482489
std::vector<std::string> state_interfaces_to_export_ = std::vector<std::string>({});
483490

controller_manager/src/controller_manager.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "controller_manager_msgs/msg/publisher_description.hpp"
2727

2828
#include "hardware_interface/distributed_control_interface/command_forwarder.hpp"
29+
#include "hardware_interface/distributed_control_interface/evaluation_helper.hpp"
2930
#include "hardware_interface/distributed_control_interface/state_publisher.hpp"
3031
#include "hardware_interface/handle.hpp"
3132
#include "hardware_interface/types/lifecycle_state_names.hpp"
@@ -408,6 +409,24 @@ void ControllerManager::get_and_initialize_distributed_parameters()
408409
get_logger(), "'use_multiple_nodes' parameter not set, using default value:%s",
409410
use_multiple_nodes_ ? "true" : "false");
410411
}
412+
if (!get_parameter("handles_qos_key", handles_qos_key_))
413+
{
414+
RCLCPP_WARN(
415+
get_logger(), "'handles_qos_key' parameter not set, using default value:%s",
416+
handles_qos_key_.c_str());
417+
}
418+
if (!get_parameter("publish_evaluation_msg", publish_evaluation_msg_))
419+
{
420+
RCLCPP_WARN(
421+
get_logger(), "'publish_evaluation_msg' parameter not set, using default value:%s",
422+
publish_evaluation_msg_ ? "true" : "false");
423+
}
424+
if (!get_parameter("evaluation_qos_key", evaluation_qos_key_))
425+
{
426+
RCLCPP_WARN(
427+
get_logger(), "'evaluation_qos_key' parameter not set, using default value:%s",
428+
evaluation_qos_key_.c_str());
429+
}
411430
}
412431

413432
void ControllerManager::configure_controller_manager()
@@ -462,8 +481,42 @@ ControllerManager::controller_manager_type ControllerManager::determine_controll
462481
return controller_manager_type::unkown_type;
463482
}
464483

484+
rmw_qos_profile_t ControllerManager::determine_qos_profile(const std::string & key) const
485+
{
486+
if (key == "sensor_data")
487+
{
488+
return evaluation_helper::rmw_qos_profile_sensor_data;
489+
}
490+
else if (key == "sensor_data_1")
491+
{
492+
return evaluation_helper::rmw_qos_profile_sensor_data_1;
493+
}
494+
else if (key == "sensor_data_100")
495+
{
496+
return evaluation_helper::rmw_qos_profile_sensor_data_100;
497+
}
498+
else if (key == "reliable")
499+
{
500+
return evaluation_helper::rmw_qos_profile_reliable;
501+
}
502+
else if (key == "reliable_100")
503+
{
504+
return evaluation_helper::rmw_qos_profile_reliable_100;
505+
}
506+
else if (key == "system_default")
507+
{
508+
return evaluation_helper::rmw_qos_profile_system_default;
509+
}
510+
throw std::runtime_error("Given qos profile not know");
511+
}
512+
465513
void ControllerManager::init_distributed_sub_controller_manager()
466514
{
515+
// just for evaluation of concept
516+
auto handle_qos_profile = determine_qos_profile(handles_qos_key_);
517+
auto evaluation_qos_profile = determine_qos_profile(evaluation_qos_key_);
518+
qos_helper_ = evaluation_helper::Evaluation_Helper::create_instance(
519+
handle_qos_profile, publish_evaluation_msg_, evaluation_qos_profile);
467520
// if only one node per sub controller manager is used
468521
if (!use_multiple_nodes())
469522
{
@@ -510,6 +563,11 @@ void ControllerManager::init_distributed_sub_controller_manager()
510563

511564
void ControllerManager::init_distributed_central_controller_manager()
512565
{
566+
// just for evaluation of concept
567+
auto handle_qos_profile = determine_qos_profile(handles_qos_key_);
568+
auto evaluation_qos_profile = determine_qos_profile(evaluation_qos_key_);
569+
qos_helper_ = evaluation_helper::Evaluation_Helper::create_instance(
570+
handle_qos_profile, publish_evaluation_msg_, evaluation_qos_profile);
513571
if (!use_multiple_nodes())
514572
{
515573
rclcpp::NodeOptions node_options;

hardware_interface/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ add_library(hardware_interface SHARED
2929
src/component_parser.cpp
3030
src/hardware_interface/distributed_control_interface/command_forwarder.cpp
3131
src/hardware_interface/distributed_control_interface/state_publisher.cpp
32+
src/hardware_interface/distributed_control_interface/evaluation_helper.cpp
3233
src/resource_manager.cpp
3334
src/sensor.cpp
3435
src/system.cpp

hardware_interface/include/hardware_interface/distributed_control_interface/command_forwarder.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <string>
77
#include <vector>
88

9+
#include "hardware_interface/distributed_control_interface/evaluation_helper.hpp"
910
#include "hardware_interface/distributed_control_interface/publisher_description.hpp"
1011
#include "hardware_interface/loaned_command_interface.hpp"
1112

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// Copyright 2020 - 2021 ros2_control Development Team
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef DISTRIBUTED_CONTROL__QOS_PROFILES_HELPER_HPP_
16+
#define DISTRIBUTED_CONTROL__QOS_PROFILES_HELPER_HPP_
17+
18+
#include <memory>
19+
#include <mutex>
20+
21+
#include "rmw/qos_profiles.h"
22+
#include "rmw/types.h"
23+
24+
namespace evaluation_helper
25+
{
26+
27+
// All profiles used for evaluation, copy them to make sure that exactly those params are used.
28+
static const rmw_qos_profile_t rmw_qos_profile_sensor_data = {
29+
RMW_QOS_POLICY_HISTORY_KEEP_LAST,
30+
5,
31+
RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT,
32+
RMW_QOS_POLICY_DURABILITY_VOLATILE,
33+
RMW_QOS_DEADLINE_DEFAULT,
34+
RMW_QOS_LIFESPAN_DEFAULT,
35+
RMW_QOS_POLICY_LIVELINESS_SYSTEM_DEFAULT,
36+
RMW_QOS_LIVELINESS_LEASE_DURATION_DEFAULT,
37+
false};
38+
39+
static const rmw_qos_profile_t rmw_qos_profile_sensor_data_1 = {
40+
RMW_QOS_POLICY_HISTORY_KEEP_LAST,
41+
1,
42+
RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT,
43+
RMW_QOS_POLICY_DURABILITY_VOLATILE,
44+
RMW_QOS_DEADLINE_DEFAULT,
45+
RMW_QOS_LIFESPAN_DEFAULT,
46+
RMW_QOS_POLICY_LIVELINESS_SYSTEM_DEFAULT,
47+
RMW_QOS_LIVELINESS_LEASE_DURATION_DEFAULT,
48+
false};
49+
50+
static const rmw_qos_profile_t rmw_qos_profile_sensor_data_100 = {
51+
RMW_QOS_POLICY_HISTORY_KEEP_LAST,
52+
100,
53+
RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT,
54+
RMW_QOS_POLICY_DURABILITY_VOLATILE,
55+
RMW_QOS_DEADLINE_DEFAULT,
56+
RMW_QOS_LIFESPAN_DEFAULT,
57+
RMW_QOS_POLICY_LIVELINESS_SYSTEM_DEFAULT,
58+
RMW_QOS_LIVELINESS_LEASE_DURATION_DEFAULT,
59+
false};
60+
61+
static const rmw_qos_profile_t rmw_qos_profile_reliable = {
62+
RMW_QOS_POLICY_HISTORY_KEEP_LAST,
63+
1,
64+
RMW_QOS_POLICY_RELIABILITY_RELIABLE,
65+
RMW_QOS_POLICY_DURABILITY_VOLATILE,
66+
RMW_QOS_DEADLINE_DEFAULT,
67+
RMW_QOS_LIFESPAN_DEFAULT,
68+
RMW_QOS_POLICY_LIVELINESS_SYSTEM_DEFAULT,
69+
RMW_QOS_LIVELINESS_LEASE_DURATION_DEFAULT,
70+
false};
71+
72+
static const rmw_qos_profile_t rmw_qos_profile_reliable_100 = {
73+
RMW_QOS_POLICY_HISTORY_KEEP_LAST,
74+
100,
75+
RMW_QOS_POLICY_RELIABILITY_RELIABLE,
76+
RMW_QOS_POLICY_DURABILITY_VOLATILE,
77+
RMW_QOS_DEADLINE_DEFAULT,
78+
RMW_QOS_LIFESPAN_DEFAULT,
79+
RMW_QOS_POLICY_LIVELINESS_SYSTEM_DEFAULT,
80+
RMW_QOS_LIVELINESS_LEASE_DURATION_DEFAULT,
81+
false};
82+
83+
static const rmw_qos_profile_t rmw_qos_profile_system_default = {
84+
RMW_QOS_POLICY_HISTORY_SYSTEM_DEFAULT,
85+
RMW_QOS_POLICY_DEPTH_SYSTEM_DEFAULT,
86+
RMW_QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT,
87+
RMW_QOS_POLICY_DURABILITY_SYSTEM_DEFAULT,
88+
RMW_QOS_DEADLINE_DEFAULT,
89+
RMW_QOS_LIFESPAN_DEFAULT,
90+
RMW_QOS_POLICY_LIVELINESS_SYSTEM_DEFAULT,
91+
RMW_QOS_LIVELINESS_LEASE_DURATION_DEFAULT,
92+
false};
93+
94+
class Evaluation_Helper
95+
{
96+
protected:
97+
Evaluation_Helper(
98+
const rmw_qos_profile_t & qos_profile, const bool & publish_evaluation_msg,
99+
const rmw_qos_profile_t & evaluation_qos_profile)
100+
: qos_profile_(qos_profile),
101+
publish_evaluation_msg_(publish_evaluation_msg),
102+
evaluation_qos_profile_(evaluation_qos_profile)
103+
{
104+
}
105+
106+
public:
107+
/**
108+
* Evaluation_Helpers should not be cloneable.
109+
*/
110+
Evaluation_Helper(Evaluation_Helper & other) = delete;
111+
/**
112+
* Evaluation_Helpers should not be assignable.
113+
*/
114+
void operator=(const Evaluation_Helper &) = delete;
115+
116+
static std::shared_ptr<Evaluation_Helper> create_instance(
117+
const rmw_qos_profile_t & qos_profile, const bool & publish_evaluation_msg,
118+
const rmw_qos_profile_t & evaluation_qos_profile)
119+
{
120+
std::lock_guard<std::mutex> lock(mutex_);
121+
if (qos_profile_instance_ == nullptr)
122+
{
123+
qos_profile_instance_ = std::shared_ptr<Evaluation_Helper>(
124+
new Evaluation_Helper(qos_profile, publish_evaluation_msg, evaluation_qos_profile));
125+
}
126+
return qos_profile_instance_;
127+
}
128+
129+
static std::shared_ptr<Evaluation_Helper> get_instance()
130+
{
131+
std::lock_guard<std::mutex> lock(mutex_);
132+
if (qos_profile_instance_ == nullptr)
133+
{
134+
throw std::runtime_error("Evaluation_Helper not initialized!");
135+
}
136+
return qos_profile_instance_;
137+
}
138+
139+
rmw_qos_profile_t get_qos_profile() const { return qos_profile_; }
140+
141+
rmw_qos_profile_t get_evaluation_qos_profile() const { return evaluation_qos_profile_; }
142+
143+
bool publish_evaluation_msg() const { return publish_evaluation_msg_; }
144+
145+
protected:
146+
static std::shared_ptr<Evaluation_Helper> qos_profile_instance_;
147+
static std::mutex mutex_;
148+
149+
const rmw_qos_profile_t qos_profile_;
150+
const bool publish_evaluation_msg_;
151+
const rmw_qos_profile_t evaluation_qos_profile_;
152+
};
153+
154+
} // namespace evaluation_helper
155+
156+
#endif // DISTRIBUTED_CONTROL__EVALUATION_HELPER_HPP_

hardware_interface/include/hardware_interface/distributed_control_interface/state_publisher.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <string>
66
#include <vector>
77

8+
#include "hardware_interface/distributed_control_interface/evaluation_helper.hpp"
89
#include "hardware_interface/loaned_state_interface.hpp"
910

1011
#include "controller_manager_msgs/msg/publisher_description.hpp"

hardware_interface/include/hardware_interface/handle.hpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <string>
1919
#include <utility>
2020

21+
#include "hardware_interface/distributed_control_interface/evaluation_helper.hpp"
2122
#include "hardware_interface/distributed_control_interface/publisher_description.hpp"
2223
#include "hardware_interface/macros.hpp"
2324
#include "hardware_interface/visibility_control.h"
@@ -206,9 +207,13 @@ class DistributedReadOnlyHandle : public ReadOnlyHandle
206207
get_underscore_separated_name() + "_state_interface_subscriber", namespace_, node_options,
207208
false);
208209
}
210+
211+
auto evaluation_helper = evaluation_helper::Evaluation_Helper::get_instance();
212+
rclcpp::QoS qos_profile(
213+
rclcpp::QoSInitialization::from_rmw(evaluation_helper->get_qos_profile()));
209214
// subscribe to topic provided by StatePublisher
210215
state_value_sub_ = node_->create_subscription<std_msgs::msg::Float64>(
211-
get_value_topic_name_, 10,
216+
get_value_topic_name_, qos_profile,
212217
std::bind(&DistributedReadOnlyHandle::get_value_cb, this, std::placeholders::_1));
213218
}
214219

@@ -354,14 +359,17 @@ class DistributedReadWriteHandle : public ReadWriteHandle
354359
node_options, false);
355360
}
356361

362+
auto evaluation_helper = evaluation_helper::Evaluation_Helper::get_instance();
363+
rclcpp::QoS qos_profile(
364+
rclcpp::QoSInitialization::from_rmw(evaluation_helper->get_qos_profile()));
357365
// subscribe to topic provided by CommandForwarder
358366
command_value_sub_ = node_->create_subscription<std_msgs::msg::Float64>(
359-
get_value_topic_name_, 10,
367+
get_value_topic_name_, qos_profile,
360368
std::bind(&DistributedReadWriteHandle::get_value_cb, this, std::placeholders::_1));
361369

362370
// create publisher so that we can forward the commands
363371
command_value_pub_ =
364-
node_->create_publisher<std_msgs::msg::Float64>(forward_command_topic_name_, 10);
372+
node_->create_publisher<std_msgs::msg::Float64>(forward_command_topic_name_, qos_profile);
365373
}
366374

367375
explicit DistributedReadWriteHandle(const std::string & interface_name)

hardware_interface/src/hardware_interface/distributed_control_interface/command_forwarder.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ CommandForwarder::CommandForwarder(
3232
namespace_, node_options, false);
3333
}
3434

35-
state_value_pub_ = node_->create_publisher<std_msgs::msg::Float64>(topic_name_, 10);
35+
auto evaluation_helper = evaluation_helper::Evaluation_Helper::get_instance();
36+
rclcpp::QoS qos_profile(
37+
rclcpp::QoSInitialization::from_rmw(evaluation_helper->get_qos_profile()));
38+
state_value_pub_ = node_->create_publisher<std_msgs::msg::Float64>(topic_name_, qos_profile);
3639
// TODO(Manuel): We should check if we cannot detect changes to LoanedStateInterface's value and only publish then
3740
timer_ = node_->create_wall_timer(
3841
period_in_ms_, std::bind(&CommandForwarder::publish_value_on_timer, this));
@@ -89,9 +92,12 @@ CommandForwarder::create_publisher_description_msg() const
8992

9093
void CommandForwarder::subscribe_to_command_publisher(const std::string & topic_name)
9194
{
95+
auto evaluation_helper = evaluation_helper::Evaluation_Helper::get_instance();
96+
rclcpp::QoS qos_profile(
97+
rclcpp::QoSInitialization::from_rmw(evaluation_helper->get_qos_profile()));
9298
subscription_topic_name_ = topic_name;
9399
command_subscription_ = node_->create_subscription<std_msgs::msg::Float64>(
94-
subscription_topic_name_, 10,
100+
subscription_topic_name_, qos_profile,
95101
std::bind(&CommandForwarder::forward_command, this, std::placeholders::_1));
96102
}
97103

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "hardware_interface/distributed_control_interface/evaluation_helper.hpp"
2+
3+
std::shared_ptr<evaluation_helper::Evaluation_Helper>
4+
evaluation_helper::Evaluation_Helper::qos_profile_instance_{nullptr};
5+
std::mutex evaluation_helper::Evaluation_Helper::mutex_;

hardware_interface/src/hardware_interface/distributed_control_interface/state_publisher.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ StatePublisher::StatePublisher(
3232
node_options, false);
3333
}
3434

35-
state_value_pub_ = node_->create_publisher<std_msgs::msg::Float64>(topic_name_, 10);
35+
auto evaluation_helper = evaluation_helper::Evaluation_Helper::get_instance();
36+
rclcpp::QoS qos_profile(
37+
rclcpp::QoSInitialization::from_rmw(evaluation_helper->get_qos_profile()));
38+
state_value_pub_ = node_->create_publisher<std_msgs::msg::Float64>(topic_name_, qos_profile);
3639
// TODO(Manuel): We should check if we cannot detect changes to LoanedStateInterface's value and only publish then
3740
timer_ = node_->create_wall_timer(
3841
period_in_ms_, std::bind(&StatePublisher::publish_value_on_timer, this));

0 commit comments

Comments
 (0)