Skip to content

Commit

Permalink
resource loaning (ros-controls#224)
Browse files Browse the repository at this point in the history
* introducing handles

Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com>

* component interfaces & tests

Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com>

* linters

Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com>

* import resource manager

Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com>

* correct year

Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com>

* import handles from loaded components

Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com>

* wip / debug

Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com>

* parse components

Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com>

* changes after rebase

Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com>

* component parser as shared library

Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com>

* validate urdf configuratin

Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com>

* documentation

Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com>

* remove default constructor

Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com>

* resource loaning

Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com>

* loan state interface

Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com>

* import externally declared components

Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com>

* move resource manager to hardware interface (ros-controls#226)

* move resource manager to hardware interface

Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com>

* include functional for std::function

Co-authored-by: Bence Magyar <bence.magyar.robotics@gmail.com>

* address review comments

Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com>

Co-authored-by: Bence Magyar <bence.magyar.robotics@gmail.com>
  • Loading branch information
Karsten1987 and bmagyar committed Nov 11, 2020
1 parent 04e6531 commit 993db54
Show file tree
Hide file tree
Showing 14 changed files with 608 additions and 186 deletions.
21 changes: 0 additions & 21 deletions controller_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ find_package(rclcpp REQUIRED)

add_library(controller_manager SHARED
src/controller_manager.cpp
src/resource_manager.cpp
)
target_include_directories(controller_manager PRIVATE include)
ament_target_dependencies(controller_manager
Expand Down Expand Up @@ -106,26 +105,6 @@ if(BUILD_TESTING)
test_controller_manager_srvs
test_robot_hardware
)

add_library(test_components SHARED
test/test_components/test_actuator.cpp
test/test_components/test_sensor.cpp
test/test_components/test_system.cpp)
ament_target_dependencies(test_components
hardware_interface
pluginlib)
install(TARGETS test_components
DESTINATION lib
)
pluginlib_export_plugin_description_file(
hardware_interface test/test_components/test_components.xml)

ament_add_gmock(
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(
Expand Down
101 changes: 0 additions & 101 deletions controller_manager/src/resource_manager.hpp

This file was deleted.

51 changes: 27 additions & 24 deletions hardware_interface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ endif()

find_package(ament_cmake REQUIRED)
find_package(control_msgs REQUIRED)
find_package(pluginlib REQUIRED)
find_package(rcpputils REQUIRED)
find_package(rcutils REQUIRED)
find_package(tinyxml2_vendor REQUIRED)
Expand All @@ -23,7 +24,9 @@ add_library(
src/components/actuator.cpp
src/components/sensor.cpp
src/components/system.cpp
src/component_parser.cpp
src/operation_mode_handle.cpp
src/resource_manager.cpp
src/robot_hardware.cpp
)
target_include_directories(
Expand All @@ -34,27 +37,15 @@ target_include_directories(
ament_target_dependencies(
hardware_interface
control_msgs
pluginlib
rcutils
rcpputils
)
# 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 SHARED
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")
# prevent pluginlib from using boost
target_compile_definitions(hardware_interface PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")

install(
DIRECTORY include/
Expand All @@ -63,7 +54,6 @@ install(

install(
TARGETS
component_parser
hardware_interface
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
Expand All @@ -80,46 +70,59 @@ if(BUILD_TESTING)
ament_target_dependencies(test_macros rcpputils)

ament_add_gmock(test_robot_hardware_interfaces test/test_robot_hardware_interface.cpp)
target_include_directories(test_robot_hardware_interfaces PRIVATE include)
target_link_libraries(test_robot_hardware_interfaces hardware_interface)

ament_add_gmock(test_register_actuators test/test_register_actuators.cpp)
target_include_directories(test_register_actuators PRIVATE include)
target_link_libraries(test_register_actuators hardware_interface)
ament_target_dependencies(test_register_actuators rcpputils)

ament_add_gmock(test_register_joints test/test_register_joints.cpp)
target_include_directories(test_register_joints PRIVATE include)
target_link_libraries(test_register_joints hardware_interface)
ament_target_dependencies(test_register_joints rcpputils)

ament_add_gmock(test_actuator_handle test/test_actuator_handle.cpp)
target_include_directories(test_actuator_handle PRIVATE include)
target_link_libraries(test_actuator_handle hardware_interface)
ament_target_dependencies(test_actuator_handle rcpputils)

ament_add_gmock(test_joint_handle test/test_joint_handle.cpp)
target_include_directories(test_joint_handle PRIVATE include)
target_link_libraries(test_joint_handle hardware_interface)
ament_target_dependencies(test_joint_handle rcpputils)

ament_add_gmock(test_component_interfaces test/test_component_interfaces.cpp)
target_link_libraries(test_component_interfaces 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 hardware_interface)

add_library(test_components SHARED
test/test_components/test_actuator.cpp
test/test_components/test_sensor.cpp
test/test_components/test_system.cpp)
target_link_libraries(test_components hardware_interface)
ament_target_dependencies(test_components
pluginlib)
install(TARGETS test_components
DESTINATION lib
)
pluginlib_export_plugin_description_file(
hardware_interface test/test_components/test_components.xml)

ament_add_gmock(
test_resource_manager
test/test_resource_manager.cpp
)
target_link_libraries(test_resource_manager hardware_interface)
endif()

ament_export_include_directories(
include
)
ament_export_libraries(
component_parser
hardware_interface
)
ament_export_dependencies(
control_msgs
pluginlib
rcpputils
tinyxml2_vendor
TinyXML2
Expand Down
8 changes: 7 additions & 1 deletion hardware_interface/include/hardware_interface/handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class ReadWriteHandle : public ReadOnlyHandle<HandleType>
class StateInterface : public ReadOnlyHandle<StateInterface>
{
public:
StateInterface(const StateInterface & other) = delete;
StateInterface(const StateInterface & other) = default;

StateInterface(StateInterface && other) = default;

Expand All @@ -149,6 +149,12 @@ class StateInterface : public ReadOnlyHandle<StateInterface>
class CommandInterface : public ReadWriteHandle<CommandInterface>
{
public:
/// CommandInterface copy constructor is actively deleted
/**
* Command interfaces are having a unique ownership and thus
* can't be copied in order to avoid simultaneous writes to
* the same resource.
*/
CommandInterface(const CommandInterface & other) = delete;

CommandInterface(CommandInterface && other) = default;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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 HARDWARE_INTERFACE__LOANED_COMMAND_INTERFACE_HPP_
#define HARDWARE_INTERFACE__LOANED_COMMAND_INTERFACE_HPP_

#include <functional>
#include <utility>

#include "hardware_interface/handle.hpp"

namespace hardware_interface
{

class LoanedCommandInterface
{
public:
using Deleter = std::function<void (void)>;

explicit LoanedCommandInterface(CommandInterface & command_interface)
: LoanedCommandInterface(command_interface, nullptr)
{}

LoanedCommandInterface(
CommandInterface & command_interface,
Deleter && deleter)
: command_interface_(command_interface),
deleter_(std::forward<Deleter>(deleter))
{}

LoanedCommandInterface(const LoanedCommandInterface & other) = delete;

LoanedCommandInterface(LoanedCommandInterface && other) = default;

virtual ~LoanedCommandInterface()
{
if (deleter_) {
deleter_();
}
}

void set_value(double val)
{
command_interface_.set_value(val);
}

double get_value() const
{
return command_interface_.get_value();
}

protected:
CommandInterface & command_interface_;
Deleter deleter_;
};

} // namespace hardware_interface
#endif // HARDWARE_INTERFACE__LOANED_COMMAND_INTERFACE_HPP_
Loading

0 comments on commit 993db54

Please sign in to comment.