diff --git a/controller_manager/CMakeLists.txt b/controller_manager/CMakeLists.txt index 59b20dbeaf..163a862eeb 100644 --- a/controller_manager/CMakeLists.txt +++ b/controller_manager/CMakeLists.txt @@ -19,7 +19,11 @@ find_package(hardware_interface REQUIRED) find_package(pluginlib REQUIRED) find_package(rclcpp REQUIRED) -add_library(controller_manager SHARED src/controller_manager.cpp src/controller_loader_pluginlib.cpp) +add_library(controller_manager SHARED + src/controller_manager.cpp + src/controller_loader_pluginlib.cpp + src/resource_manager.cpp +) target_include_directories(controller_manager PRIVATE include) ament_target_dependencies(controller_manager ament_index_cpp @@ -63,6 +67,10 @@ if(BUILD_TESTING) target_include_directories(test_controller PRIVATE include) target_link_libraries(test_controller controller_manager) target_compile_definitions(test_controller PRIVATE "CONTROLLER_MANAGER_BUILDING_DLL") + install(TARGETS test_controller + DESTINATION lib + ) + pluginlib_export_plugin_description_file(controller_interface test/test_controller.xml) ament_add_gmock( test_controller_manager @@ -99,11 +107,27 @@ if(BUILD_TESTING) test_robot_hardware ) - pluginlib_export_plugin_description_file(controller_interface test/test_controller.xml) - - install(TARGETS test_controller + add_library(test_hardware_resources SHARED + test/test_hardware_resources/test_actuator_hardware.cpp + test/test_hardware_resources/test_joint_component.cpp + test/test_hardware_resources/test_sensor_component.cpp + test/test_hardware_resources/test_sensor_hardware.cpp + test/test_hardware_resources/test_system_hardware.cpp) + ament_target_dependencies(test_hardware_resources + hardware_interface + pluginlib) + install(TARGETS test_hardware_resources DESTINATION lib ) + pluginlib_export_plugin_description_file( + hardware_interface test/test_hardware_resources.xml) + + ament_add_gtest( + test_resource_manager + test/test_resource_manager.cpp + ) + target_include_directories(test_resource_manager PRIVATE include src) + target_link_libraries(test_resource_manager controller_manager) endif() ament_export_libraries( diff --git a/controller_manager/include/controller_manager/controller_loader_pluginlib.hpp b/controller_manager/include/controller_manager/controller_loader_pluginlib.hpp index 6b56aa9684..6aadb2890a 100644 --- a/controller_manager/include/controller_manager/controller_loader_pluginlib.hpp +++ b/controller_manager/include/controller_manager/controller_loader_pluginlib.hpp @@ -36,10 +36,11 @@ class ControllerLoaderPluginlib : public ControllerLoaderInterface virtual ~ControllerLoaderPluginlib() = default; CONTROLLER_MANAGER_PUBLIC - controller_interface::ControllerInterfaceSharedPtr create(const std::string & controller_type); + controller_interface::ControllerInterfaceSharedPtr create(const std::string & controller_type) + override; CONTROLLER_MANAGER_PUBLIC - bool is_available(const std::string & controller_type) const; + bool is_available(const std::string & controller_type) const override; CONTROLLER_MANAGER_PUBLIC std::vector get_declared_classes() const override; diff --git a/controller_manager/src/resource_manager.cpp b/controller_manager/src/resource_manager.cpp new file mode 100644 index 0000000000..3bc702754f --- /dev/null +++ b/controller_manager/src/resource_manager.cpp @@ -0,0 +1,197 @@ +// Copyright 2020 Open Source Robotics Foundation, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include +#include + +#include "hardware_interface/components/component_info.hpp" +#include "hardware_interface/component_parser.hpp" +#include "hardware_interface/hardware_resources/actuator_hardware.hpp" +#include "hardware_interface/hardware_resources/hardware_info.hpp" +#include "hardware_interface/hardware_resources/sensor_hardware.hpp" +#include "hardware_interface/hardware_resources/system_hardware.hpp" + +#include "pluginlib/class_loader.hpp" + +#include "./resource_manager.hpp" + +namespace controller_manager +{ + +class ResourceStorage +{ + static constexpr const char * pkg_name = "hardware_interface"; + + static constexpr const char * joint_component_interface_name = + "hardware_interface::components::Joint"; + static constexpr const char * sensor_component_interface_name = + "hardware_interface::components::Sensor"; + + static constexpr const char * actuator_interface_name = + "hardware_interface::hardware_resources::ActuatorHardwareInterface"; + static constexpr const char * sensor_interface_name = + "hardware_interface::hardware_resources::SensorHardwareInterface"; + static constexpr const char * system_interface_name = + "hardware_interface::hardware_resources::SystemHardwareInterface"; + +public: + ResourceStorage() + : joint_component_loader_(pkg_name, joint_component_interface_name), + sensor_component_loader_(pkg_name, sensor_component_interface_name), + actuator_loader_(pkg_name, actuator_interface_name), + sensor_loader_(pkg_name, sensor_interface_name), + system_loader_(pkg_name, system_interface_name) + {} + + ~ResourceStorage() = default; + + void initialize_joint_component( + const hardware_interface::components::ComponentInfo & component_info) + { + joint_components_.emplace_back( + std::unique_ptr( + joint_component_loader_.createUnmanagedInstance(component_info.class_type))); + joint_components_.back()->configure(component_info); + } + + void initialize_sensor_component( + const hardware_interface::components::ComponentInfo & component_info) + { + sensor_components_.emplace_back( + std::unique_ptr( + sensor_component_loader_.createUnmanagedInstance(component_info.class_type))); + sensor_components_.back()->configure(component_info); + } + + template + void initialize_hardware( + const hardware_interface::hardware_resources::HardwareInfo & hardware_info, + pluginlib::ClassLoader & loader, + std::vector & container) + { + // hardware_class_type has to match class name in plugin xml description + // TODO(karsten1987) extract package from hardware_class_type + // e.g.: / + auto interface = std::unique_ptr( + loader.createUnmanagedInstance(hardware_info.hardware_class_type)); + HardwareT actuator(std::move(interface)); + container.emplace_back(std::move(actuator)); + container.back().configure(hardware_info); + } + + void initialize_actuator( + const hardware_interface::hardware_resources::HardwareInfo & hardware_info) + { + initialize_hardware( + hardware_info, actuator_loader_, actuators_); + } + + void initialize_sensor(const hardware_interface::hardware_resources::HardwareInfo & hardware_info) + { + initialize_hardware( + hardware_info, sensor_loader_, sensors_); + } + + void initialize_system(const hardware_interface::hardware_resources::HardwareInfo & hardware_info) + { + initialize_hardware( + hardware_info, system_loader_, systems_); + } + + // components plugins + pluginlib::ClassLoader joint_component_loader_; + pluginlib::ClassLoader sensor_component_loader_; + + std::vector> joint_components_; + std::vector> sensor_components_; + + // hardware plugins + pluginlib::ClassLoader + actuator_loader_; + pluginlib::ClassLoader + sensor_loader_; + pluginlib::ClassLoader + system_loader_; + + std::vector actuators_; + std::vector sensors_; + std::vector systems_; +}; + +ResourceManager::ResourceManager() +: resource_storage_(std::make_unique()) +{} + +ResourceManager::~ResourceManager() = default; + +ResourceManager::ResourceManager(const std::string & urdf) +: resource_storage_(std::make_unique()) +{ + const std::string system_type = "system"; + const std::string sensor_type = "sensor"; + const std::string actuator_type = "actuator"; + + auto hardware_info = hardware_interface::parse_control_resources_from_urdf(urdf); + + for (const auto & hardware : hardware_info) { + if (hardware.type == actuator_type) { + resource_storage_->initialize_actuator(hardware); + } + if (hardware.type == sensor_type) { + resource_storage_->initialize_sensor(hardware); + } + if (hardware.type == system_type) { + resource_storage_->initialize_system(hardware); + } + + for (const auto & joint : hardware.joints) { + resource_storage_->initialize_joint_component(joint); + } + + for (const auto & sensor : hardware.sensors) { + resource_storage_->initialize_sensor_component(sensor); + } + } +} + +size_t ResourceManager::joint_components_size() const +{ + return resource_storage_->joint_components_.size(); +} + +size_t ResourceManager::sensor_components_size() const +{ + return resource_storage_->sensor_components_.size(); +} + +size_t ResourceManager::actuator_interfaces_size() const +{ + return resource_storage_->actuators_.size(); +} + +size_t ResourceManager::sensor_interfaces_size() const +{ + return resource_storage_->sensors_.size(); +} + +size_t ResourceManager::system_interfaces_size() const +{ + return resource_storage_->systems_.size(); +} +} // namespace controller_manager diff --git a/controller_manager/src/resource_manager.hpp b/controller_manager/src/resource_manager.hpp new file mode 100644 index 0000000000..3646317619 --- /dev/null +++ b/controller_manager/src/resource_manager.hpp @@ -0,0 +1,55 @@ +// Copyright 2020 Open Source Robotics Foundation, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef RESOURCE_MANAGER_HPP_ +#define RESOURCE_MANAGER_HPP_ + +#include +#include + +namespace controller_manager +{ + +class ResourceStorage; + +class ResourceManager +{ +public: + ResourceManager(); + + explicit ResourceManager(const std::string & urdf); + + ResourceManager(const ResourceManager &) = delete; + + ~ResourceManager(); + + size_t joint_components_size() const; + + size_t sensor_components_size() const; + + size_t actuator_interfaces_size() const; + + size_t sensor_interfaces_size() const; + + size_t system_interfaces_size() const; + + // loan_joint(const std::string & name); + // loan_sensor(const std::string & name); + +private: + std::unique_ptr resource_storage_; +}; + +} // namespace controller_manager +#endif // RESOURCE_MANAGER_HPP_ diff --git a/controller_manager/test/controller_manager_test_common.hpp b/controller_manager/test/controller_manager_test_common.hpp index bd7a606a1e..b57c955771 100644 --- a/controller_manager/test/controller_manager_test_common.hpp +++ b/controller_manager/test/controller_manager_test_common.hpp @@ -71,13 +71,15 @@ class ControllerLoaderMock : public controller_manager::ControllerLoaderInterfac ControllerLoaderMock() : controller_manager::ControllerLoaderInterface("controller_interface::MockControllerInterface") {} - MOCK_METHOD1(create, controller_interface::ControllerInterfaceSharedPtr(const std::string &)); - MOCK_CONST_METHOD1(is_available, bool(const std::string &)); + MOCK_METHOD( + controller_interface::ControllerInterfaceSharedPtr, create, (const std::string &), + (override)); + MOCK_METHOD(bool, is_available, (const std::string &), (const, override)); std::vector get_declared_classes() const override { return {MOCK_TEST_CONTROLLER_NAME}; } - MOCK_METHOD0(reload, void()); + MOCK_METHOD(void, reload, (), (override)); }; #endif // CONTROLLER_MANAGER_TEST_COMMON_HPP_ diff --git a/controller_manager/test/test_controller_manager_srvs.cpp b/controller_manager/test/test_controller_manager_srvs.cpp index 9a0f6e8b9c..c60fdc7895 100644 --- a/controller_manager/test/test_controller_manager_srvs.cpp +++ b/controller_manager/test/test_controller_manager_srvs.cpp @@ -32,7 +32,6 @@ using ::testing::Return; using namespace std::chrono_literals; - class TestControllerManagerSrvs : public TestControllerManager { public: @@ -137,7 +136,6 @@ TEST_F(TestControllerManagerSrvs, list_controller_types) ::testing::Contains("controller_interface::MockControllerInterface")); } - TEST_F(TestControllerManagerSrvs, list_controllers_srv) { rclcpp::executors::SingleThreadedExecutor srv_executor; rclcpp::Node::SharedPtr srv_node = std::make_shared("srv_client"); @@ -176,7 +174,6 @@ TEST_F(TestControllerManagerSrvs, list_controllers_srv) { result->controller.size()); ASSERT_EQ("active", result->controller[0].state); - cm_->switch_controller( {}, {test_controller::TEST_CONTROLLER_NAME}, controller_manager_msgs::srv::SwitchController::Request::STRICT, true, @@ -207,7 +204,6 @@ TEST_F(TestControllerManagerSrvs, reload_controller_libraries_srv) { auto request = std::make_shared(); - std::shared_ptr mock_loader(new ControllerLoaderMock); cm_->register_controller_loader(mock_loader); @@ -219,7 +215,6 @@ TEST_F(TestControllerManagerSrvs, reload_controller_libraries_srv) { auto result = call_service_and_wait(*client, request, srv_executor); ASSERT_TRUE(result->ok); - // Add a controller, but stopped auto test_controller = cm_->load_controller( test_controller::TEST_CONTROLLER_NAME, @@ -257,7 +252,6 @@ TEST_F(TestControllerManagerSrvs, reload_controller_libraries_srv) { lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE, test_controller->get_lifecycle_node()->get_current_state().id()); - // Failed reload due to active controller request->force_kill = false; EXPECT_CALL(*mock_loader, reload).Times(0); @@ -278,7 +272,6 @@ TEST_F(TestControllerManagerSrvs, reload_controller_libraries_srv) { result = call_service_and_wait(*client, request, srv_executor, true); ASSERT_TRUE(result->ok); - ASSERT_EQ( test_controller.use_count(), 1) << "No more references to the controller after reloading."; @@ -320,7 +313,6 @@ TEST_F(TestControllerManagerSrvs, unload_controller_srv) { auto result = call_service_and_wait(*client, request, srv_executor); ASSERT_FALSE(result->ok) << "Controller not loaded: " << request->name; - auto test_controller = std::make_shared(); auto abstract_test_controller = cm_->add_controller( test_controller, test_controller::TEST_CONTROLLER_NAME, diff --git a/controller_manager/test/test_hardware_resources.xml b/controller_manager/test/test_hardware_resources.xml new file mode 100644 index 0000000000..3dadf6badd --- /dev/null +++ b/controller_manager/test/test_hardware_resources.xml @@ -0,0 +1,33 @@ + + + + + Test Hardware Actuator + + + + + + Test Hardware Sensor + + + + + + Test Hardware System + + + + + + Test Joint Component + + + + + + Test Sensor Component + + + + diff --git a/controller_manager/test/test_hardware_resources/test_actuator_hardware.cpp b/controller_manager/test/test_hardware_resources/test_actuator_hardware.cpp new file mode 100644 index 0000000000..3857c88538 --- /dev/null +++ b/controller_manager/test/test_hardware_resources/test_actuator_hardware.cpp @@ -0,0 +1,65 @@ +// Copyright 2020 ros2_control Development Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include "./test_actuator_hardware.hpp" + +using hardware_interface::hardware_interface_status; +using hardware_interface::return_type; + +return_type +TestActuatorHardware::configure( + const hardware_interface::hardware_resources::HardwareInfo & /* actuator_info */) +{ + return return_type::OK; +} + +return_type +TestActuatorHardware::start() +{ + return return_type::OK; +} + +return_type +TestActuatorHardware::stop() +{ + return return_type::OK; +} + +hardware_interface_status +TestActuatorHardware::get_status() const +{ + return hardware_interface_status::UNKNOWN; +} + +return_type +TestActuatorHardware::read_joint( + std::shared_ptr/* joint */) const +{ + return return_type::OK; +} + +return_type +TestActuatorHardware::write_joint( + const std::shared_ptr/* joint */) +{ + return return_type::OK; +} + +#include "pluginlib/class_list_macros.hpp" // NOLINT + +PLUGINLIB_EXPORT_CLASS( + TestActuatorHardware, + hardware_interface::hardware_resources::ActuatorHardwareInterface) diff --git a/controller_manager/test/test_hardware_resources/test_actuator_hardware.hpp b/controller_manager/test/test_hardware_resources/test_actuator_hardware.hpp new file mode 100644 index 0000000000..995c847286 --- /dev/null +++ b/controller_manager/test/test_hardware_resources/test_actuator_hardware.hpp @@ -0,0 +1,45 @@ +// Copyright 2020 ros2_control Development Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef TEST_HARDWARE_RESOURCES__TEST_ACTUATOR_HARDWARE_HPP_ +#define TEST_HARDWARE_RESOURCES__TEST_ACTUATOR_HARDWARE_HPP_ + +#include + +#include "hardware_interface/hardware_resources/actuator_hardware_interface.hpp" + +class TestActuatorHardware : public hardware_interface::hardware_resources:: + ActuatorHardwareInterface +{ +public: + hardware_interface::return_type + configure(const hardware_interface::hardware_resources::HardwareInfo & actuator_info) override; + + hardware_interface::return_type + start() override; + + hardware_interface::return_type + stop() override; + + hardware_interface::hardware_interface_status + get_status() const override; + + hardware_interface::return_type + read_joint(std::shared_ptr joint) const override; + + hardware_interface::return_type + write_joint(const std::shared_ptr joint) override; +}; + +#endif // TEST_HARDWARE_RESOURCES__TEST_ACTUATOR_HARDWARE_HPP_ diff --git a/controller_manager/test/test_hardware_resources/test_joint_component.cpp b/controller_manager/test/test_hardware_resources/test_joint_component.cpp new file mode 100644 index 0000000000..3ab5858eb0 --- /dev/null +++ b/controller_manager/test/test_hardware_resources/test_joint_component.cpp @@ -0,0 +1,44 @@ +// Copyright 2020 ros2_control Development Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include + +#include "./test_joint_component.hpp" + +using hardware_interface::return_type; + +return_type +TestJointComponent::configure( + const hardware_interface::components::ComponentInfo & /* joint_info */) +{ + return return_type::OK; +} + +std::vector +TestJointComponent::get_command_interfaces() const +{ + return {"test_command_interface"}; +} + +std::vector +TestJointComponent::get_state_interfaces() const +{ + return {"test_state_interface"}; +} + +#include "pluginlib/class_list_macros.hpp" // NOLINT + +PLUGINLIB_EXPORT_CLASS(TestJointComponent, hardware_interface::components::Joint) diff --git a/controller_manager/test/test_hardware_resources/test_joint_component.hpp b/controller_manager/test/test_hardware_resources/test_joint_component.hpp new file mode 100644 index 0000000000..b754cfa993 --- /dev/null +++ b/controller_manager/test/test_hardware_resources/test_joint_component.hpp @@ -0,0 +1,35 @@ +// Copyright 2020 ros2_control Development Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef TEST_HARDWARE_RESOURCES__TEST_JOINT_COMPONENT_HPP_ +#define TEST_HARDWARE_RESOURCES__TEST_JOINT_COMPONENT_HPP_ + +#include +#include +#include + +#include "hardware_interface/components/joint.hpp" + +class TestJointComponent : public hardware_interface::components::Joint +{ +public: + hardware_interface::return_type + configure(const hardware_interface::components::ComponentInfo & joint_info) override; + + std::vector get_command_interfaces() const override; + + std::vector get_state_interfaces() const override; +}; + +#endif // TEST_HARDWARE_RESOURCES__TEST_JOINT_COMPONENT_HPP_ diff --git a/controller_manager/test/test_hardware_resources/test_sensor_component.cpp b/controller_manager/test/test_hardware_resources/test_sensor_component.cpp new file mode 100644 index 0000000000..7ee7c6f0c6 --- /dev/null +++ b/controller_manager/test/test_hardware_resources/test_sensor_component.cpp @@ -0,0 +1,38 @@ +// Copyright 2020 ros2_control Development Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include + +#include "./test_sensor_component.hpp" + +using hardware_interface::return_type; + +return_type +TestSensorComponent::configure( + const hardware_interface::components::ComponentInfo & /* sensor_info */) +{ + return return_type::OK; +} + +std::vector +TestSensorComponent::get_state_interfaces() const +{ + return {"test_state_interface"}; +} + +#include "pluginlib/class_list_macros.hpp" // NOLINT + +PLUGINLIB_EXPORT_CLASS(TestSensorComponent, hardware_interface::components::Sensor) diff --git a/controller_manager/test/test_hardware_resources/test_sensor_component.hpp b/controller_manager/test/test_hardware_resources/test_sensor_component.hpp new file mode 100644 index 0000000000..ce7e8c1998 --- /dev/null +++ b/controller_manager/test/test_hardware_resources/test_sensor_component.hpp @@ -0,0 +1,33 @@ +// Copyright 2020 ros2_control Development Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef TEST_HARDWARE_RESOURCES__TEST_SENSOR_COMPONENT_HPP_ +#define TEST_HARDWARE_RESOURCES__TEST_SENSOR_COMPONENT_HPP_ + +#include +#include +#include + +#include "hardware_interface/components/sensor.hpp" + +class TestSensorComponent : public hardware_interface::components::Sensor +{ +public: + hardware_interface::return_type + configure(const hardware_interface::components::ComponentInfo & sensor_info) override; + + std::vector get_state_interfaces() const override; +}; + +#endif // TEST_HARDWARE_RESOURCES__TEST_SENSOR_COMPONENT_HPP_ diff --git a/controller_manager/test/test_hardware_resources/test_sensor_hardware.cpp b/controller_manager/test/test_hardware_resources/test_sensor_hardware.cpp new file mode 100644 index 0000000000..8fe3ab68f1 --- /dev/null +++ b/controller_manager/test/test_hardware_resources/test_sensor_hardware.cpp @@ -0,0 +1,59 @@ +// Copyright 2020 ros2_control Development Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include + +#include "./test_sensor_hardware.hpp" + +using hardware_interface::hardware_interface_status; +using hardware_interface::return_type; + +return_type +TestSensorHardware::configure( + const hardware_interface::hardware_resources::HardwareInfo & /* sensor_info */) +{ + return return_type::OK; +} + +return_type +TestSensorHardware::start() +{ + return return_type::OK; +} + +return_type +TestSensorHardware::stop() +{ + return return_type::OK; +} + +hardware_interface_status +TestSensorHardware::get_status() const +{ + return hardware_interface_status::UNKNOWN; +} + +return_type +TestSensorHardware::read_sensors( + const std::vector> & /* sensors */) const +{ + return return_type::OK; +} + +#include "pluginlib/class_list_macros.hpp" // NOLINT + +PLUGINLIB_EXPORT_CLASS( + TestSensorHardware, + hardware_interface::hardware_resources::SensorHardwareInterface) diff --git a/controller_manager/test/test_hardware_resources/test_sensor_hardware.hpp b/controller_manager/test/test_hardware_resources/test_sensor_hardware.hpp new file mode 100644 index 0000000000..c00df394bc --- /dev/null +++ b/controller_manager/test/test_hardware_resources/test_sensor_hardware.hpp @@ -0,0 +1,43 @@ +// Copyright 2020 ros2_control Development Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef TEST_HARDWARE_RESOURCES__TEST_SENSOR_HARDWARE_HPP_ +#define TEST_HARDWARE_RESOURCES__TEST_SENSOR_HARDWARE_HPP_ + +#include +#include + +#include "hardware_interface/hardware_resources/sensor_hardware_interface.hpp" + +class TestSensorHardware : public hardware_interface::hardware_resources::SensorHardwareInterface +{ +public: + hardware_interface::return_type + configure(const hardware_interface::hardware_resources::HardwareInfo & sensor_info) override; + + hardware_interface::return_type + start() override; + + hardware_interface::return_type + stop() override; + + hardware_interface::hardware_interface_status + get_status() const override; + + hardware_interface::return_type + read_sensors(const std::vector> & sensors) + const override; +}; + +#endif // TEST_HARDWARE_RESOURCES__TEST_SENSOR_HARDWARE_HPP_ diff --git a/controller_manager/test/test_hardware_resources/test_system_hardware.cpp b/controller_manager/test/test_hardware_resources/test_system_hardware.cpp new file mode 100644 index 0000000000..e07b9d9409 --- /dev/null +++ b/controller_manager/test/test_hardware_resources/test_system_hardware.cpp @@ -0,0 +1,73 @@ +// Copyright 2020 ros2_control Development Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include + +#include "./test_system_hardware.hpp" + +using hardware_interface::hardware_interface_status; +using hardware_interface::return_type; + +hardware_interface::return_type +TestSystemHardware::configure( + const hardware_interface::hardware_resources::HardwareInfo & /* system_info */) +{ + return return_type::OK; +} + +return_type +TestSystemHardware::start() +{ + return return_type::OK; +} + +return_type +TestSystemHardware::stop() +{ + return return_type::OK; +} + +hardware_interface_status +TestSystemHardware::get_status() const +{ + return hardware_interface_status::UNKNOWN; +} + +return_type +TestSystemHardware::read_sensors( + std::vector> & /* sensors */) const +{ + return return_type::OK; +} + +return_type +TestSystemHardware::read_joints( + std::vector> & /* joints */) const +{ + return return_type::OK; +} + +return_type +TestSystemHardware::write_joints( + const std::vector> & /* joints */) +{ + return return_type::OK; +} + +#include "pluginlib/class_list_macros.hpp" // NOLINT + +PLUGINLIB_EXPORT_CLASS( + TestSystemHardware, + hardware_interface::hardware_resources::SystemHardwareInterface) diff --git a/controller_manager/test/test_hardware_resources/test_system_hardware.hpp b/controller_manager/test/test_hardware_resources/test_system_hardware.hpp new file mode 100644 index 0000000000..f597800035 --- /dev/null +++ b/controller_manager/test/test_hardware_resources/test_system_hardware.hpp @@ -0,0 +1,51 @@ +// Copyright 2020 ros2_control Development Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef TEST_HARDWARE_RESOURCES__TEST_SYSTEM_HARDWARE_HPP_ +#define TEST_HARDWARE_RESOURCES__TEST_SYSTEM_HARDWARE_HPP_ + +#include +#include + +#include "hardware_interface/hardware_resources/system_hardware_interface.hpp" + +class TestSystemHardware : public hardware_interface::hardware_resources::SystemHardwareInterface +{ +public: + hardware_interface::return_type + configure(const hardware_interface::hardware_resources::HardwareInfo & system_info) override; + + hardware_interface::return_type + start() override; + + hardware_interface::return_type + stop() override; + + hardware_interface::hardware_interface_status + get_status() const override; + + hardware_interface::return_type + read_sensors( + std::vector> & sensors) const override; + + hardware_interface::return_type + read_joints( + std::vector> & joints) const override; + + hardware_interface::return_type + write_joints( + const std::vector> & joints) override; +}; + +#endif // TEST_HARDWARE_RESOURCES__TEST_SYSTEM_HARDWARE_HPP_ diff --git a/controller_manager/test/test_resource_manager.cpp b/controller_manager/test/test_resource_manager.cpp new file mode 100644 index 0000000000..93d76ce0ac --- /dev/null +++ b/controller_manager/test/test_resource_manager.cpp @@ -0,0 +1,155 @@ +// Copyright 2017 Open Source Robotics Foundation, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include + +#include "resource_manager.hpp" + +class TestResourceManager : public ::testing::Test +{ +public: + static void SetUpTestCase() + { + } + + void SetUp() + { + urdf_head_ = + R"( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +)"; + + urdf_tail_ = + R"( + +)"; + + test_hardware_resource_system_ = + R"( + + + test_actuator_hardware + 2 + 2 + + + test_joint_component + -1 + 1 + + + + + test_sensor_hardware + 2 + 2 + + + test_sensor_component + -1 + 1 + + + + + test_system_hardware + 2 + 2 + + + test_joint_component + -1 + 1 + + + test_joint_component + -1 + 1 + + +)"; + } + + std::string urdf_head_; + std::string test_hardware_resource_system_; + std::string urdf_tail_; +}; + +TEST_F(TestResourceManager, initialization_empty) { + controller_manager::ResourceManager rm; + EXPECT_EQ(0u, rm.actuator_interfaces_size()); + EXPECT_EQ(0u, rm.sensor_interfaces_size()); + EXPECT_EQ(0u, rm.system_interfaces_size()); +} + +TEST_F(TestResourceManager, initialization_with_urdf) { + auto urdf = urdf_head_ + test_hardware_resource_system_ + urdf_tail_; + controller_manager::ResourceManager rm(urdf); + + EXPECT_EQ(3u, rm.joint_components_size()); + EXPECT_EQ(1u, rm.sensor_components_size()); + + EXPECT_EQ(1u, rm.actuator_interfaces_size()); + EXPECT_EQ(1u, rm.sensor_interfaces_size()); + EXPECT_EQ(1u, rm.system_interfaces_size()); +} diff --git a/hardware_interface/CMakeLists.txt b/hardware_interface/CMakeLists.txt index 4e9f289919..b0add8cc10 100644 --- a/hardware_interface/CMakeLists.txt +++ b/hardware_interface/CMakeLists.txt @@ -20,11 +20,11 @@ find_package(TinyXML2 REQUIRED) add_library( hardware_interface SHARED - src/actuator_hardware.cpp + src/hardware_resources/actuator_hardware.cpp + src/hardware_resources/sensor_hardware.cpp + src/hardware_resources/system_hardware.cpp src/operation_mode_handle.cpp src/robot_hardware.cpp - src/sensor_hardware.cpp - src/system_hardware.cpp ) target_include_directories( hardware_interface @@ -41,32 +41,22 @@ ament_target_dependencies( # which is appropriate when building the dll but not consuming it. target_compile_definitions(hardware_interface PRIVATE "HARDWARE_INTERFACE_BUILDING_DLL") -add_library( - component_parser - src/component_parser.cpp -) -target_include_directories( - component_parser - PUBLIC - include -) -ament_target_dependencies( - component_parser - TinyXML2 -) -target_compile_definitions(component_parser PRIVATE "HARDWARE_INTERFACE_BUILDING_DLL") - add_library( components SHARED src/components/joint.cpp src/components/sensor.cpp + src/component_parser.cpp ) target_include_directories( components PUBLIC include ) +ament_target_dependencies( + components + TinyXML2 +) # Causes the visibility macros to use dllexport rather than dllimport, # which is appropriate when building the dll but not consuming it. target_compile_definitions(components PRIVATE "HARDWARE_INTERFACE_BUILDING_DLL") @@ -78,7 +68,6 @@ install( install( TARGETS - component_parser components hardware_interface RUNTIME DESTINATION bin @@ -124,19 +113,13 @@ if(BUILD_TESTING) target_link_libraries(test_component_interfaces components hardware_interface) ament_add_gmock(test_component_parser test/test_component_parser.cpp) - target_link_libraries(test_component_parser component_parser) - ament_target_dependencies(test_component_parser TinyXML2) + target_link_libraries(test_component_parser components) endif() -ament_export_dependencies( - rclcpp - rcpputils -) ament_export_include_directories( include ) ament_export_libraries( - component_parser components hardware_interface ) diff --git a/hardware_interface/include/hardware_interface/component_parser.hpp b/hardware_interface/include/hardware_interface/component_parser.hpp index e7b3d08175..3b2795601d 100644 --- a/hardware_interface/include/hardware_interface/component_parser.hpp +++ b/hardware_interface/include/hardware_interface/component_parser.hpp @@ -20,7 +20,7 @@ #include #include "hardware_interface/components/component_info.hpp" -#include "hardware_interface/hardware_info.hpp" +#include "hardware_interface/hardware_resources/hardware_info.hpp" #include "hardware_interface/visibility_control.h" namespace hardware_interface @@ -34,7 +34,8 @@ namespace hardware_interface * \throws std::runtime_error if a robot attribute or tag is not found */ HARDWARE_INTERFACE_PUBLIC -std::vector parse_control_resources_from_urdf(const std::string & urdf); +std::vector +parse_control_resources_from_urdf(const std::string & urdf); } // namespace hardware_interface #endif // HARDWARE_INTERFACE__COMPONENT_PARSER_HPP_ diff --git a/hardware_interface/include/hardware_interface/components/joint.hpp b/hardware_interface/include/hardware_interface/components/joint.hpp index 64ede0a2bc..9f2fef052e 100644 --- a/hardware_interface/include/hardware_interface/components/joint.hpp +++ b/hardware_interface/include/hardware_interface/components/joint.hpp @@ -50,6 +50,7 @@ class Joint * return_type::ERROR otherwise. */ HARDWARE_INTERFACE_PUBLIC + virtual return_type configure(const ComponentInfo & joint_info); /** @@ -58,6 +59,7 @@ class Joint * \return string list with command interfaces. */ HARDWARE_INTERFACE_PUBLIC + virtual std::vector get_command_interfaces() const; /** @@ -66,6 +68,7 @@ class Joint * \return string list with state interfaces. */ HARDWARE_INTERFACE_PUBLIC + virtual std::vector get_state_interfaces() const; /** @@ -81,7 +84,8 @@ class Joint * defined for the joint; return return_type::INTERFACE_NOT_PROVIDED if the list of interfaces * is empty; return_type::OK otherwise. */ - HARDWARE_INTERFACE_EXPORT + HARDWARE_INTERFACE_PUBLIC + virtual return_type get_command( std::vector & command, const std::vector & interfaces) const; @@ -94,7 +98,8 @@ class Joint * \param command list of doubles with commands for the hardware. * \return return_type::OK always. */ - HARDWARE_INTERFACE_EXPORT + HARDWARE_INTERFACE_PUBLIC + virtual return_type get_command(std::vector & command) const; /** @@ -113,7 +118,8 @@ class Joint * for different interfaces. This should be changed in the future. * (see: https://github.com/ros-controls/ros2_control/issues/129) */ - HARDWARE_INTERFACE_EXPORT + HARDWARE_INTERFACE_PUBLIC + virtual return_type set_command( const std::vector & command, const std::vector & interfaces); @@ -128,7 +134,8 @@ class Joint * joint's command interfaces; return_type::COMMAND_OUT_OF_LIMITS if one of the command values is out * of limits; return_type::OK otherwise. */ - HARDWARE_INTERFACE_EXPORT + HARDWARE_INTERFACE_PUBLIC + virtual return_type set_command(const std::vector & command); /** @@ -143,7 +150,8 @@ class Joint * defined for the joint; return return_type::INTERFACE_NOT_PROVIDED if the list of interfaces * is empty; return_type::OK otherwise. */ - HARDWARE_INTERFACE_EXPORT + HARDWARE_INTERFACE_PUBLIC + virtual return_type get_state( std::vector & state, const std::vector & interfaces) const; @@ -156,7 +164,8 @@ class Joint * \param state list of doubles with states of the hardware. * \return return_type::OK always. */ - HARDWARE_INTERFACE_EXPORT + HARDWARE_INTERFACE_PUBLIC + virtual return_type get_state(std::vector & state) const; /** @@ -170,7 +179,8 @@ class Joint * have the same length; return_type::INTERFACE_NOT_FOUND if one of provided interfaces is not * defined for the joint; return_type::OK otherwise. */ - HARDWARE_INTERFACE_EXPORT + HARDWARE_INTERFACE_PUBLIC + virtual return_type set_state( const std::vector & state, const std::vector & interfaces); @@ -184,7 +194,8 @@ class Joint * \return return_type::INTERFACE_VALUE_SIZE_NOT_EQUAL is command size is not equal to number of * joint's state interfaces, return_type::OK otherwise. */ - HARDWARE_INTERFACE_EXPORT + HARDWARE_INTERFACE_PUBLIC + virtual return_type set_state(const std::vector & state); protected: diff --git a/hardware_interface/include/hardware_interface/components/sensor.hpp b/hardware_interface/include/hardware_interface/components/sensor.hpp index a99c85eec9..5d52fccf48 100644 --- a/hardware_interface/include/hardware_interface/components/sensor.hpp +++ b/hardware_interface/include/hardware_interface/components/sensor.hpp @@ -50,7 +50,8 @@ class Sensor * return_type::ERROR otherwise. */ HARDWARE_INTERFACE_PUBLIC - return_type configure(const ComponentInfo & joint_info); + virtual + return_type configure(const ComponentInfo & sensor_info); /** * \brief Provide the list of state interfaces configured for the sensor. @@ -58,7 +59,8 @@ class Sensor * \return string list with state interfaces. */ HARDWARE_INTERFACE_PUBLIC - std::vector get_state_interfaces(); + virtual + std::vector get_state_interfaces() const; /** * \brief Get state list from the sensor. This function is used by the controller to get the @@ -72,7 +74,8 @@ class Sensor * defined for the sensor; return return_type::INTERFACE_NOT_PROVIDED if the list of interfaces * is empty; return_type::OK otherwise. */ - HARDWARE_INTERFACE_EXPORT + HARDWARE_INTERFACE_PUBLIC + virtual return_type get_state( std::vector & state, const std::vector & interfaces) const; @@ -85,7 +88,8 @@ class Sensor * \param state list of doubles with states of the hardware. * \return return_type::OK always. */ - HARDWARE_INTERFACE_EXPORT + HARDWARE_INTERFACE_PUBLIC + virtual return_type get_state(std::vector & state) const; /** @@ -99,7 +103,8 @@ class Sensor * have the same length; return_type::INTERFACE_NOT_FOUND if one of provided interfaces is not * defined for the sensor; return_type::OK otherwise. */ - HARDWARE_INTERFACE_EXPORT + HARDWARE_INTERFACE_PUBLIC + virtual return_type set_state( const std::vector & state, const std::vector & interfaces); @@ -113,7 +118,8 @@ class Sensor * \return return_type::INTERFACE_VALUE_SIZE_NOT_EQUAL is state size is not equal to number of * sensor's state interfaces, return_type::OK otherwise. */ - HARDWARE_INTERFACE_EXPORT + HARDWARE_INTERFACE_PUBLIC + virtual return_type set_state(const std::vector & state); protected: diff --git a/hardware_interface/include/hardware_interface/actuator_hardware.hpp b/hardware_interface/include/hardware_interface/hardware_resources/actuator_hardware.hpp similarity index 75% rename from hardware_interface/include/hardware_interface/actuator_hardware.hpp rename to hardware_interface/include/hardware_interface/hardware_resources/actuator_hardware.hpp index 1bcfbafe60..d0bf69a90d 100644 --- a/hardware_interface/include/hardware_interface/actuator_hardware.hpp +++ b/hardware_interface/include/hardware_interface/hardware_resources/actuator_hardware.hpp @@ -12,12 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef HARDWARE_INTERFACE__ACTUATOR_HARDWARE_HPP_ -#define HARDWARE_INTERFACE__ACTUATOR_HARDWARE_HPP_ +#ifndef HARDWARE_INTERFACE__HARDWARE_RESOURCES__ACTUATOR_HARDWARE_HPP_ +#define HARDWARE_INTERFACE__HARDWARE_RESOURCES__ACTUATOR_HARDWARE_HPP_ #include -#include "hardware_interface/hardware_info.hpp" +#include "hardware_interface/hardware_resources/actuator_hardware_interface.hpp" +#include "hardware_interface/hardware_resources/hardware_info.hpp" #include "hardware_interface/types/hardware_interface_return_values.hpp" #include "hardware_interface/types/hardware_interface_status_values.hpp" #include "hardware_interface/visibility_control.h" @@ -29,13 +30,17 @@ namespace components { class Joint; } // namespace components -class ActuatorHardwareInterface; + +namespace hardware_resources +{ class ActuatorHardware final { public: ActuatorHardware() = default; + explicit ActuatorHardware(ActuatorHardware && other) = default; + explicit ActuatorHardware(std::unique_ptr impl); ~ActuatorHardware() = default; @@ -56,5 +61,6 @@ class ActuatorHardware final std::unique_ptr impl_; }; +} // namespace hardware_resources } // namespace hardware_interface -#endif // HARDWARE_INTERFACE__ACTUATOR_HARDWARE_HPP_ +#endif // HARDWARE_INTERFACE__HARDWARE_RESOURCES__ACTUATOR_HARDWARE_HPP_ diff --git a/hardware_interface/include/hardware_interface/actuator_hardware_interface.hpp b/hardware_interface/include/hardware_interface/hardware_resources/actuator_hardware_interface.hpp similarity index 89% rename from hardware_interface/include/hardware_interface/actuator_hardware_interface.hpp rename to hardware_interface/include/hardware_interface/hardware_resources/actuator_hardware_interface.hpp index cf7ae22ee5..d681882776 100644 --- a/hardware_interface/include/hardware_interface/actuator_hardware_interface.hpp +++ b/hardware_interface/include/hardware_interface/hardware_resources/actuator_hardware_interface.hpp @@ -12,19 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef HARDWARE_INTERFACE__ACTUATOR_HARDWARE_INTERFACE_HPP_ -#define HARDWARE_INTERFACE__ACTUATOR_HARDWARE_INTERFACE_HPP_ +#ifndef HARDWARE_INTERFACE__HARDWARE_RESOURCES__ACTUATOR_HARDWARE_INTERFACE_HPP_ +#define HARDWARE_INTERFACE__HARDWARE_RESOURCES__ACTUATOR_HARDWARE_INTERFACE_HPP_ #include #include "hardware_interface/components/joint.hpp" -#include "hardware_interface/hardware_info.hpp" +#include "hardware_interface/hardware_resources/hardware_info.hpp" #include "hardware_interface/types/hardware_interface_return_values.hpp" #include "hardware_interface/types/hardware_interface_status_values.hpp" #include "hardware_interface/visibility_control.h" namespace hardware_interface { +namespace hardware_resources +{ /** * \brief Virtual Class to implement when integrating a 1 DoF actuator into ros2_control. @@ -101,5 +103,6 @@ class ActuatorHardwareInterface return_type write_joint(const std::shared_ptr joint) = 0; }; +} // namespace hardware_resources } // namespace hardware_interface -#endif // HARDWARE_INTERFACE__ACTUATOR_HARDWARE_INTERFACE_HPP_ +#endif // HARDWARE_INTERFACE__HARDWARE_RESOURCES__ACTUATOR_HARDWARE_INTERFACE_HPP_ diff --git a/hardware_interface/include/hardware_interface/hardware_info.hpp b/hardware_interface/include/hardware_interface/hardware_resources/hardware_info.hpp similarity index 87% rename from hardware_interface/include/hardware_interface/hardware_info.hpp rename to hardware_interface/include/hardware_interface/hardware_resources/hardware_info.hpp index ebdfab37a8..b04784f7ca 100644 --- a/hardware_interface/include/hardware_interface/hardware_info.hpp +++ b/hardware_interface/include/hardware_interface/hardware_resources/hardware_info.hpp @@ -13,8 +13,8 @@ // limitations under the License. -#ifndef HARDWARE_INTERFACE__HARDWARE_INFO_HPP_ -#define HARDWARE_INTERFACE__HARDWARE_INFO_HPP_ +#ifndef HARDWARE_INTERFACE__HARDWARE_RESOURCES__HARDWARE_INFO_HPP_ +#define HARDWARE_INTERFACE__HARDWARE_RESOURCES__HARDWARE_INFO_HPP_ #include #include @@ -24,6 +24,8 @@ namespace hardware_interface { +namespace hardware_resources +{ /** * \brief This structure stores information about hardware defined in a robot's URDF. @@ -63,5 +65,6 @@ struct HardwareInfo std::vector transmissions; }; +} // namespace hardware_resources } // namespace hardware_interface -#endif // HARDWARE_INTERFACE__HARDWARE_INFO_HPP_ +#endif // HARDWARE_INTERFACE__HARDWARE_RESOURCES__HARDWARE_INFO_HPP_ diff --git a/hardware_interface/include/hardware_interface/sensor_hardware.hpp b/hardware_interface/include/hardware_interface/hardware_resources/sensor_hardware.hpp similarity index 77% rename from hardware_interface/include/hardware_interface/sensor_hardware.hpp rename to hardware_interface/include/hardware_interface/hardware_resources/sensor_hardware.hpp index 95bb04f4cf..cacb920385 100644 --- a/hardware_interface/include/hardware_interface/sensor_hardware.hpp +++ b/hardware_interface/include/hardware_interface/hardware_resources/sensor_hardware.hpp @@ -12,15 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef HARDWARE_INTERFACE__SENSOR_HARDWARE_HPP_ -#define HARDWARE_INTERFACE__SENSOR_HARDWARE_HPP_ +#ifndef HARDWARE_INTERFACE__HARDWARE_RESOURCES__SENSOR_HARDWARE_HPP_ +#define HARDWARE_INTERFACE__HARDWARE_RESOURCES__SENSOR_HARDWARE_HPP_ #include #include #include #include -#include "hardware_interface/hardware_info.hpp" +#include "hardware_interface/hardware_resources/hardware_info.hpp" +#include "hardware_interface/hardware_resources/sensor_hardware_interface.hpp" #include "hardware_interface/types/hardware_interface_return_values.hpp" #include "hardware_interface/types/hardware_interface_status_values.hpp" #include "hardware_interface/visibility_control.h" @@ -32,13 +33,17 @@ namespace components { class Sensor; } // namespace components -class SensorHardwareInterface; + +namespace hardware_resources +{ class SensorHardware final { public: SensorHardware() = default; + explicit SensorHardware(SensorHardware && other) = default; + explicit SensorHardware(std::unique_ptr impl); ~SensorHardware() = default; @@ -62,5 +67,6 @@ class SensorHardware final std::unique_ptr impl_; }; +} // namespace hardware_resources } // namespace hardware_interface -#endif // HARDWARE_INTERFACE__SENSOR_HARDWARE_HPP_ +#endif // HARDWARE_INTERFACE__HARDWARE_RESOURCES__SENSOR_HARDWARE_HPP_ diff --git a/hardware_interface/include/hardware_interface/sensor_hardware_interface.hpp b/hardware_interface/include/hardware_interface/hardware_resources/sensor_hardware_interface.hpp similarity index 88% rename from hardware_interface/include/hardware_interface/sensor_hardware_interface.hpp rename to hardware_interface/include/hardware_interface/hardware_resources/sensor_hardware_interface.hpp index dd0e408773..e517f941d9 100644 --- a/hardware_interface/include/hardware_interface/sensor_hardware_interface.hpp +++ b/hardware_interface/include/hardware_interface/hardware_resources/sensor_hardware_interface.hpp @@ -12,20 +12,22 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef HARDWARE_INTERFACE__SENSOR_HARDWARE_INTERFACE_HPP_ -#define HARDWARE_INTERFACE__SENSOR_HARDWARE_INTERFACE_HPP_ +#ifndef HARDWARE_INTERFACE__HARDWARE_RESOURCES__SENSOR_HARDWARE_INTERFACE_HPP_ +#define HARDWARE_INTERFACE__HARDWARE_RESOURCES__SENSOR_HARDWARE_INTERFACE_HPP_ #include #include #include "hardware_interface/components/sensor.hpp" -#include "hardware_interface/hardware_info.hpp" +#include "hardware_interface/hardware_resources/hardware_info.hpp" #include "hardware_interface/types/hardware_interface_return_values.hpp" #include "hardware_interface/types/hardware_interface_status_values.hpp" #include "hardware_interface/visibility_control.h" namespace hardware_interface { +namespace hardware_resources +{ /** * \brief Virtual Class to implement when integrating a stand-alone sensor into ros2_control. @@ -92,5 +94,6 @@ class SensorHardwareInterface 0; }; +} // namespace hardware_resources } // namespace hardware_interface -#endif // HARDWARE_INTERFACE__SENSOR_HARDWARE_INTERFACE_HPP_ +#endif // HARDWARE_INTERFACE__HARDWARE_RESOURCES__SENSOR_HARDWARE_INTERFACE_HPP_ diff --git a/hardware_interface/include/hardware_interface/system_hardware.hpp b/hardware_interface/include/hardware_interface/hardware_resources/system_hardware.hpp similarity index 78% rename from hardware_interface/include/hardware_interface/system_hardware.hpp rename to hardware_interface/include/hardware_interface/hardware_resources/system_hardware.hpp index 5a64148c29..8d2fa8f1c0 100644 --- a/hardware_interface/include/hardware_interface/system_hardware.hpp +++ b/hardware_interface/include/hardware_interface/hardware_resources/system_hardware.hpp @@ -12,15 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef HARDWARE_INTERFACE__SYSTEM_HARDWARE_HPP_ -#define HARDWARE_INTERFACE__SYSTEM_HARDWARE_HPP_ +#ifndef HARDWARE_INTERFACE__HARDWARE_RESOURCES__SYSTEM_HARDWARE_HPP_ +#define HARDWARE_INTERFACE__HARDWARE_RESOURCES__SYSTEM_HARDWARE_HPP_ #include #include #include #include -#include "hardware_interface/hardware_info.hpp" +#include "hardware_interface/hardware_resources/hardware_info.hpp" +#include "hardware_interface/hardware_resources/system_hardware_interface.hpp" #include "hardware_interface/types/hardware_interface_return_values.hpp" #include "hardware_interface/types/hardware_interface_status_values.hpp" #include "hardware_interface/visibility_control.h" @@ -33,7 +34,9 @@ namespace components class Joint; class Sensor; } // namespace components -class SystemHardwareInterface; + +namespace hardware_resources +{ class SystemHardware final { @@ -41,6 +44,9 @@ class SystemHardware final HARDWARE_INTERFACE_PUBLIC explicit SystemHardware(std::unique_ptr impl); + HARDWARE_INTERFACE_PUBLIC + explicit SystemHardware(SystemHardware && other) = default; + virtual ~SystemHardware() = default; HARDWARE_INTERFACE_PUBLIC @@ -68,5 +74,6 @@ class SystemHardware final std::unique_ptr impl_; }; +} // namespace hardware_resources } // namespace hardware_interface -#endif // HARDWARE_INTERFACE__SYSTEM_HARDWARE_HPP_ +#endif // HARDWARE_INTERFACE__HARDWARE_RESOURCES__SYSTEM_HARDWARE_HPP_ diff --git a/hardware_interface/include/hardware_interface/system_hardware_interface.hpp b/hardware_interface/include/hardware_interface/hardware_resources/system_hardware_interface.hpp similarity index 91% rename from hardware_interface/include/hardware_interface/system_hardware_interface.hpp rename to hardware_interface/include/hardware_interface/hardware_resources/system_hardware_interface.hpp index 722c75c435..530b1cbc6a 100644 --- a/hardware_interface/include/hardware_interface/system_hardware_interface.hpp +++ b/hardware_interface/include/hardware_interface/hardware_resources/system_hardware_interface.hpp @@ -12,21 +12,23 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef HARDWARE_INTERFACE__SYSTEM_HARDWARE_INTERFACE_HPP_ -#define HARDWARE_INTERFACE__SYSTEM_HARDWARE_INTERFACE_HPP_ +#ifndef HARDWARE_INTERFACE__HARDWARE_RESOURCES__SYSTEM_HARDWARE_INTERFACE_HPP_ +#define HARDWARE_INTERFACE__HARDWARE_RESOURCES__SYSTEM_HARDWARE_INTERFACE_HPP_ #include #include #include "hardware_interface/components/joint.hpp" #include "hardware_interface/components/sensor.hpp" -#include "hardware_interface/hardware_info.hpp" +#include "hardware_interface/hardware_resources/hardware_info.hpp" #include "hardware_interface/types/hardware_interface_return_values.hpp" #include "hardware_interface/types/hardware_interface_status_values.hpp" #include "hardware_interface/visibility_control.h" namespace hardware_interface { +namespace hardware_resources +{ /** * \brief Virtual Class to implement when integrating a complex system into ros2_control. @@ -112,10 +114,11 @@ class SystemHardwareInterface * \return return_type:OK if everything worked as expected, return_type::ERROR otherwise. */ HARDWARE_INTERFACE_PUBLIC - return_type virtual + return_type write_joints(const std::vector> & joints) = 0; }; +} // namespace hardware_resources } // namespace hardware_interface -#endif // HARDWARE_INTERFACE__SYSTEM_HARDWARE_INTERFACE_HPP_ +#endif // HARDWARE_INTERFACE__HARDWARE_RESOURCES__SYSTEM_HARDWARE_INTERFACE_HPP_ diff --git a/hardware_interface/src/component_parser.cpp b/hardware_interface/src/component_parser.cpp index 3841be6c76..1aa8b7fb10 100644 --- a/hardware_interface/src/component_parser.cpp +++ b/hardware_interface/src/component_parser.cpp @@ -19,7 +19,7 @@ #include #include "hardware_interface/components/component_info.hpp" -#include "hardware_interface/hardware_info.hpp" +#include "hardware_interface/hardware_resources/hardware_info.hpp" #include "hardware_interface/component_parser.hpp" namespace @@ -41,6 +41,8 @@ namespace hardware_interface namespace detail { +using hardware_resources::HardwareInfo; +using components::ComponentInfo; /** * \brief Gets value of the text between tags. * @@ -158,9 +160,9 @@ std::vector parse_interfaces_from_xml( * \return robot_control_components::ComponentInfo filled with information about component * \throws std::runtime_error if a component attribute or tag is not found */ -components::ComponentInfo parse_component_from_xml(const tinyxml2::XMLElement * component_it) +ComponentInfo parse_component_from_xml(const tinyxml2::XMLElement * component_it) { - components::ComponentInfo component; + ComponentInfo component; // Find name, type and class of a component component.type = component_it->Name(); @@ -237,7 +239,8 @@ HardwareInfo parse_resource_from_xml(const tinyxml2::XMLElement * ros2_control_i } // namespace detail -std::vector parse_control_resources_from_urdf(const std::string & urdf) +std::vector +parse_control_resources_from_urdf(const std::string & urdf) { // Check if everything OK with URDF string if (urdf.empty()) { @@ -263,7 +266,7 @@ std::vector parse_control_resources_from_urdf(const std::string & throw std::runtime_error("no " + std::string(kROS2ControlTag) + " tag"); } - std::vector hardware_info; + std::vector hardware_info; while (ros2_control_it) { hardware_info.push_back(detail::parse_resource_from_xml(ros2_control_it)); ros2_control_it = ros2_control_it->NextSiblingElement(kROS2ControlTag); diff --git a/hardware_interface/src/components/sensor.cpp b/hardware_interface/src/components/sensor.cpp index 0229e8b14f..5c51ed8848 100644 --- a/hardware_interface/src/components/sensor.cpp +++ b/hardware_interface/src/components/sensor.cpp @@ -36,7 +36,7 @@ return_type Sensor::configure(const ComponentInfo & joint_info) return return_type::OK; } -std::vector Sensor::get_state_interfaces() +std::vector Sensor::get_state_interfaces() const { return info_.state_interfaces; } diff --git a/hardware_interface/src/actuator_hardware.cpp b/hardware_interface/src/hardware_resources/actuator_hardware.cpp similarity index 89% rename from hardware_interface/src/actuator_hardware.cpp rename to hardware_interface/src/hardware_resources/actuator_hardware.cpp index d6336f98c6..e2d5e9c360 100644 --- a/hardware_interface/src/actuator_hardware.cpp +++ b/hardware_interface/src/hardware_resources/actuator_hardware.cpp @@ -17,18 +17,19 @@ #include #include -#include "hardware_interface/actuator_hardware.hpp" +#include "hardware_interface/hardware_resources/actuator_hardware.hpp" -#include "hardware_interface/actuator_hardware_interface.hpp" #include "hardware_interface/components/component_info.hpp" #include "hardware_interface/components/joint.hpp" -#include "hardware_interface/hardware_info.hpp" +#include "hardware_interface/hardware_resources/hardware_info.hpp" #include "hardware_interface/types/hardware_interface_return_values.hpp" #include "hardware_interface/types/hardware_interface_status_values.hpp" #include "hardware_interface/visibility_control.h" namespace hardware_interface { +namespace hardware_resources +{ ActuatorHardware::ActuatorHardware(std::unique_ptr impl) : impl_(std::move(impl)) @@ -64,4 +65,5 @@ return_type ActuatorHardware::write_joint(const std::shared_ptrwrite_joint(joint); } +} // namespace hardware_resources } // namespace hardware_interface diff --git a/hardware_interface/src/sensor_hardware.cpp b/hardware_interface/src/hardware_resources/sensor_hardware.cpp similarity index 89% rename from hardware_interface/src/sensor_hardware.cpp rename to hardware_interface/src/hardware_resources/sensor_hardware.cpp index 44057317f4..eeb42e2dbe 100644 --- a/hardware_interface/src/sensor_hardware.cpp +++ b/hardware_interface/src/hardware_resources/sensor_hardware.cpp @@ -17,18 +17,19 @@ #include #include -#include "hardware_interface/sensor_hardware.hpp" +#include "hardware_interface/hardware_resources/sensor_hardware.hpp" #include "hardware_interface/components/component_info.hpp" #include "hardware_interface/components/sensor.hpp" -#include "hardware_interface/hardware_info.hpp" -#include "hardware_interface/sensor_hardware_interface.hpp" +#include "hardware_interface/hardware_resources/hardware_info.hpp" #include "hardware_interface/types/hardware_interface_return_values.hpp" #include "hardware_interface/types/hardware_interface_status_values.hpp" #include "hardware_interface/visibility_control.h" namespace hardware_interface { +namespace hardware_resources +{ SensorHardware::SensorHardware(std::unique_ptr impl) : impl_(std::move(impl)) @@ -60,4 +61,5 @@ return_type SensorHardware::read_sensors( return impl_->read_sensors(sensors); } +} // namespace hardware_resources } // namespace hardware_interface diff --git a/hardware_interface/src/system_hardware.cpp b/hardware_interface/src/hardware_resources/system_hardware.cpp similarity index 90% rename from hardware_interface/src/system_hardware.cpp rename to hardware_interface/src/hardware_resources/system_hardware.cpp index 9641aae82b..abac5e5dca 100644 --- a/hardware_interface/src/system_hardware.cpp +++ b/hardware_interface/src/hardware_resources/system_hardware.cpp @@ -17,19 +17,20 @@ #include #include -#include "hardware_interface/system_hardware.hpp" +#include "hardware_interface/hardware_resources/system_hardware.hpp" #include "hardware_interface/components/component_info.hpp" #include "hardware_interface/components/joint.hpp" #include "hardware_interface/components/sensor.hpp" -#include "hardware_interface/hardware_info.hpp" -#include "hardware_interface/system_hardware_interface.hpp" +#include "hardware_interface/hardware_resources/hardware_info.hpp" #include "hardware_interface/types/hardware_interface_return_values.hpp" #include "hardware_interface/types/hardware_interface_status_values.hpp" #include "hardware_interface/visibility_control.h" namespace hardware_interface { +namespace hardware_resources +{ SystemHardware::SystemHardware(std::unique_ptr impl) : impl_(std::move(impl)) @@ -71,4 +72,5 @@ return_type SystemHardware::write_joints( return impl_->write_joints(joints); } +} // namespace hardware_resources } // namespace hardware_interface diff --git a/hardware_interface/test/test_component_interfaces.cpp b/hardware_interface/test/test_component_interfaces.cpp index 004b9de8a1..7e99cc044e 100644 --- a/hardware_interface/test/test_component_interfaces.cpp +++ b/hardware_interface/test/test_component_interfaces.cpp @@ -18,16 +18,16 @@ #include #include -#include "hardware_interface/actuator_hardware.hpp" -#include "hardware_interface/actuator_hardware_interface.hpp" #include "hardware_interface/components/component_info.hpp" #include "hardware_interface/components/joint.hpp" #include "hardware_interface/components/sensor.hpp" -#include "hardware_interface/hardware_info.hpp" -#include "hardware_interface/sensor_hardware_interface.hpp" -#include "hardware_interface/sensor_hardware.hpp" -#include "hardware_interface/system_hardware_interface.hpp" -#include "hardware_interface/system_hardware.hpp" +#include "hardware_interface/hardware_resources/actuator_hardware.hpp" +#include "hardware_interface/hardware_resources/actuator_hardware_interface.hpp" +#include "hardware_interface/hardware_resources/hardware_info.hpp" +#include "hardware_interface/hardware_resources/sensor_hardware_interface.hpp" +#include "hardware_interface/hardware_resources/sensor_hardware.hpp" +#include "hardware_interface/hardware_resources/system_hardware_interface.hpp" +#include "hardware_interface/hardware_resources/system_hardware.hpp" #include "hardware_interface/types/hardware_interface_return_values.hpp" #include "hardware_interface/types/hardware_interface_status_values.hpp" #include "hardware_interface/types/hardware_interface_type_values.hpp" @@ -120,9 +120,9 @@ class DummyForceTorqueSensor : public components::Sensor } }; -class DummyActuatorHardware : public ActuatorHardwareInterface +class DummyActuatorHardware : public hardware_resources::ActuatorHardwareInterface { - return_type configure(const HardwareInfo & actuator_info) override + return_type configure(const hardware_resources::HardwareInfo & actuator_info) override { info_ = actuator_info; hw_read_time_ = stod(info_.hardware_parameters["example_param_read_for_sec"]); @@ -171,15 +171,15 @@ class DummyActuatorHardware : public ActuatorHardwareInterface } private: - HardwareInfo info_; + hardware_resources::HardwareInfo info_; hardware_interface_status status_ = hardware_interface_status::UNKNOWN; std::vector hw_values_ = {1.2}; double hw_read_time_, hw_write_time_; }; -class DummySensorHardware : public SensorHardwareInterface +class DummySensorHardware : public hardware_resources::SensorHardwareInterface { - return_type configure(const HardwareInfo & sensor_info) override + return_type configure(const hardware_resources::HardwareInfo & sensor_info) override { info_ = sensor_info; binary_to_voltage_factor_ = stod(info_.hardware_parameters["binary_to_voltage_factor"]); @@ -228,15 +228,15 @@ class DummySensorHardware : public SensorHardwareInterface } private: - HardwareInfo info_; + hardware_resources::HardwareInfo info_; hardware_interface_status status_ = hardware_interface_status::UNKNOWN; double binary_to_voltage_factor_; std::vector ft_hw_values_ = {1, -1.0, 3.4, 7.9, 5.5, 4.4}; }; -class DummySystemHardware : public SystemHardwareInterface +class DummySystemHardware : public hardware_resources::SystemHardwareInterface { - return_type configure(const HardwareInfo & system_info) override + return_type configure(const hardware_resources::HardwareInfo & system_info) override { info_ = system_info; api_version_ = stod(info_.hardware_parameters["example_api_version"]); @@ -318,7 +318,7 @@ class DummySystemHardware : public SystemHardwareInterface } private: - HardwareInfo info_; + hardware_resources::HardwareInfo info_; hardware_interface_status status_; double hw_write_time_, hw_read_time_, api_version_; std::vector ft_hw_values_ = {-3.5, -2.1, -8.7, -5.4, -9.0, -11.2}; @@ -331,18 +331,18 @@ class DummySystemHardware : public SystemHardwareInterface using hardware_interface::components::ComponentInfo; using hardware_interface::components::Joint; using hardware_interface::components::Sensor; -using hardware_interface::ActuatorHardware; -using hardware_interface::ActuatorHardwareInterface; -using hardware_interface::HardwareInfo; -using hardware_interface::hardware_interface_status; -using hardware_interface::return_type; -using hardware_interface::SensorHardware; -using hardware_interface::SensorHardwareInterface; -using hardware_interface::SystemHardware; -using hardware_interface::SystemHardwareInterface; using hardware_interface::hardware_interfaces_components_test::DummyForceTorqueSensor; using hardware_interface::hardware_interfaces_components_test::DummyMultiJoint; using hardware_interface::hardware_interfaces_components_test::DummyPositionJoint; +using hardware_interface::hardware_interface_status; +using hardware_interface::hardware_resources::ActuatorHardware; +using hardware_interface::hardware_resources::ActuatorHardwareInterface; +using hardware_interface::hardware_resources::HardwareInfo; +using hardware_interface::hardware_resources::SensorHardware; +using hardware_interface::hardware_resources::SensorHardwareInterface; +using hardware_interface::hardware_resources::SystemHardware; +using hardware_interface::hardware_resources::SystemHardwareInterface; +using hardware_interface::return_type; using hardware_interface::hardware_interfaces_components_test::DummyActuatorHardware; using hardware_interface::hardware_interfaces_components_test::DummySensorHardware;