From e90583046e8d5656078a25d211dd46817b95d558 Mon Sep 17 00:00:00 2001 From: Karsten Knese Date: Mon, 18 Jun 2018 14:31:24 +0200 Subject: [PATCH 1/4] ParameterVariant -> Parameter --- controller_parameter_server/src/parameter_server.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/controller_parameter_server/src/parameter_server.cpp b/controller_parameter_server/src/parameter_server.cpp index ecd23cd287..c24c47cae0 100644 --- a/controller_parameter_server/src/parameter_server.cpp +++ b/controller_parameter_server/src/parameter_server.cpp @@ -48,18 +48,14 @@ ParameterServer::load_parameters(const std::string & yaml_config_file) auto key_values = parser.get_key_value_pairs(); for (auto pair : key_values) { - this->set_parameters({rclcpp::parameter::ParameterVariant(pair.first, pair.second)}); + this->set_parameters({rclcpp::Parameter(pair.first, pair.second)}); } } void ParameterServer::load_parameters(const std::string & key, const std::string & value) { - if (!parameter_service_) { - throw std::runtime_error("parameter server is not initialized"); - } - - this->set_parameters({rclcpp::parameter::ParameterVariant(key, value)}); + this->set_parameters({rclcpp::Parameter(key, value)}); } } // namespace controller_parameter_server From 308ba7e31ad681eb41238437c37bb1f49c5dc2dd Mon Sep 17 00:00:00 2001 From: Karsten Knese Date: Mon, 18 Jun 2018 14:35:18 +0200 Subject: [PATCH 2/4] remove explicit parameter service --- .../controller_parameter_server/parameter_server.hpp | 7 ------- .../src/controller_parameter_server.cpp | 1 - controller_parameter_server/src/parameter_server.cpp | 11 ----------- .../test/test_parameter_server.cpp | 10 ---------- 4 files changed, 29 deletions(-) diff --git a/controller_parameter_server/include/controller_parameter_server/parameter_server.hpp b/controller_parameter_server/include/controller_parameter_server/parameter_server.hpp index 3d0a8527bf..fddb769257 100644 --- a/controller_parameter_server/include/controller_parameter_server/parameter_server.hpp +++ b/controller_parameter_server/include/controller_parameter_server/parameter_server.hpp @@ -35,10 +35,6 @@ class ParameterServer : public rclcpp::Node virtual ~ParameterServer() = default; - CONTROLLER_PARAMETER_SERVER_PUBLIC - void - init(); - CONTROLLER_PARAMETER_SERVER_PUBLIC void load_parameters(const std::string & yaml_config_file); @@ -46,9 +42,6 @@ class ParameterServer : public rclcpp::Node CONTROLLER_PARAMETER_SERVER_PUBLIC void load_parameters(const std::string & key, const std::string & value); - -private: - std::shared_ptr parameter_service_; }; } // namespace controller_parameter_server diff --git a/controller_parameter_server/src/controller_parameter_server.cpp b/controller_parameter_server/src/controller_parameter_server.cpp index 7c4fdc825d..0dfe1b1694 100644 --- a/controller_parameter_server/src/controller_parameter_server.cpp +++ b/controller_parameter_server/src/controller_parameter_server.cpp @@ -34,7 +34,6 @@ int main(int argc, char ** argv) } auto ps = std::make_shared(); - ps->init(); ps->load_parameters(argv[1]); rclcpp::spin(ps); diff --git a/controller_parameter_server/src/parameter_server.cpp b/controller_parameter_server/src/parameter_server.cpp index c24c47cae0..3cf7f9907c 100644 --- a/controller_parameter_server/src/parameter_server.cpp +++ b/controller_parameter_server/src/parameter_server.cpp @@ -25,20 +25,9 @@ ParameterServer::ParameterServer() : rclcpp::Node("controller_parameter_server") {} -void -ParameterServer::init() -{ - parameter_service_ = - std::make_shared(shared_from_this()); -} - void ParameterServer::load_parameters(const std::string & yaml_config_file) { - if (!parameter_service_) { - throw std::runtime_error("parameter server is not initialized"); - } - if (yaml_config_file.empty()) { throw std::runtime_error("yaml config file path is empty"); } diff --git a/controller_parameter_server/test/test_parameter_server.cpp b/controller_parameter_server/test/test_parameter_server.cpp index 6aeb9656f8..d7cac5b8f9 100644 --- a/controller_parameter_server/test/test_parameter_server.cpp +++ b/controller_parameter_server/test/test_parameter_server.cpp @@ -38,17 +38,8 @@ class TestControllerParameterServer : public ::testing::Test } }; -TEST_F(TestControllerParameterServer, init) { - auto ps = std::make_shared(); - EXPECT_THROW(ps->load_parameters("key", "value"), std::runtime_error); - - ps->init(); - EXPECT_NO_THROW(ps->load_parameters("key", "value")); -} - TEST_F(TestControllerParameterServer, init_key_value) { auto ps = std::make_shared(); - ps->init(); std::map parameters = {{ @@ -81,7 +72,6 @@ TEST_F(TestControllerParameterServer, load_config_file) { std::string file_path = std::string(yaml_file); auto ps = std::make_shared(); - ps->init(); ps->load_parameters(file_path); auto client_node = std::make_shared("test_parameter_client_node"); From 2ad25996813412ec6c7d804a07977f7df8c4e544 Mon Sep 17 00:00:00 2001 From: Karsten Knese Date: Mon, 18 Jun 2018 14:52:11 +0200 Subject: [PATCH 3/4] comply with new uncrustify --- .../test/test_parameter_server.cpp | 40 +++++++++---------- .../test/test_yaml_parser.cpp | 32 +++++++-------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/controller_parameter_server/test/test_parameter_server.cpp b/controller_parameter_server/test/test_parameter_server.cpp index d7cac5b8f9..ec4f358951 100644 --- a/controller_parameter_server/test/test_parameter_server.cpp +++ b/controller_parameter_server/test/test_parameter_server.cpp @@ -43,10 +43,10 @@ TEST_F(TestControllerParameterServer, init_key_value) { std::map parameters = {{ - {"test_controller.joints.joint1", "joint1"}, - {"test_controller.joints.joint2", "joint2"}, - {"test_controller.joints.joint3", "joint3"} - }}; + {"test_controller.joints.joint1", "joint1"}, + {"test_controller.joints.joint2", "joint2"}, + {"test_controller.joints.joint3", "joint3"} + }}; for (auto param : parameters) { ps->load_parameters(param.first, param.second); @@ -95,25 +95,25 @@ TEST_F(TestControllerParameterServer, load_config_file) { std::vector expected_keys = {{ - ".controller_name", - ".controller_list.0", - ".controller_list.1", - ".test_joint_controller.joints", - ".test_trajectory_controller.joints.0.joint1.name", - ".test_trajectory_controller.joints.1", - ".test_trajectory_controller.joints.2" - }}; + ".controller_name", + ".controller_list.0", + ".controller_list.1", + ".test_joint_controller.joints", + ".test_trajectory_controller.joints.0.joint1.name", + ".test_trajectory_controller.joints.1", + ".test_trajectory_controller.joints.2" + }}; std::vector expected_values = {{ - "my_controller", - "my_controller1", - "my_controller2", - "my_joint1", - "my_joint1", - "my_joint2", - "my_joint3" - }}; + "my_controller", + "my_controller1", + "my_controller2", + "my_joint1", + "my_joint1", + "my_joint2", + "my_joint3" + }}; auto parameter_future = parameters_client->get_parameters(expected_keys); diff --git a/controller_parameter_server/test/test_yaml_parser.cpp b/controller_parameter_server/test/test_yaml_parser.cpp index cc3b69c735..c7300ed110 100644 --- a/controller_parameter_server/test/test_yaml_parser.cpp +++ b/controller_parameter_server/test/test_yaml_parser.cpp @@ -47,25 +47,25 @@ TEST_F(TestYamlParser, init) { std::vector expected_keys = {{ - ".controller_name", - ".controller_list.0", - ".controller_list.1", - ".test_joint_controller.joints", - ".test_trajectory_controller.joints.0.joint1.name", - ".test_trajectory_controller.joints.1", - ".test_trajectory_controller.joints.2" - }}; + ".controller_name", + ".controller_list.0", + ".controller_list.1", + ".test_joint_controller.joints", + ".test_trajectory_controller.joints.0.joint1.name", + ".test_trajectory_controller.joints.1", + ".test_trajectory_controller.joints.2" + }}; std::vector expected_values = {{ - "my_controller", - "my_controller1", - "my_controller2", - "my_joint1", - "my_joint1", - "my_joint2", - "my_joint3" - }}; + "my_controller", + "my_controller1", + "my_controller2", + "my_joint1", + "my_joint1", + "my_joint2", + "my_joint3" + }}; if (expected_keys.size() != expected_values.size()) { FAIL(); From cb2239f05471e0b1c0e367e13897c0ca41e94438 Mon Sep 17 00:00:00 2001 From: Karsten Knese Date: Mon, 18 Jun 2018 19:40:11 +0200 Subject: [PATCH 4/4] use ros2 class loader macros --- controller_manager/src/controller_manager.cpp | 2 +- controller_manager/test/test_controller/test_controller.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/controller_manager/src/controller_manager.cpp b/controller_manager/src/controller_manager.cpp index e01e274c49..b8ff5f78f9 100644 --- a/controller_manager/src/controller_manager.cpp +++ b/controller_manager/src/controller_manager.cpp @@ -21,7 +21,7 @@ #include "ament_index_cpp/get_resource.hpp" #include "ament_index_cpp/get_resources.hpp" -#include "class_loader/class_loader.h" +#include "class_loader/class_loader.hpp" #include "controller_interface/controller_interface.hpp" diff --git a/controller_manager/test/test_controller/test_controller.cpp b/controller_manager/test/test_controller/test_controller.cpp index 59fc35fe5f..9dd2f96f4c 100644 --- a/controller_manager/test/test_controller/test_controller.cpp +++ b/controller_manager/test/test_controller/test_controller.cpp @@ -42,7 +42,7 @@ TestController::on_configure(const rclcpp_lifecycle::State & previous_state) } // namespace test_controller -#include "class_loader/class_loader_register_macro.h" +#include "class_loader/register_macro.hpp" CLASS_LOADER_REGISTER_CLASS( test_controller::TestController, controller_interface::ControllerInterface)