From 203ffce8dfcd92bcf8800a679ac5eef6081363f7 Mon Sep 17 00:00:00 2001 From: Karsten Knese Date: Tue, 16 Jun 2020 22:35:11 -0700 Subject: [PATCH] move interfaces into hardware_interface package Signed-off-by: Karsten Knese --- hardware_interface/CMakeLists.txt | 38 ++++-- .../include/hardware_interface/actuator.hpp | 87 +++++++++++++ .../hardware_interface}/component_info.hpp | 12 +- .../actuator_interface.hpp | 70 ++++++++++ .../component_interfaces/sensor_interface.hpp | 63 +++++++++ .../component_interfaces/system_interface.hpp | 68 ++++++++++ .../hardware_interface/robot_hardware.hpp | 7 + .../robot_hardware_interface.hpp | 5 - .../include/hardware_interface/sensor.hpp | 75 +++++++++++ .../include/hardware_interface/system.hpp | 86 +++++++++++++ .../utils}/component_parser.hpp | 30 +++-- .../utils}/ros2_control_utils.hpp | 16 ++- hardware_interface/package.xml | 5 +- .../src/utils/component_parser.cpp | 52 ++++---- .../test/test_component_parser.cpp | 28 ++-- robot_control_components/CMakeLists.txt | 95 ++------------ .../robot_control_components/actuator.hpp | 88 ------------- .../impl/effort_actuator.hpp | 49 ------- .../impl/position_actuator.hpp | 49 ------- .../impl/position_sensor.hpp | 49 ------- .../impl/velocity_actuator.hpp | 49 ------- .../impl/velocity_sensor.hpp | 49 ------- .../robot_control_components/robot.hpp | 60 --------- .../ros2_control_types.h | 40 ------ .../robot_control_components/sensor.hpp | 72 ----------- .../visibility_control.h | 64 --------- robot_control_components/package.xml | 8 +- .../robot_control_components_plugins.xml | 13 +- robot_control_components/src/actuator.cpp | 121 ------------------ .../src/effort_actuator.cpp | 76 +++++++++++ .../src/impl/effort_actuator.cpp | 20 --- .../src/impl/position_actuator.cpp | 20 --- .../src/impl/position_sensor.cpp | 20 --- .../src/impl/velocity_actuator.cpp | 20 --- .../src/impl/velocity_sensor.cpp | 20 --- .../src/position_actuator.cpp | 76 +++++++++++ .../src/position_sensor.cpp | 70 ++++++++++ robot_control_components/src/robot.cpp | 40 ------ robot_control_components/src/sensor.cpp | 62 --------- .../src/velocity_actuator.cpp | 76 +++++++++++ .../src/velocity_sensor.cpp | 70 ++++++++++ 41 files changed, 949 insertions(+), 1069 deletions(-) create mode 100644 hardware_interface/include/hardware_interface/actuator.hpp rename {robot_control_components/include/robot_control_components => hardware_interface/include/hardware_interface}/component_info.hpp (77%) create mode 100644 hardware_interface/include/hardware_interface/component_interfaces/actuator_interface.hpp create mode 100644 hardware_interface/include/hardware_interface/component_interfaces/sensor_interface.hpp create mode 100644 hardware_interface/include/hardware_interface/component_interfaces/system_interface.hpp create mode 100644 hardware_interface/include/hardware_interface/sensor.hpp create mode 100644 hardware_interface/include/hardware_interface/system.hpp rename {robot_control_components/include/robot_control_components => hardware_interface/include/hardware_interface/utils}/component_parser.hpp (75%) rename {robot_control_components/include/robot_control_components => hardware_interface/include/hardware_interface/utils}/ros2_control_utils.hpp (86%) rename {robot_control_components => hardware_interface}/src/utils/component_parser.cpp (81%) rename {robot_control_components => hardware_interface}/test/test_component_parser.cpp (95%) delete mode 100644 robot_control_components/include/robot_control_components/actuator.hpp delete mode 100644 robot_control_components/include/robot_control_components/impl/effort_actuator.hpp delete mode 100644 robot_control_components/include/robot_control_components/impl/position_actuator.hpp delete mode 100644 robot_control_components/include/robot_control_components/impl/position_sensor.hpp delete mode 100644 robot_control_components/include/robot_control_components/impl/velocity_actuator.hpp delete mode 100644 robot_control_components/include/robot_control_components/impl/velocity_sensor.hpp delete mode 100644 robot_control_components/include/robot_control_components/robot.hpp delete mode 100644 robot_control_components/include/robot_control_components/ros2_control_types.h delete mode 100644 robot_control_components/include/robot_control_components/sensor.hpp delete mode 100644 robot_control_components/include/robot_control_components/visibility_control.h delete mode 100644 robot_control_components/src/actuator.cpp create mode 100644 robot_control_components/src/effort_actuator.cpp delete mode 100644 robot_control_components/src/impl/effort_actuator.cpp delete mode 100644 robot_control_components/src/impl/position_actuator.cpp delete mode 100644 robot_control_components/src/impl/position_sensor.cpp delete mode 100644 robot_control_components/src/impl/velocity_actuator.cpp delete mode 100644 robot_control_components/src/impl/velocity_sensor.cpp create mode 100644 robot_control_components/src/position_actuator.cpp create mode 100644 robot_control_components/src/position_sensor.cpp delete mode 100644 robot_control_components/src/robot.cpp delete mode 100644 robot_control_components/src/sensor.cpp create mode 100644 robot_control_components/src/velocity_actuator.cpp create mode 100644 robot_control_components/src/velocity_sensor.cpp diff --git a/hardware_interface/CMakeLists.txt b/hardware_interface/CMakeLists.txt index ab4089e2cc..5409df68d0 100644 --- a/hardware_interface/CMakeLists.txt +++ b/hardware_interface/CMakeLists.txt @@ -13,7 +13,8 @@ endif() find_package(ament_cmake REQUIRED) find_package(rclcpp REQUIRED) find_package(rcpputils REQUIRED) -find_package(robot_control_components REQUIRED) +find_package(tinyxml2_vendor REQUIRED) +find_package(TinyXML2 REQUIRED) add_library( hardware_interface @@ -26,26 +27,38 @@ add_library( target_include_directories( hardware_interface PUBLIC - include) + include +) ament_target_dependencies( hardware_interface rclcpp rcpputils - robot_control_components ) - # Causes the visibility macros to use dllexport rather than dllimport, # 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/utils/component_parser.cpp +) +target_include_directories( + component_parser + PUBLIC + include +) +ament_target_dependencies( + component_parser + TinyXML2 +) + install( DIRECTORY include/ DESTINATION include ) install( - TARGETS - hardware_interface + TARGETS hardware_interface component_parser RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib) @@ -54,17 +67,24 @@ if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) ament_lint_auto_find_test_dependencies() - ament_add_gtest(test_macros test/test_macros.cpp) + ament_add_gmock(test_macros test/test_macros.cpp) target_include_directories(test_macros PRIVATE include) ament_target_dependencies(test_macros rcpputils) + + 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) endif() ament_export_dependencies( - robot_control_components + rclcpp + rcpputils ) ament_export_include_directories( include ) ament_export_libraries( - hardware_interface) + hardware_interface + component_parser +) ament_package() diff --git a/hardware_interface/include/hardware_interface/actuator.hpp b/hardware_interface/include/hardware_interface/actuator.hpp new file mode 100644 index 0000000000..18f0f4c162 --- /dev/null +++ b/hardware_interface/include/hardware_interface/actuator.hpp @@ -0,0 +1,87 @@ +// 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 HARDWARE_INTERFACE__ACTUATOR_HPP_ +#define HARDWARE_INTERFACE__ACTUATOR_HPP_ + +#include +#include +#include +#include + +#include "hardware_interface/component_info.hpp" +#include "hardware_interface/component_interfaces/actuator_interface.hpp" +#include "hardware_interface/types/hardware_interface_return_values.hpp" +#include "hardware_interface/visibility_control.h" + +namespace hardware_interface +{ + +class Actuator final +{ +public: + explicit Actuator(std::unique_ptr impl) + : impl_(std::move(impl)) + {} + + ~Actuator() = default; + + HARDWARE_INTERFACE_PUBLIC + hardware_interface_ret_t configure(const ComponentInfo & actuator_info) + { + return impl_->configure(actuator_info); + } + + HARDWARE_INTERFACE_PUBLIC + hardware_interface_ret_t start() + { + return impl_->start(); + } + + HARDWARE_INTERFACE_PUBLIC + hardware_interface_ret_t stop() + { + return impl_->stop(); + } + + HARDWARE_INTERFACE_PUBLIC + bool is_started() const + { + return impl_->is_started(); + } + + HARDWARE_INTERFACE_PUBLIC + hardware_interface_ret_t read(double & data) + { + return impl_->read(data); + } + + HARDWARE_INTERFACE_PUBLIC + hardware_interface_ret_t write(const double & data) + { + return impl_->write(data); + } + + HARDWARE_INTERFACE_PUBLIC + std::string get_interface_name() const + { + return impl_->get_interface_name(); + } + +private: + std::unique_ptr impl_; +}; + +} // namespace hardware_interface +#endif // HARDWARE_INTERFACE__ACTUATOR_HPP_ diff --git a/robot_control_components/include/robot_control_components/component_info.hpp b/hardware_interface/include/hardware_interface/component_info.hpp similarity index 77% rename from robot_control_components/include/robot_control_components/component_info.hpp rename to hardware_interface/include/hardware_interface/component_info.hpp index b657b24538..9cfea4fe22 100644 --- a/robot_control_components/include/robot_control_components/component_info.hpp +++ b/hardware_interface/include/hardware_interface/component_info.hpp @@ -13,16 +13,14 @@ // limitations under the License. -#ifndef ROBOT_CONTROL_COMPONENTS__COMPONENT_INFO_HPP_ -#define ROBOT_CONTROL_COMPONENTS__COMPONENT_INFO_HPP_ +#ifndef HARDWARE_INTERFACE__COMPONENT_INFO_HPP_ +#define HARDWARE_INTERFACE__COMPONENT_INFO_HPP_ #include #include #include -#include "robot_control_components/visibility_control.h" - -namespace robot_control_components +namespace hardware_interface { struct ComponentInfo @@ -39,6 +37,6 @@ struct ComponentInfo std::map hardware_parameters; }; -} // namespace robot_control_components +} // namespace hardware_interface -#endif // ROBOT_CONTROL_COMPONENTS__COMPONENT_INFO_HPP_ +#endif // HARDWARE_INTERFACE__COMPONENT_INFO_HPP_ diff --git a/hardware_interface/include/hardware_interface/component_interfaces/actuator_interface.hpp b/hardware_interface/include/hardware_interface/component_interfaces/actuator_interface.hpp new file mode 100644 index 0000000000..e17e59a657 --- /dev/null +++ b/hardware_interface/include/hardware_interface/component_interfaces/actuator_interface.hpp @@ -0,0 +1,70 @@ +// 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 HARDWARE_INTERFACE__COMPONENT_INTERFACES__ACTUATOR_INTERFACE_HPP_ +#define HARDWARE_INTERFACE__COMPONENT_INTERFACES__ACTUATOR_INTERFACE_HPP_ + +#include +#include +#include +#include + +#include "hardware_interface/component_info.hpp" +#include "hardware_interface/types/hardware_interface_return_values.hpp" +#include "hardware_interface/visibility_control.h" + +namespace hardware_interface +{ + +class ActuatorInterface +{ +public: + HARDWARE_INTERFACE_PUBLIC + ActuatorInterface() = default; + + HARDWARE_INTERFACE_PUBLIC + virtual + ~ActuatorInterface() = default; + + HARDWARE_INTERFACE_PUBLIC + virtual + hardware_interface_ret_t configure(const ComponentInfo & actuator_info) = 0; + + HARDWARE_INTERFACE_PUBLIC + virtual + std::string get_interface_name() const = 0; + + HARDWARE_INTERFACE_PUBLIC + virtual + hardware_interface_ret_t start() = 0; + + HARDWARE_INTERFACE_PUBLIC + virtual + hardware_interface_ret_t stop() = 0; + + HARDWARE_INTERFACE_PUBLIC + virtual + bool is_started() const = 0; + + HARDWARE_INTERFACE_PUBLIC + virtual + hardware_interface_ret_t read(double & data) = 0; + + HARDWARE_INTERFACE_PUBLIC + virtual + hardware_interface_ret_t write(const double & data) = 0; +}; + +} // namespace hardware_interface +#endif // HARDWARE_INTERFACE__COMPONENT_INTERFACES__ACTUATOR_INTERFACE_HPP_ diff --git a/hardware_interface/include/hardware_interface/component_interfaces/sensor_interface.hpp b/hardware_interface/include/hardware_interface/component_interfaces/sensor_interface.hpp new file mode 100644 index 0000000000..b96ce1cb04 --- /dev/null +++ b/hardware_interface/include/hardware_interface/component_interfaces/sensor_interface.hpp @@ -0,0 +1,63 @@ +// 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 HARDWARE_INTERFACE__COMPONENT_INTERFACES__SENSOR_INTERFACE_HPP_ +#define HARDWARE_INTERFACE__COMPONENT_INTERFACES__SENSOR_INTERFACE_HPP_ + +#include + +#include "hardware_interface/component_info.hpp" +#include "hardware_interface/types/hardware_interface_return_values.hpp" +#include "hardware_interface/visibility_control.h" + +namespace hardware_interface +{ + +class SensorInterface +{ +public: + HARDWARE_INTERFACE_PUBLIC + SensorInterface() = default; + + HARDWARE_INTERFACE_PUBLIC + virtual + ~SensorInterface() = default; + + HARDWARE_INTERFACE_PUBLIC + virtual + hardware_interface_ret_t configure(const ComponentInfo & sensor_info) = 0; + + HARDWARE_INTERFACE_PUBLIC + virtual + std::string get_interface_name() const = 0; + + HARDWARE_INTERFACE_PUBLIC + virtual + hardware_interface_ret_t start() = 0; + + HARDWARE_INTERFACE_PUBLIC + virtual + hardware_interface_ret_t stop() = 0; + + HARDWARE_INTERFACE_PUBLIC + virtual + bool is_started() const = 0; + + HARDWARE_INTERFACE_PUBLIC + virtual + hardware_interface_ret_t read(double & data) = 0; +}; + +} // namespace hardware_interface +#endif // HARDWARE_INTERFACE__COMPONENT_INTERFACES__SENSOR_INTERFACE_HPP_ diff --git a/hardware_interface/include/hardware_interface/component_interfaces/system_interface.hpp b/hardware_interface/include/hardware_interface/component_interfaces/system_interface.hpp new file mode 100644 index 0000000000..4367324099 --- /dev/null +++ b/hardware_interface/include/hardware_interface/component_interfaces/system_interface.hpp @@ -0,0 +1,68 @@ +// 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 HARDWARE_INTERFACE__COMPONENT_INTERFACES__SYSTEM_INTERFACE_HPP_ +#define HARDWARE_INTERFACE__COMPONENT_INTERFACES__SYSTEM_INTERFACE_HPP_ + +#include +#include + +#include "hardware_interface/component_info.hpp" +#include "hardware_interface/types/hardware_interface_return_values.hpp" +#include "hardware_interface/visibility_control.h" + +namespace hardware_interface +{ + +class SystemInterface +{ +public: + HARDWARE_INTERFACE_PUBLIC + SystemInterface() = default; + + HARDWARE_INTERFACE_PUBLIC + virtual + ~SystemInterface() = default; + + HARDWARE_INTERFACE_PUBLIC + virtual + hardware_interface_ret_t configure(const ComponentInfo & sensor_info) = 0; + + HARDWARE_INTERFACE_PUBLIC + virtual + std::vector get_interface_names() const = 0; + + HARDWARE_INTERFACE_PUBLIC + virtual + hardware_interface_ret_t start() = 0; + + HARDWARE_INTERFACE_PUBLIC + virtual + hardware_interface_ret_t stop() = 0; + + HARDWARE_INTERFACE_PUBLIC + virtual + bool is_started() const = 0; + + HARDWARE_INTERFACE_PUBLIC + virtual + hardware_interface_ret_t read(std::vector & data) = 0; + + hardware_interface_ret_t + virtual + write(const std::vector & data) = 0; +}; + +} // namespace hardware_interface +#endif // HARDWARE_INTERFACE__COMPONENT_INTERFACES__SYSTEM_INTERFACE_HPP_ diff --git a/hardware_interface/include/hardware_interface/robot_hardware.hpp b/hardware_interface/include/hardware_interface/robot_hardware.hpp index 674ebe148b..0033204b7e 100644 --- a/hardware_interface/include/hardware_interface/robot_hardware.hpp +++ b/hardware_interface/include/hardware_interface/robot_hardware.hpp @@ -18,10 +18,13 @@ #include #include +#include "hardware_interface/actuator.hpp" #include "hardware_interface/joint_command_handle.hpp" #include "hardware_interface/joint_state_handle.hpp" #include "hardware_interface/operation_mode_handle.hpp" #include "hardware_interface/robot_hardware_interface.hpp" +#include "hardware_interface/sensor.hpp" +#include "hardware_interface/system.hpp" #include "hardware_interface/types/hardware_interface_return_values.hpp" #include "hardware_interface/visibility_control.h" @@ -86,6 +89,10 @@ class RobotHardware : public RobotHardwareInterface std::vector registered_joint_state_handles_; std::vector registered_joint_command_handles_; std::vector registered_operation_mode_handles_; + + std::vector actuators_; + std::vector sensors_; + std::vector systems_; }; } // namespace hardware_interface diff --git a/hardware_interface/include/hardware_interface/robot_hardware_interface.hpp b/hardware_interface/include/hardware_interface/robot_hardware_interface.hpp index 3ec64f4be7..2b1d54d249 100644 --- a/hardware_interface/include/hardware_interface/robot_hardware_interface.hpp +++ b/hardware_interface/include/hardware_interface/robot_hardware_interface.hpp @@ -18,8 +18,6 @@ #include "hardware_interface/types/hardware_interface_return_values.hpp" #include "hardware_interface/visibility_control.h" -#include "robot_control_components/robot.hpp" - namespace hardware_interface { @@ -44,9 +42,6 @@ class RobotHardwareInterface HARDWARE_INTERFACE_PUBLIC virtual hardware_interface_ret_t write() = 0; - - - robot_control_components::Robot robot_; }; } // namespace hardware_interface diff --git a/hardware_interface/include/hardware_interface/sensor.hpp b/hardware_interface/include/hardware_interface/sensor.hpp new file mode 100644 index 0000000000..7c8cfa3c93 --- /dev/null +++ b/hardware_interface/include/hardware_interface/sensor.hpp @@ -0,0 +1,75 @@ +// 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 HARDWARE_INTERFACE__SENSOR_HPP_ +#define HARDWARE_INTERFACE__SENSOR_HPP_ + +#include +#include +#include + +#include "hardware_interface/component_info.hpp" +#include "hardware_interface/component_interfaces/sensor_interface.hpp" +#include "hardware_interface/types/hardware_interface_return_values.hpp" +#include "hardware_interface/visibility_control.h" + +namespace hardware_interface +{ + +class Sensor final +{ +public: + explicit Sensor(std::unique_ptr impl) + : impl_(std::move(impl)) + {} + + virtual ~Sensor() = default; + + HARDWARE_INTERFACE_PUBLIC + hardware_interface_ret_t configure(const ComponentInfo & sensor_info) + { + return impl_->configure(sensor_info); + } + + HARDWARE_INTERFACE_PUBLIC + hardware_interface_ret_t start() + { + return impl_->start(); + } + + HARDWARE_INTERFACE_PUBLIC + hardware_interface_ret_t stop() + { + return impl_->stop(); + } + + HARDWARE_INTERFACE_PUBLIC + hardware_interface_ret_t read(double & data) + { + return impl_->read(data); + } + + HARDWARE_INTERFACE_PUBLIC + std::string get_interface_name() + { + return impl_->get_interface_name(); + } + +private: + std::unique_ptr impl_; +}; + +} // namespace hardware_interface +#endif // HARDWARE_INTERFACE__SENSOR_HPP_ diff --git a/hardware_interface/include/hardware_interface/system.hpp b/hardware_interface/include/hardware_interface/system.hpp new file mode 100644 index 0000000000..0575903213 --- /dev/null +++ b/hardware_interface/include/hardware_interface/system.hpp @@ -0,0 +1,86 @@ +// 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 HARDWARE_INTERFACE__SYSTEM_HPP_ +#define HARDWARE_INTERFACE__SYSTEM_HPP_ + +#include +#include +#include +#include + +#include "hardware_interface/component_info.hpp" +#include "hardware_interface/component_interfaces/system_interface.hpp" +#include "hardware_interface/visibility_control.h" + +namespace hardware_interface +{ + +class System final +{ +public: + explicit System(std::unique_ptr impl) + : impl_(std::move(impl)) + {} + + virtual ~System() = default; + + HARDWARE_INTERFACE_PUBLIC + hardware_interface_ret_t configure(const ComponentInfo & sensor_info) + { + return impl_->configure(sensor_info); + } + + HARDWARE_INTERFACE_PUBLIC + std::vector get_interface_names() + { + return impl_->get_interface_names(); + } + + HARDWARE_INTERFACE_PUBLIC + hardware_interface_ret_t start() + { + return impl_->start(); + } + + HARDWARE_INTERFACE_PUBLIC + hardware_interface_ret_t stop() + { + return impl_->stop(); + } + + HARDWARE_INTERFACE_PUBLIC + bool is_started() + { + return impl_->is_started(); + } + + HARDWARE_INTERFACE_PUBLIC + hardware_interface_ret_t read(std::vector & data) + { + return impl_->read(data); + } + + HARDWARE_INTERFACE_PUBLIC + hardware_interface_ret_t write(const std::vector & data) + { + return impl_->write(data); + } + +private: + std::unique_ptr impl_; +}; + +} // namespace hardware_interface +#endif // HARDWARE_INTERFACE__SYSTEM_HPP_ diff --git a/robot_control_components/include/robot_control_components/component_parser.hpp b/hardware_interface/include/hardware_interface/utils/component_parser.hpp similarity index 75% rename from robot_control_components/include/robot_control_components/component_parser.hpp rename to hardware_interface/include/hardware_interface/utils/component_parser.hpp index 5a43951a1b..ba011af8b6 100644 --- a/robot_control_components/include/robot_control_components/component_parser.hpp +++ b/hardware_interface/include/hardware_interface/utils/component_parser.hpp @@ -12,19 +12,20 @@ // See the License for the specific language governing permissions and // limitations under the License. - -#ifndef ROBOT_CONTROL_COMPONENTS__COMPONENT_PARSER_HPP_ -#define ROBOT_CONTROL_COMPONENTS__COMPONENT_PARSER_HPP_ +#ifndef HARDWARE_INTERFACE__UTILS__COMPONENT_PARSER_HPP_ +#define HARDWARE_INTERFACE__UTILS__COMPONENT_PARSER_HPP_ #include #include -#include "robot_control_components/component_info.hpp" -#include "robot_control_components/visibility_control.h" - +#include "hardware_interface/component_info.hpp" +#include "hardware_interface/visibility_control.h" -namespace robot_control_components +namespace hardware_interface +{ +namespace utils { + /** * \brief Search XML snippet from URDF for informations about a control component. * @@ -32,7 +33,7 @@ namespace robot_control_components * \return robot_control_components::ComponentInfo filled with informations about the robot * \throws std::runtime_error if a robot attribute or tag is not found */ -ROBOT_CONTROL_COMPONENTS_PUBLIC +HARDWARE_INTERFACE_PUBLIC ComponentInfo parse_robot_from_urdf(const std::string & urdf); /** @@ -42,7 +43,7 @@ ComponentInfo parse_robot_from_urdf(const std::string & urdf); * \return robot_control_components::ComponentInfo filled with informations about component * \throws std::runtime_error if a component attribute or tag is not found */ -ROBOT_CONTROL_COMPONENTS_PUBLIC +HARDWARE_INTERFACE_PUBLIC ComponentInfo parse_component_from_xml(const tinyxml2::XMLElement * component_it); /** @@ -52,7 +53,10 @@ ComponentInfo parse_component_from_xml(const tinyxml2::XMLElement * component_it * \return std::map< std::__cxx11::string, std::__cxx11::string > key-value map with parameters * \throws std::runtime_error if a component attribute or tag is not found */ -ROBOT_CONTROL_COMPONENTS_PUBLIC -std::map parse_parameters_from_xml(const tinyxml2::XMLElement * params_it); -} // namespace robot_control_components -#endif // ROBOT_CONTROL_COMPONENTS__COMPONENT_PARSER_HPP_ +HARDWARE_INTERFACE_PUBLIC +std::map parse_parameters_from_xml( + const tinyxml2::XMLElement * params_it); + +} // namespace utils +} // namespace hardware_interface +#endif // HARDWARE_INTERFACE__UTILS__COMPONENT_PARSER_HPP_ diff --git a/robot_control_components/include/robot_control_components/ros2_control_utils.hpp b/hardware_interface/include/hardware_interface/utils/ros2_control_utils.hpp similarity index 86% rename from robot_control_components/include/robot_control_components/ros2_control_utils.hpp rename to hardware_interface/include/hardware_interface/utils/ros2_control_utils.hpp index 67b64a53e7..c559cb76a9 100644 --- a/robot_control_components/include/robot_control_components/ros2_control_utils.hpp +++ b/hardware_interface/include/hardware_interface/utils/ros2_control_utils.hpp @@ -34,13 +34,16 @@ namespace ros2_control_utils { // Classes -template < typename T > +template class ROS2ControlLoaderPluginlib { public: - ROBOT_CONTROL_COMPONENTS_PUBLIC ROS2ControlLoaderPluginlib(const std::string package, const std::string base_type) : loader_(std::make_shared>(package, base_type)) + ROBOT_CONTROL_COMPONENTS_PUBLIC ROS2ControlLoaderPluginlib( + const std::string package, + const std::string base_type) + : loader_(std::make_shared>(package, base_type)) { - }; + } ROBOT_CONTROL_COMPONENTS_PUBLIC virtual ~ROS2ControlLoaderPluginlib() = default; @@ -50,20 +53,19 @@ class ROS2ControlLoaderPluginlib std::shared_ptr create(const std::string & type) { return std::shared_ptr(loader_->createUnmanagedInstance(type)); - }; + } ROBOT_CONTROL_COMPONENTS_PUBLIC bool is_available(const std::string & type) { return loader_->isClassAvailable(type); - }; + } private: - std::shared_ptr> loader_; + std::shared_ptr> loader_; }; - } // namespace ros2_control_utils #endif // ROBOT_CONTROL_COMPONENTS__ROS2_CONTROL_UTILS_H_ diff --git a/hardware_interface/package.xml b/hardware_interface/package.xml index 5630695f39..bbfa2dd909 100644 --- a/hardware_interface/package.xml +++ b/hardware_interface/package.xml @@ -11,9 +11,10 @@ rclcpp rcpputils - robot_control_components + tinyxml2_vendor + TinyXML2 - ament_cmake_gtest + ament_cmake_gmock ament_lint_auto ament_lint_common diff --git a/robot_control_components/src/utils/component_parser.cpp b/hardware_interface/src/utils/component_parser.cpp similarity index 81% rename from robot_control_components/src/utils/component_parser.cpp rename to hardware_interface/src/utils/component_parser.cpp index 27c4f9f16d..dae5abcf14 100644 --- a/robot_control_components/src/utils/component_parser.cpp +++ b/hardware_interface/src/utils/component_parser.cpp @@ -12,29 +12,32 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "robot_control_components/component_parser.hpp" -#include "robot_control_components/component_info.hpp" +#include "hardware_interface/utils/component_parser.hpp" #include #include #include +#include "hardware_interface/component_info.hpp" + namespace { - constexpr const auto kRobotTag = "robot"; - constexpr const auto kROS2ControlTag = "ros2_control"; - constexpr const auto kHardwareTag = "hardware"; - constexpr const auto kClassTypeTag = "classType"; - constexpr const auto kParamTag = "param"; - constexpr const auto kJointTag = "joint"; - constexpr const auto kInterfaceNameTag = "interfaceName"; - - // For compleate reference of syntax - not used in parser - constexpr const auto kActuatorTag = "actuator"; - constexpr const auto kSensorTag = "sensor"; +constexpr const auto kRobotTag = "robot"; +constexpr const auto kROS2ControlTag = "ros2_control"; +constexpr const auto kHardwareTag = "hardware"; +constexpr const auto kClassTypeTag = "classType"; +constexpr const auto kParamTag = "param"; +constexpr const auto kJointTag = "joint"; +constexpr const auto kInterfaceNameTag = "interfaceName"; + +// For compleate reference of syntax - not used in parser +//constexpr const auto kActuatorTag = "actuator"; +//constexpr const auto kSensorTag = "sensor"; } // namespace -namespace robot_control_components +namespace hardware_interface +{ +namespace utils { ComponentInfo parse_robot_from_urdf(const std::string & urdf) @@ -71,8 +74,7 @@ ComponentInfo parse_robot_from_urdf(const std::string & urdf) // Parse everything under ros2_control tag robot.hardware_class_type = ""; const auto * ros2_control_child_it = ros2_control_it->FirstChildElement(); - while (ros2_control_child_it) - { + while (ros2_control_child_it) { if (!std::string(kHardwareTag).compare(ros2_control_child_it->Name())) { const auto * type_it = ros2_control_child_it->FirstChildElement(kClassTypeTag); robot.hardware_class_type = type_it->GetText(); @@ -80,9 +82,8 @@ ComponentInfo parse_robot_from_urdf(const std::string & urdf) if (params_it) { robot.hardware_parameters = parse_parameters_from_xml(params_it); } - } - else { - robot.subcomponents.push_back( parse_component_from_xml(ros2_control_child_it) ); + } else { + robot.subcomponents.push_back(parse_component_from_xml(ros2_control_child_it) ); } ros2_control_child_it = ros2_control_child_it->NextSiblingElement(); @@ -121,12 +122,14 @@ ComponentInfo parse_component_from_xml(const tinyxml2::XMLElement * component_it } const auto * interface_name_it = joint_it->FirstChildElement(kInterfaceNameTag); if (!interface_name_it) { - throw std::runtime_error("no interface names found for " + component.joint + " in " + component.name); + throw std::runtime_error( + "no interface names found for " + component.joint + " in " + component.name); } while (interface_name_it) { const std::string interface_name = interface_name_it->GetText(); if (interface_name.empty()) { - throw std::runtime_error("no interface name value in " + component.joint + " of " + component.name); + throw std::runtime_error( + "no interface name value in " + component.joint + " of " + component.name); } component.interface_names.push_back(interface_name); @@ -148,15 +151,15 @@ ComponentInfo parse_component_from_xml(const tinyxml2::XMLElement * component_it if (params_it) { component.hardware_parameters = parse_parameters_from_xml(params_it); } - } - else { + } else { component.hardware_class_type = ""; } return component; } -std::map parse_parameters_from_xml(const tinyxml2::XMLElement * params_it) +std::map parse_parameters_from_xml( + const tinyxml2::XMLElement * params_it) { std::map parameters; while (params_it) { @@ -176,4 +179,5 @@ std::map parse_parameters_from_xml(const tinyxml2::XML return parameters; } +} // namespace utils } // namespace robot_control_components diff --git a/robot_control_components/test/test_component_parser.cpp b/hardware_interface/test/test_component_parser.cpp similarity index 95% rename from robot_control_components/test/test_component_parser.cpp rename to hardware_interface/test/test_component_parser.cpp index a1f0013628..8b9d80dac3 100644 --- a/robot_control_components/test/test_component_parser.cpp +++ b/hardware_interface/test/test_component_parser.cpp @@ -15,7 +15,7 @@ #include #include -#include "robot_control_components/component_parser.hpp" +#include "hardware_interface/utils/component_parser.hpp" using namespace ::testing; // NOLINT @@ -24,8 +24,8 @@ class TestComponentParser : public Test protected: void SetUp() override { - urdf_xml_head_= - R"( + urdf_xml_head_ = + R"( @@ -145,8 +145,8 @@ class TestComponentParser : public Test )"; - urdf_xml_tail_= - R"( + urdf_xml_tail_ = + R"( transmission_interface/SimpleTransmission @@ -168,8 +168,8 @@ class TestComponentParser : public Test )"; - valid_urdf_ros2_control_actuators_only_= - R"( + valid_urdf_ros2_control_actuators_only_ = + R"( ros2_control_demo_hardware/DemoRobotHardwareMinimal @@ -197,8 +197,8 @@ class TestComponentParser : public Test )"; - valid_urdf_ros2_control_actuators_sensors_= - R"( + valid_urdf_ros2_control_actuators_sensors_ = + R"( ros2_control_demo_hardware/DemoRobotHardwareMinimal @@ -230,11 +230,12 @@ class TestComponentParser : public Test std::string valid_urdf_ros2_control_actuators_only_, valid_urdf_ros2_control_actuators_sensors_; }; -using robot_control_components::parse_robot_from_urdf; +using hardware_interface::utils::parse_robot_from_urdf; TEST_F(TestComponentParser, successfully_parse_valid_urdf_actuators) { - std::string urdf_to_test = urdf_xml_head_ + valid_urdf_ros2_control_actuators_only_ + urdf_xml_tail_; + std::string urdf_to_test = urdf_xml_head_ + valid_urdf_ros2_control_actuators_only_ + + urdf_xml_tail_; const auto robot_info = parse_robot_from_urdf(urdf_to_test); EXPECT_EQ(robot_info.name, "MinimalRobot"); @@ -257,7 +258,8 @@ TEST_F(TestComponentParser, successfully_parse_valid_urdf_actuators) TEST_F(TestComponentParser, successfully_parse_valid_urdf_actuators_sensors) { - std::string urdf_to_test = urdf_xml_head_ + valid_urdf_ros2_control_actuators_sensors_ + urdf_xml_tail_; + std::string urdf_to_test = urdf_xml_head_ + valid_urdf_ros2_control_actuators_sensors_ + + urdf_xml_tail_; const auto robot_info = parse_robot_from_urdf(urdf_to_test); EXPECT_EQ(robot_info.name, "MinimalRobot"); @@ -288,7 +290,7 @@ TEST_F(TestComponentParser, empty_string_throws_error) TEST_F(TestComponentParser, empty_urdf_throws_error) { const std::string empty_urdf = - ""; + ""; ASSERT_THROW(parse_robot_from_urdf(empty_urdf), std::runtime_error); } diff --git a/robot_control_components/CMakeLists.txt b/robot_control_components/CMakeLists.txt index eb7b68ddcb..6accad9e91 100644 --- a/robot_control_components/CMakeLists.txt +++ b/robot_control_components/CMakeLists.txt @@ -14,112 +14,41 @@ endif() # find dependencies find_package(ament_cmake REQUIRED) -find_package(control_msgs REQUIRED) +find_package(hardware_interface REQUIRED) find_package(pluginlib REQUIRED) -find_package(rclcpp REQUIRED) -find_package(tinyxml2_vendor REQUIRED) -find_package(TinyXML2 REQUIRED) - -add_library(component_parser SHARED - src/utils/component_parser.cpp -) - -target_include_directories(component_parser - PRIVATE include -) - -ament_target_dependencies(component_parser - TinyXML2 -) add_library(${PROJECT_NAME} SHARED - src/actuator.cpp - src/robot.cpp - src/sensor.cpp + # actuators + src/effort_actuator.cpp + src/position_actuator.cpp + src/velocity_actuator.cpp + # sensors + src/position_sensor.cpp + src/velocity_sensor.cpp ) - target_include_directories(${PROJECT_NAME} PRIVATE include ) - -target_link_libraries(${PROJECT_NAME} - component_parser -) - ament_target_dependencies(${PROJECT_NAME} - control_msgs - pluginlib - rclcpp -) - -add_library(${PROJECT_NAME}_actuators SHARED - src/impl/effort_actuator.cpp - src/impl/position_actuator.cpp - src/impl/velocity_actuator.cpp -) - -target_include_directories(${PROJECT_NAME}_actuators - PRIVATE include -) - -ament_target_dependencies(${PROJECT_NAME}_actuators - control_msgs + hardware_interface pluginlib - rclcpp ) -add_library(${PROJECT_NAME}_sensors SHARED - src/impl/position_sensor.cpp - src/impl/velocity_sensor.cpp -) - -target_include_directories(${PROJECT_NAME}_sensors - PRIVATE include -) - -ament_target_dependencies(${PROJECT_NAME}_sensors - control_msgs - pluginlib - rclcpp -) - -pluginlib_export_plugin_description_file(robot_control_components robot_control_components_plugins.xml) +pluginlib_export_plugin_description_file( + robot_control_components robot_control_components_plugins.xml) install(TARGETS - component_parser ${PROJECT_NAME} - ${PROJECT_NAME}_actuators - ${PROJECT_NAME}_sensors DESTINATION lib ) -install(DIRECTORY include/ - DESTINATION include -) - if(BUILD_TESTING) - find_package(ament_cmake_gmock REQUIRED) find_package(ament_lint_auto REQUIRED) ament_lint_auto_find_test_dependencies() - - ament_add_gmock(test_component_parser test/test_component_parser.cpp) - target_include_directories(test_component_parser PRIVATE include) - target_link_libraries(test_component_parser component_parser) endif() ament_export_dependencies( - control_msgs + hardware_interface pluginlib - rclcpp -) -ament_export_libraries( - component_parser - ${PROJECT_NAME} - ${PROJECT_NAME}_actuators - ${PROJECT_NAME}_sensors -) -ament_export_include_directories( -include ) ament_package() - diff --git a/robot_control_components/include/robot_control_components/actuator.hpp b/robot_control_components/include/robot_control_components/actuator.hpp deleted file mode 100644 index 39f1c528b2..0000000000 --- a/robot_control_components/include/robot_control_components/actuator.hpp +++ /dev/null @@ -1,88 +0,0 @@ -// 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 ROBOT_CONTROL_COMPONENTS__ACTUATOR_HPP_ -#define ROBOT_CONTROL_COMPONENTS__ACTUATOR_HPP_ - -#include -#include - -#include "control_msgs/msg/interface_value.hpp" - -#include "rclcpp/macros.hpp" -#include "rclcpp/rclcpp.hpp" - -#include "robot_control_components/component_info.hpp" -#include "robot_control_components/ros2_control_types.h" -#include "robot_control_components/visibility_control.h" - - -namespace robot_control_components -{ - -class Actuator -{ -public: - RCLCPP_SHARED_PTR_DEFINITIONS(Actuator) - - Actuator() = default; - - virtual ~Actuator() = default; - - ROBOT_CONTROL_COMPONENTS_PUBLIC components_ret_t configure(ComponentInfo actuator_info); - - ROBOT_CONTROL_COMPONENTS_PUBLIC components_ret_t init(); - - ROBOT_CONTROL_COMPONENTS_PUBLIC components_ret_t recover(); - - ROBOT_CONTROL_COMPONENTS_PUBLIC components_ret_t start(); - - ROBOT_CONTROL_COMPONENTS_PUBLIC components_ret_t stop(); - - ROBOT_CONTROL_COMPONENTS_PUBLIC components_ret_t read(); - - ROBOT_CONTROL_COMPONENTS_PUBLIC components_ret_t write(); - - ROBOT_CONTROL_COMPONENTS_PUBLIC components_ret_t get_data(control_msgs::msg::InterfaceValue * data); - - ROBOT_CONTROL_COMPONENTS_PUBLIC components_ret_t set_data(control_msgs::msg::InterfaceValue * data, std::string claimer_id); - - ROBOT_CONTROL_COMPONENTS_PUBLIC std::vector get_interface_names(); - - ROBOT_CONTROL_COMPONENTS_PUBLIC components_ret_t claim(const std::string claimer_id); - - ROBOT_CONTROL_COMPONENTS_PUBLIC components_ret_t unclaim(const std::string claimer_id); - - ROBOT_CONTROL_COMPONENTS_PUBLIC bool isClaimed(); - - ROBOT_CONTROL_COMPONENTS_PUBLIC bool canRead(); - -protected: - std::string name_; - std::string type_; - bool can_read_; - bool has_hardware_; - bool read_async_; - - std::string claimer_id_; - - std::vector valid_interface_names_; - std::vector interface_names_; - control_msgs::msg::InterfaceValue data_; -}; - -} // namespace robot_control_components - -#endif // ROBOT_CONTROL_COMPONENTS__ACTUATOR_HPP_ diff --git a/robot_control_components/include/robot_control_components/impl/effort_actuator.hpp b/robot_control_components/include/robot_control_components/impl/effort_actuator.hpp deleted file mode 100644 index 1fda6ba9f5..0000000000 --- a/robot_control_components/include/robot_control_components/impl/effort_actuator.hpp +++ /dev/null @@ -1,49 +0,0 @@ -// 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 ROBOT_CONTROL_COMPONENTS__IMPL_EFFORT_ACTUATOR_HPP_ -#define ROBOT_CONTROL_COMPONENTS__IMPL_EFFORT_ACTUATOR_HPP_ - - -#include "rclcpp/macros.hpp" - -#include "robot_control_components/ros2_control_types.h" -#include "robot_control_components/actuator.hpp" -#include "robot_control_components/visibility_control.h" - - -using namespace robot_control_components; - -namespace robot_control_components_actuators -{ - -class EffortActuator : public Actuator -{ -public: - RCLCPP_SHARED_PTR_DEFINITIONS(EffortActuator); - - ROBOT_CONTROL_COMPONENTS_PUBLIC EffortActuator() : Actuator() { - valid_interface_names_.resize(1); - valid_interface_names_.push_back(ROS2C_INTERFACE_EFFORT); - }; - - ROBOT_CONTROL_COMPONENTS_PUBLIC ~EffortActuator() = default; - -}; - -} // namespace robot_control_components_sensors - -#endif // ROBOT_CONTROL_COMPONENTS__IMPL_EFFORT_ACTUATOR_HPP_ - diff --git a/robot_control_components/include/robot_control_components/impl/position_actuator.hpp b/robot_control_components/include/robot_control_components/impl/position_actuator.hpp deleted file mode 100644 index 6664d18946..0000000000 --- a/robot_control_components/include/robot_control_components/impl/position_actuator.hpp +++ /dev/null @@ -1,49 +0,0 @@ -// 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 ROBOT_CONTROL_COMPONENTS__IMPL_POSITION_ACTUATOR_HPP_ -#define ROBOT_CONTROL_COMPONENTS__IMPL_POSITION_ACTUATOR_HPP_ - - -#include "rclcpp/macros.hpp" - -#include "robot_control_components/ros2_control_types.h" -#include "robot_control_components/actuator.hpp" -#include "robot_control_components/visibility_control.h" - - -using namespace robot_control_components; - -namespace robot_control_components_actuators -{ - -class PositionActuator : public Actuator -{ -public: - RCLCPP_SHARED_PTR_DEFINITIONS(PositionActuator); - - ROBOT_CONTROL_COMPONENTS_PUBLIC PositionActuator() : Actuator() { - valid_interface_names_.resize(1); - valid_interface_names_.push_back(ROS2C_INTERFACE_POSITION); - }; - - ROBOT_CONTROL_COMPONENTS_PUBLIC ~PositionActuator() = default; - -}; - -} // namespace robot_control_components_sensors - -#endif // ROBOT_CONTROL_COMPONENTS__IMPL_POSITION_ACTUATOR_HPP_ - diff --git a/robot_control_components/include/robot_control_components/impl/position_sensor.hpp b/robot_control_components/include/robot_control_components/impl/position_sensor.hpp deleted file mode 100644 index d1decb9672..0000000000 --- a/robot_control_components/include/robot_control_components/impl/position_sensor.hpp +++ /dev/null @@ -1,49 +0,0 @@ -// 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 ROBOT_CONTROL_COMPONENTS__IMPL_POSITION_SENSOR_HPP_ -#define ROBOT_CONTROL_COMPONENTS__IMPL_POSITION_SENSOR_HPP_ - - -#include "rclcpp/macros.hpp" - -#include "robot_control_components/ros2_control_types.h" -#include "robot_control_components/sensor.hpp" -#include "robot_control_components/visibility_control.h" - - -using namespace robot_control_components; - -namespace robot_control_components_sensors -{ - -class PositionSensor : public Sensor -{ -public: - RCLCPP_SHARED_PTR_DEFINITIONS(PositionSensor); - - ROBOT_CONTROL_COMPONENTS_PUBLIC PositionSensor() : Sensor() { - valid_interface_names_.resize(1); - valid_interface_names_.push_back(ROS2C_INTERFACE_POSITION); - }; - - ROBOT_CONTROL_COMPONENTS_PUBLIC ~PositionSensor() = default; - -}; - -} // namespace robot_control_components_sensors - -#endif // ROBOT_CONTROL_COMPONENTS__IMPL_POSITION_SENSOR_HPP_ - diff --git a/robot_control_components/include/robot_control_components/impl/velocity_actuator.hpp b/robot_control_components/include/robot_control_components/impl/velocity_actuator.hpp deleted file mode 100644 index 2d83cafd65..0000000000 --- a/robot_control_components/include/robot_control_components/impl/velocity_actuator.hpp +++ /dev/null @@ -1,49 +0,0 @@ -// 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 ROBOT_CONTROL_COMPONENTS__IMPL_VELOCITY_ACTUATOR_HPP_ -#define ROBOT_CONTROL_COMPONENTS__IMPL_VELOCITY_ACTUATOR_HPP_ - - -#include "rclcpp/macros.hpp" - -#include "robot_control_components/ros2_control_types.h" -#include "robot_control_components/actuator.hpp" -#include "robot_control_components/visibility_control.h" - - -using namespace robot_control_components; - -namespace robot_control_components_actuators -{ - -class VelocityActuator : public Actuator -{ -public: - RCLCPP_SHARED_PTR_DEFINITIONS(VelocityActuator); - - ROBOT_CONTROL_COMPONENTS_PUBLIC VelocityActuator() : Actuator() { - valid_interface_names_.resize(1); - valid_interface_names_.push_back(ROS2C_INTERFACE_VELOCITY); - }; - - ROBOT_CONTROL_COMPONENTS_PUBLIC ~VelocityActuator() = default; - -}; - -} // namespace robot_control_components_sensors - -#endif // ROBOT_CONTROL_COMPONENTS__IMPL_VELOCITY_ACTUATOR_HPP_ - diff --git a/robot_control_components/include/robot_control_components/impl/velocity_sensor.hpp b/robot_control_components/include/robot_control_components/impl/velocity_sensor.hpp deleted file mode 100644 index a7ee80e690..0000000000 --- a/robot_control_components/include/robot_control_components/impl/velocity_sensor.hpp +++ /dev/null @@ -1,49 +0,0 @@ -// 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 ROBOT_CONTROL_COMPONENTS__IMPL_POSITION_SENSOR_HPP_ -#define ROBOT_CONTROL_COMPONENTS__IMPL_POSITION_SENSOR_HPP_ - - -#include "rclcpp/macros.hpp" - -#include "robot_control_components/ros2_control_types.h" -#include "robot_control_components/sensor.hpp" -#include "robot_control_components/visibility_control.h" - - -using namespace robot_control_components; - -namespace robot_control_components_sensors -{ - -class VelocitySensor : public Sensor -{ -public: - RCLCPP_SHARED_PTR_DEFINITIONS(VelocitySensor); - - ROBOT_CONTROL_COMPONENTS_PUBLIC VelocitySensor() : Sensor() { - valid_interface_names_.resize(1); - valid_interface_names_.push_back(ROS2C_INTERFACE_VELOCITY); - }; - - ROBOT_CONTROL_COMPONENTS_PUBLIC ~VelocitySensor() = default; - -}; - -} // namespace robot_control_components_sensors - -#endif // ROBOT_CONTROL_COMPONENTS__IMPL_POSITION_SENSOR_HPP_ - diff --git a/robot_control_components/include/robot_control_components/robot.hpp b/robot_control_components/include/robot_control_components/robot.hpp deleted file mode 100644 index 7aa33964b0..0000000000 --- a/robot_control_components/include/robot_control_components/robot.hpp +++ /dev/null @@ -1,60 +0,0 @@ -// 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 ROBOT_CONTROL_COMPONENTS__ROBOT_HPP_ -#define ROBOT_CONTROL_COMPONENTS__ROBOT_HPP_ - -#include -#include - -#include "control_msgs/msg/dynamic_joint_state.hpp" -#include "control_msgs/msg/interface_value.hpp" - -#include "rclcpp/macros.hpp" -#include "rclcpp/rclcpp.hpp" - -#include "robot_control_components/actuator.hpp" -#include "robot_control_components/sensor.hpp" -#include "robot_control_components/ros2_control_types.h" -#include "robot_control_components/visibility_control.h" - -namespace robot_control_components -{ - -class Robot -{ -public: - RCLCPP_SHARED_PTR_DEFINITIONS(Robot) - - Robot() = default; - - ~Robot() = default; - - ROBOT_CONTROL_COMPONENTS_PUBLIC components_ret_t configure(const std::string & urdf_string); - - -protected: - - control_msgs::msg::DynamicJointState joint_states_; - - std::vector joint_names_; - - std::map actuators_; - std::map sensors_; - -}; - -} // namespace robot_control_components - -#endif // ROBOT_CONTROL_COMPONENTS__ROBOT_HPP_ diff --git a/robot_control_components/include/robot_control_components/ros2_control_types.h b/robot_control_components/include/robot_control_components/ros2_control_types.h deleted file mode 100644 index 69607511ab..0000000000 --- a/robot_control_components/include/robot_control_components/ros2_control_types.h +++ /dev/null @@ -1,40 +0,0 @@ -// 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 ROBOT_CONTROL_COMPONENTS__ROS2_CONTROL_TYPES_H_ -#define ROBOT_CONTROL_COMPONENTS__ROS2_CONTROL_TYPES_H_ - -#include "robot_control_components/visibility_control.h" - -namespace robot_control_components -{ -using components_ret_t = int; -static constexpr components_ret_t ROS2C_RETURN_OK = 0; -static constexpr components_ret_t ROS2C_RETURN_ERROR = 1; - -static constexpr components_ret_t ROS2C_RETURN_ACTUATOR_CLAIMED_ERROR = 10; -static constexpr components_ret_t ROS2C_RETURN_ACTUATOR_ALREADY_CLAIMED = 11; -static constexpr components_ret_t ROS2C_RETURN_ACTUATOR_NOT_CLAIMED = 11; -static constexpr components_ret_t ROS2C_RETURN_ACTUATOR_UNATHORIZED_UNCLAIM = 13; -static constexpr components_ret_t ROS2C_RETURN_ACTUATOR_NON_CLAIMED_WRITE = 15; - -static constexpr components_ret_t ROS2C_RETURN_ACTUATOR_CAN_NOT_READ = 20; - - -constexpr const auto ROS2C_INTERFACE_POSITION = "position"; -constexpr const auto ROS2C_INTERFACE_VELOCITY = "velocity"; -constexpr const auto ROS2C_INTERFACE_EFFORT = "effor"; - -} // namespace robot_control_components -#endif // ROBOT_CONTROL_COMPONENTS__ROS2_CONTROL_TYPES_H_ diff --git a/robot_control_components/include/robot_control_components/sensor.hpp b/robot_control_components/include/robot_control_components/sensor.hpp deleted file mode 100644 index da779caca7..0000000000 --- a/robot_control_components/include/robot_control_components/sensor.hpp +++ /dev/null @@ -1,72 +0,0 @@ -// 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 ROBOT_CONTROL_COMPONENTS__SENSOR_HPP_ -#define ROBOT_CONTROL_COMPONENTS__SENSOR_HPP_ - -#include -#include - -#include "control_msgs/msg/interface_value.hpp" - -#include "rclcpp/macros.hpp" -#include "rclcpp/rclcpp.hpp" - -#include "robot_control_components/component_info.hpp" -#include "robot_control_components/ros2_control_types.h" -#include "robot_control_components/visibility_control.h" - -namespace robot_control_components -{ - -class Sensor -{ -public: - RCLCPP_SHARED_PTR_DEFINITIONS(Sensor); - - Sensor() = default; - - virtual ~Sensor() = default; - - ROBOT_CONTROL_COMPONENTS_PUBLIC components_ret_t configure(ComponentInfo sensor_info); - - ROBOT_CONTROL_COMPONENTS_PUBLIC components_ret_t init(); - - ROBOT_CONTROL_COMPONENTS_PUBLIC components_ret_t recover(); - - ROBOT_CONTROL_COMPONENTS_PUBLIC components_ret_t start(); - - ROBOT_CONTROL_COMPONENTS_PUBLIC components_ret_t stop(); - - ROBOT_CONTROL_COMPONENTS_PUBLIC components_ret_t read(); - - ROBOT_CONTROL_COMPONENTS_PUBLIC components_ret_t get_value(control_msgs::msg::InterfaceValue * data); - - ROBOT_CONTROL_COMPONENTS_PUBLIC std::vector get_interface_names(); - -protected: - std::string name_; - std::string type_; - bool has_hardware_; - bool read_async_; - - std::vector valid_interface_names_; - std::vector interface_names_; - control_msgs::msg::InterfaceValue data_; -}; - -} // namespace robot_control_components - -#endif // ROBOT_CONTROL_COMPONENTS__SENSOR_HPP_ diff --git a/robot_control_components/include/robot_control_components/visibility_control.h b/robot_control_components/include/robot_control_components/visibility_control.h deleted file mode 100644 index 2b1318341a..0000000000 --- a/robot_control_components/include/robot_control_components/visibility_control.h +++ /dev/null @@ -1,64 +0,0 @@ -// 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. - -/* This header must be included by all rclcpp headers which declare symbols - * which are defined in the rclcpp library. When not building the rclcpp - * library, i.e. when using the headers in other package's code, the contents - * of this header change the visibility of certain symbols which the rclcpp - * library cannot have, but the consuming code must have inorder to link. - */ - -#ifndef ROBOT_CONTROL_COMPONENTS__VISIBILITY_CONTROL_H_ -#define ROBOT_CONTROL_COMPONENTS__VISIBILITY_CONTROL_H_ - -// This logic was borrowed (then namespaced) from the examples on the gcc wiki: -// https://gcc.gnu.org/wiki/Visibility - -#if defined _WIN32 || defined __CYGWIN__ -#ifdef __GNUC__ -#define ROBOT_CONTROL_COMPONENTS_EXPORT \ - __attribute__((dllexport)) -#define ROBOT_CONTROL_COMPONENTS_IMPORT \ - __attribute__((dllimport)) -#else -#define ROBOT_CONTROL_COMPONENTS_EXPORT __declspec(dllexport) -#define ROBOT_CONTROL_COMPONENTS_IMPORT __declspec(dllimport) -#endif -#ifdef ROBOT_CONTROL_COMPONENTS_BUILDING_DLL -#define ROBOT_CONTROL_COMPONENTS_PUBLIC \ - ROBOT_CONTROL_COMPONENTS_EXPORT -#else -#define ROBOT_CONTROL_COMPONENTS_PUBLIC \ - ROBOT_CONTROL_COMPONENTS_IMPORT -#endif -#define ROBOT_CONTROL_COMPONENTS_PUBLIC_TYPE \ - ROBOT_CONTROL_COMPONENTS_PUBLIC -#define ROBOT_CONTROL_COMPONENTS_LOCAL -#else -#define ROBOT_CONTROL_COMPONENTS_EXPORT \ - __attribute__((visibility("default"))) -#define ROBOT_CONTROL_COMPONENTS_IMPORT -#if __GNUC__ >= 4 -#define ROBOT_CONTROL_COMPONENTS_PUBLIC \ - __attribute__((visibility("default"))) -#define ROBOT_CONTROL_COMPONENTS_LOCAL \ - __attribute__((visibility("hidden"))) -#else -#define ROBOT_CONTROL_COMPONENTS_PUBLIC -#define ROBOT_CONTROL_COMPONENTS_LOCAL -#endif -#define ROBOT_CONTROL_COMPONENTS_PUBLIC_TYPE -#endif - -#endif // ROBOT_CONTROL_COMPONENTS__VISIBILITY_CONTROL_H_ diff --git a/robot_control_components/package.xml b/robot_control_components/package.xml index 963cdce180..1133b99210 100644 --- a/robot_control_components/package.xml +++ b/robot_control_components/package.xml @@ -4,17 +4,13 @@ robot_control_components 0.0.0 The main package for `ros2_control`-concept testing. The package implements the most important classes and tests them with `demo_robot` to enable functionality and test driven development. - stogl + Denis Štogl Apache License 2.0 - Denis Štogl - control_msgs + hardware_interface pluginlib - rclcpp - tinyxml2_vendor - ament_cmake_gmock ament_lint_auto ament_lint_common diff --git a/robot_control_components/robot_control_components_plugins.xml b/robot_control_components/robot_control_components_plugins.xml index dafde0a53e..906c0486cb 100644 --- a/robot_control_components/robot_control_components_plugins.xml +++ b/robot_control_components/robot_control_components_plugins.xml @@ -1,28 +1,25 @@ - + The effot actuator provides virtual representation of effot-only actuator. - + The position actuator provides virtual representation of position-only actuator. - + The velocity actuator provides virtual representation of velocity-only actuator. - - - - + The position sensor provides virtual representation of position-only sensor. - + The velocity sensor provides virtual representation of velocity-only sensor. diff --git a/robot_control_components/src/actuator.cpp b/robot_control_components/src/actuator.cpp deleted file mode 100644 index ed853f1581..0000000000 --- a/robot_control_components/src/actuator.cpp +++ /dev/null @@ -1,121 +0,0 @@ -// 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 "robot_control_components/actuator.hpp" - -namespace robot_control_components -{ - -components_ret_t Actuator::configure(ComponentInfo actuator_info) -{ - return ROS2C_RETURN_OK; -} - -components_ret_t Actuator::init() -{ - return ROS2C_RETURN_OK; -} - -components_ret_t Actuator::recover() -{ - return ROS2C_RETURN_OK; -} - -components_ret_t Actuator::start() -{ - return ROS2C_RETURN_OK; -} - -components_ret_t Actuator::stop() -{ - return ROS2C_RETURN_OK; -} - -components_ret_t Actuator::read() -{ - components_ret_t ret = ROS2C_RETURN_OK; - if (!can_read_) { - ret = ROS2C_RETURN_ACTUATOR_CAN_NOT_READ; - } - return ret; -} - -components_ret_t Actuator::write() -{ - return ROS2C_RETURN_OK; -} - -components_ret_t Actuator::get_data(control_msgs::msg::InterfaceValue * data) -{ - // TODO: Add check is data are plausible - *data = data_; - return ROS2C_RETURN_OK; -} - -components_ret_t Actuator::set_data(control_msgs::msg::InterfaceValue * data, std::string claimer_id) -{ - components_ret_t ret = ROS2C_RETURN_OK; - if (!claimer_id_.compare(claimer_id)) { - data_ = *data; - } - else { - ret = ROS2C_RETURN_ACTUATOR_NON_CLAIMED_WRITE; - } - return ret; -} - -std::vector Actuator::get_interface_names() -{ - return interface_names_; -} - -components_ret_t Actuator::claim(const std::string claimer_id) -{ - components_ret_t ret = ROS2C_RETURN_OK; - if (claimer_id_.empty()) { - claimer_id_ = claimer_id; - } - else { - ret = ROS2C_RETURN_ACTUATOR_ALREADY_CLAIMED; - } - return ret; - -} - -components_ret_t Actuator::unclaim(const std::string claimer_id) -{ - components_ret_t ret = ROS2C_RETURN_OK; - if (claimer_id_.empty()) { - ret = ROS2C_RETURN_ACTUATOR_NOT_CLAIMED; - } - else if (!claimer_id_.compare(claimer_id)) { - claimer_id_ = ""; - } - else { - ret = ROS2C_RETURN_ACTUATOR_UNATHORIZED_UNCLAIM; - } - return ret; -} - -bool Actuator::isClaimed() -{ - return claimer_id_.empty(); -} - -bool Actuator::canRead() -{ - return can_read_; -} - -} // namespace robot_control_components diff --git a/robot_control_components/src/effort_actuator.cpp b/robot_control_components/src/effort_actuator.cpp new file mode 100644 index 0000000000..1c0e524730 --- /dev/null +++ b/robot_control_components/src/effort_actuator.cpp @@ -0,0 +1,76 @@ +// 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 "hardware_interface/component_interfaces/actuator_interface.hpp" + +namespace robot_control_components +{ + +using hardware_interface::hardware_interface_ret_t; +using hardware_interface::HW_RET_OK; +using hardware_interface::ComponentInfo; + +class EffortActuator : public hardware_interface::ActuatorInterface +{ +public: + EffortActuator() = default; + + ~EffortActuator() = default; + + hardware_interface_ret_t configure(const ComponentInfo & actuator_info) + { + (void) actuator_info; + return hardware_interface::HW_RET_OK; + } + + std::string get_interface_name() const + { + return ""; + } + + hardware_interface_ret_t start() + { + return HW_RET_OK; + } + + hardware_interface_ret_t stop() + { + return HW_RET_OK; + } + + bool is_started() const + { + return false; + } + + hardware_interface_ret_t read(double & data) + { + (void) data; + return HW_RET_OK; + } + + hardware_interface_ret_t write(const double & data) + { + (void) data; + return HW_RET_OK; + } +}; + +} // namespace robot_control_components + +#include "pluginlib/class_list_macros.hpp" +PLUGINLIB_EXPORT_CLASS( + robot_control_components::EffortActuator, hardware_interface::ActuatorInterface) diff --git a/robot_control_components/src/impl/effort_actuator.cpp b/robot_control_components/src/impl/effort_actuator.cpp deleted file mode 100644 index 0b2a9ba91a..0000000000 --- a/robot_control_components/src/impl/effort_actuator.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// 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 "robot_control_components/impl/effort_actuator.hpp" - -#include "pluginlib/class_list_macros.hpp" -PLUGINLIB_EXPORT_CLASS( - robot_control_components_actuators::EffortActuator, robot_control_components::Actuator) - diff --git a/robot_control_components/src/impl/position_actuator.cpp b/robot_control_components/src/impl/position_actuator.cpp deleted file mode 100644 index 65aab5bc25..0000000000 --- a/robot_control_components/src/impl/position_actuator.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// 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 "robot_control_components/impl/position_actuator.hpp" - -#include "pluginlib/class_list_macros.hpp" -PLUGINLIB_EXPORT_CLASS( - robot_control_components_actuators::PositionActuator, robot_control_components::Actuator) - diff --git a/robot_control_components/src/impl/position_sensor.cpp b/robot_control_components/src/impl/position_sensor.cpp deleted file mode 100644 index 0ae1bab320..0000000000 --- a/robot_control_components/src/impl/position_sensor.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// 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 "robot_control_components/impl/position_sensor.hpp" - -#include "pluginlib/class_list_macros.hpp" -PLUGINLIB_EXPORT_CLASS( - robot_control_components_sensors::PositionSensor, robot_control_components::Sensor) - diff --git a/robot_control_components/src/impl/velocity_actuator.cpp b/robot_control_components/src/impl/velocity_actuator.cpp deleted file mode 100644 index ea5fbd926c..0000000000 --- a/robot_control_components/src/impl/velocity_actuator.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// 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 "robot_control_components/impl/velocity_actuator.hpp" - -#include "pluginlib/class_list_macros.hpp" -PLUGINLIB_EXPORT_CLASS( - robot_control_components_actuators::VelocityActuator, robot_control_components::Actuator) - diff --git a/robot_control_components/src/impl/velocity_sensor.cpp b/robot_control_components/src/impl/velocity_sensor.cpp deleted file mode 100644 index 636ad34133..0000000000 --- a/robot_control_components/src/impl/velocity_sensor.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// 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 "robot_control_components/impl/velocity_sensor.hpp" - -#include "pluginlib/class_list_macros.hpp" -PLUGINLIB_EXPORT_CLASS( - robot_control_components_sensors::VelocitySensor, robot_control_components::Sensor) - diff --git a/robot_control_components/src/position_actuator.cpp b/robot_control_components/src/position_actuator.cpp new file mode 100644 index 0000000000..a2cd93988d --- /dev/null +++ b/robot_control_components/src/position_actuator.cpp @@ -0,0 +1,76 @@ +// 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 "hardware_interface/component_interfaces/actuator_interface.hpp" + +namespace robot_control_components +{ + +using hardware_interface::hardware_interface_ret_t; +using hardware_interface::HW_RET_OK; +using hardware_interface::ComponentInfo; + +class PositionActuator : public hardware_interface::ActuatorInterface +{ +public: + PositionActuator() = default; + + ~PositionActuator() = default; + + hardware_interface_ret_t configure(const ComponentInfo & actuator_info) + { + (void) actuator_info; + return hardware_interface::HW_RET_OK; + } + + std::string get_interface_name() const + { + return ""; + } + + hardware_interface_ret_t start() + { + return HW_RET_OK; + } + + hardware_interface_ret_t stop() + { + return HW_RET_OK; + } + + bool is_started() const + { + return false; + } + + hardware_interface_ret_t read(double & data) + { + (void) data; + return HW_RET_OK; + } + + hardware_interface_ret_t write(const double & data) + { + (void) data; + return HW_RET_OK; + } +}; + +} // namespace robot_control_components + +#include "pluginlib/class_list_macros.hpp" +PLUGINLIB_EXPORT_CLASS( + robot_control_components::PositionActuator, hardware_interface::ActuatorInterface) diff --git a/robot_control_components/src/position_sensor.cpp b/robot_control_components/src/position_sensor.cpp new file mode 100644 index 0000000000..be8085137f --- /dev/null +++ b/robot_control_components/src/position_sensor.cpp @@ -0,0 +1,70 @@ +// 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 "hardware_interface/component_interfaces/sensor_interface.hpp" + +namespace robot_control_components +{ + +using hardware_interface::hardware_interface_ret_t; +using hardware_interface::HW_RET_OK; +using hardware_interface::ComponentInfo; + +class PositionSensor : public hardware_interface::SensorInterface +{ +public: + PositionSensor() = default; + + ~PositionSensor() = default; + + hardware_interface_ret_t configure(const ComponentInfo & sensor_info) + { + (void) sensor_info; + return HW_RET_OK; + } + + std::string get_interface_name() const + { + return ""; + } + + hardware_interface_ret_t start() + { + return HW_RET_OK; + } + + hardware_interface_ret_t stop() + { + return HW_RET_OK; + } + + bool is_started() const + { + return HW_RET_OK; + } + + hardware_interface_ret_t read(double & data) + { + (void) data; + return HW_RET_OK; + } +}; + +} // namespace robot_control_components + +#include "pluginlib/class_list_macros.hpp" +PLUGINLIB_EXPORT_CLASS( + robot_control_components::PositionSensor, hardware_interface::SensorInterface) diff --git a/robot_control_components/src/robot.cpp b/robot_control_components/src/robot.cpp deleted file mode 100644 index ea735a7598..0000000000 --- a/robot_control_components/src/robot.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// 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 "rclcpp/rclcpp.hpp" - -#include "robot_control_components/robot.hpp" -#include "robot_control_components/component_parser.hpp" - -namespace robot_control_components -{ - -components_ret_t Robot::configure(const std::string & urdf_string) -{ - //TODO: Add catch - try { - ComponentInfo robot_info = parse_robot_from_urdf(urdf_string); - } - catch (const std::runtime_error& e) { - RCLCPP_FATAL(rclcpp::get_logger("ros2_control_Robot"), "Error while parsing URDF: " + std::string(e.what())); - return ROS2C_RETURN_ERROR; - } - - - - return ROS2C_RETURN_OK; -} - -} // namespace robot_control_components diff --git a/robot_control_components/src/sensor.cpp b/robot_control_components/src/sensor.cpp deleted file mode 100644 index 1f7105b617..0000000000 --- a/robot_control_components/src/sensor.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// 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 "robot_control_components/sensor.hpp" - -namespace robot_control_components -{ - -components_ret_t Sensor::configure(ComponentInfo sensor_info) -{ - return ROS2C_RETURN_OK; -} - -components_ret_t Sensor::init() -{ - return ROS2C_RETURN_OK; -} - -components_ret_t Sensor::recover() -{ - return ROS2C_RETURN_OK; -} - -components_ret_t Sensor::start() -{ - return ROS2C_RETURN_OK; -} - -components_ret_t Sensor::stop() -{ - return ROS2C_RETURN_OK; -} - -components_ret_t Sensor::read() -{ - return ROS2C_RETURN_OK; -} - -components_ret_t Sensor::get_value(control_msgs::msg::InterfaceValue * data) -{ - // TODO: Add check is data are plausible - *data = data_; - return ROS2C_RETURN_OK; -} - -std::vector Sensor::get_interface_names() -{ - return interface_names_; -}; - -} // namespace robot_control_components diff --git a/robot_control_components/src/velocity_actuator.cpp b/robot_control_components/src/velocity_actuator.cpp new file mode 100644 index 0000000000..310439f3c8 --- /dev/null +++ b/robot_control_components/src/velocity_actuator.cpp @@ -0,0 +1,76 @@ +// 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 "hardware_interface/component_interfaces/actuator_interface.hpp" + +namespace robot_control_components +{ + +using hardware_interface::hardware_interface_ret_t; +using hardware_interface::HW_RET_OK; +using hardware_interface::ComponentInfo; + +class VelocityActuator : public hardware_interface::ActuatorInterface +{ +public: + VelocityActuator() = default; + + ~VelocityActuator() = default; + + hardware_interface_ret_t configure(const ComponentInfo & actuator_info) + { + (void) actuator_info; + return hardware_interface::HW_RET_OK; + } + + std::string get_interface_name() const + { + return ""; + } + + hardware_interface_ret_t start() + { + return HW_RET_OK; + } + + hardware_interface_ret_t stop() + { + return HW_RET_OK; + } + + bool is_started() const + { + return false; + } + + hardware_interface_ret_t read(double & data) + { + (void) data; + return HW_RET_OK; + } + + hardware_interface_ret_t write(const double & data) + { + (void) data; + return HW_RET_OK; + } +}; + +} // namespace robot_control_components + +#include "pluginlib/class_list_macros.hpp" +PLUGINLIB_EXPORT_CLASS( + robot_control_components::VelocityActuator, hardware_interface::ActuatorInterface) diff --git a/robot_control_components/src/velocity_sensor.cpp b/robot_control_components/src/velocity_sensor.cpp new file mode 100644 index 0000000000..d1bc475689 --- /dev/null +++ b/robot_control_components/src/velocity_sensor.cpp @@ -0,0 +1,70 @@ +// 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 "hardware_interface/component_interfaces/sensor_interface.hpp" + +namespace robot_control_components +{ + +using hardware_interface::hardware_interface_ret_t; +using hardware_interface::HW_RET_OK; +using hardware_interface::ComponentInfo; + +class VelocitySensor : public hardware_interface::SensorInterface +{ +public: + VelocitySensor() = default; + + ~VelocitySensor() = default; + + hardware_interface_ret_t configure(const ComponentInfo & sensor_info) + { + (void) sensor_info; + return HW_RET_OK; + } + + std::string get_interface_name() const + { + return ""; + } + + hardware_interface_ret_t start() + { + return HW_RET_OK; + } + + hardware_interface_ret_t stop() + { + return HW_RET_OK; + } + + bool is_started() const + { + return HW_RET_OK; + } + + hardware_interface_ret_t read(double & data) + { + (void) data; + return HW_RET_OK; + } +}; + +} // namespace robot_control_components + +#include "pluginlib/class_list_macros.hpp" +PLUGINLIB_EXPORT_CLASS( + robot_control_components::VelocitySensor, hardware_interface::SensorInterface)