Skip to content

Commit 993db54

Browse files
Karsten1987bmagyar
andauthored
resource loaning (#224)
* introducing handles Signed-off-by: Karsten Knese <[email protected]> * component interfaces & tests Signed-off-by: Karsten Knese <[email protected]> * linters Signed-off-by: Karsten Knese <[email protected]> * import resource manager Signed-off-by: Karsten Knese <[email protected]> * correct year Signed-off-by: Karsten Knese <[email protected]> * import handles from loaded components Signed-off-by: Karsten Knese <[email protected]> * wip / debug Signed-off-by: Karsten Knese <[email protected]> * parse components Signed-off-by: Karsten Knese <[email protected]> * changes after rebase Signed-off-by: Karsten Knese <[email protected]> * component parser as shared library Signed-off-by: Karsten Knese <[email protected]> * validate urdf configuratin Signed-off-by: Karsten Knese <[email protected]> * documentation Signed-off-by: Karsten Knese <[email protected]> * remove default constructor Signed-off-by: Karsten Knese <[email protected]> * resource loaning Signed-off-by: Karsten Knese <[email protected]> * loan state interface Signed-off-by: Karsten Knese <[email protected]> * import externally declared components Signed-off-by: Karsten Knese <[email protected]> * move resource manager to hardware interface (#226) * move resource manager to hardware interface Signed-off-by: Karsten Knese <[email protected]> * include functional for std::function Co-authored-by: Bence Magyar <[email protected]> * address review comments Signed-off-by: Karsten Knese <[email protected]> Co-authored-by: Bence Magyar <[email protected]>
1 parent 04e6531 commit 993db54

File tree

14 files changed

+608
-186
lines changed

14 files changed

+608
-186
lines changed

controller_manager/CMakeLists.txt

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ find_package(rclcpp REQUIRED)
2121

2222
add_library(controller_manager SHARED
2323
src/controller_manager.cpp
24-
src/resource_manager.cpp
2524
)
2625
target_include_directories(controller_manager PRIVATE include)
2726
ament_target_dependencies(controller_manager
@@ -106,26 +105,6 @@ if(BUILD_TESTING)
106105
test_controller_manager_srvs
107106
test_robot_hardware
108107
)
109-
110-
add_library(test_components SHARED
111-
test/test_components/test_actuator.cpp
112-
test/test_components/test_sensor.cpp
113-
test/test_components/test_system.cpp)
114-
ament_target_dependencies(test_components
115-
hardware_interface
116-
pluginlib)
117-
install(TARGETS test_components
118-
DESTINATION lib
119-
)
120-
pluginlib_export_plugin_description_file(
121-
hardware_interface test/test_components/test_components.xml)
122-
123-
ament_add_gmock(
124-
test_resource_manager
125-
test/test_resource_manager.cpp
126-
)
127-
target_include_directories(test_resource_manager PRIVATE include src)
128-
target_link_libraries(test_resource_manager controller_manager)
129108
endif()
130109

131110
ament_export_libraries(

controller_manager/src/resource_manager.hpp

Lines changed: 0 additions & 101 deletions
This file was deleted.

hardware_interface/CMakeLists.txt

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ endif()
1212

1313
find_package(ament_cmake REQUIRED)
1414
find_package(control_msgs REQUIRED)
15+
find_package(pluginlib REQUIRED)
1516
find_package(rcpputils REQUIRED)
1617
find_package(rcutils REQUIRED)
1718
find_package(tinyxml2_vendor REQUIRED)
@@ -23,7 +24,9 @@ add_library(
2324
src/components/actuator.cpp
2425
src/components/sensor.cpp
2526
src/components/system.cpp
27+
src/component_parser.cpp
2628
src/operation_mode_handle.cpp
29+
src/resource_manager.cpp
2730
src/robot_hardware.cpp
2831
)
2932
target_include_directories(
@@ -34,27 +37,15 @@ target_include_directories(
3437
ament_target_dependencies(
3538
hardware_interface
3639
control_msgs
40+
pluginlib
3741
rcutils
3842
rcpputils
3943
)
4044
# Causes the visibility macros to use dllexport rather than dllimport,
4145
# which is appropriate when building the dll but not consuming it.
4246
target_compile_definitions(hardware_interface PRIVATE "HARDWARE_INTERFACE_BUILDING_DLL")
43-
44-
add_library(
45-
component_parser SHARED
46-
src/component_parser.cpp
47-
)
48-
target_include_directories(
49-
component_parser
50-
PUBLIC
51-
include
52-
)
53-
ament_target_dependencies(
54-
component_parser
55-
TinyXML2
56-
)
57-
target_compile_definitions(component_parser PRIVATE "HARDWARE_INTERFACE_BUILDING_DLL")
47+
# prevent pluginlib from using boost
48+
target_compile_definitions(hardware_interface PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")
5849

5950
install(
6051
DIRECTORY include/
@@ -63,7 +54,6 @@ install(
6354

6455
install(
6556
TARGETS
66-
component_parser
6757
hardware_interface
6858
RUNTIME DESTINATION bin
6959
ARCHIVE DESTINATION lib
@@ -80,46 +70,59 @@ if(BUILD_TESTING)
8070
ament_target_dependencies(test_macros rcpputils)
8171

8272
ament_add_gmock(test_robot_hardware_interfaces test/test_robot_hardware_interface.cpp)
83-
target_include_directories(test_robot_hardware_interfaces PRIVATE include)
8473
target_link_libraries(test_robot_hardware_interfaces hardware_interface)
8574

8675
ament_add_gmock(test_register_actuators test/test_register_actuators.cpp)
87-
target_include_directories(test_register_actuators PRIVATE include)
8876
target_link_libraries(test_register_actuators hardware_interface)
8977
ament_target_dependencies(test_register_actuators rcpputils)
9078

9179
ament_add_gmock(test_register_joints test/test_register_joints.cpp)
92-
target_include_directories(test_register_joints PRIVATE include)
9380
target_link_libraries(test_register_joints hardware_interface)
9481
ament_target_dependencies(test_register_joints rcpputils)
9582

9683
ament_add_gmock(test_actuator_handle test/test_actuator_handle.cpp)
97-
target_include_directories(test_actuator_handle PRIVATE include)
9884
target_link_libraries(test_actuator_handle hardware_interface)
9985
ament_target_dependencies(test_actuator_handle rcpputils)
10086

10187
ament_add_gmock(test_joint_handle test/test_joint_handle.cpp)
102-
target_include_directories(test_joint_handle PRIVATE include)
10388
target_link_libraries(test_joint_handle hardware_interface)
10489
ament_target_dependencies(test_joint_handle rcpputils)
10590

10691
ament_add_gmock(test_component_interfaces test/test_component_interfaces.cpp)
10792
target_link_libraries(test_component_interfaces hardware_interface)
10893

10994
ament_add_gmock(test_component_parser test/test_component_parser.cpp)
110-
target_link_libraries(test_component_parser component_parser)
111-
ament_target_dependencies(test_component_parser TinyXML2)
95+
target_link_libraries(test_component_parser hardware_interface)
96+
97+
add_library(test_components SHARED
98+
test/test_components/test_actuator.cpp
99+
test/test_components/test_sensor.cpp
100+
test/test_components/test_system.cpp)
101+
target_link_libraries(test_components hardware_interface)
102+
ament_target_dependencies(test_components
103+
pluginlib)
104+
install(TARGETS test_components
105+
DESTINATION lib
106+
)
107+
pluginlib_export_plugin_description_file(
108+
hardware_interface test/test_components/test_components.xml)
109+
110+
ament_add_gmock(
111+
test_resource_manager
112+
test/test_resource_manager.cpp
113+
)
114+
target_link_libraries(test_resource_manager hardware_interface)
112115
endif()
113116

114117
ament_export_include_directories(
115118
include
116119
)
117120
ament_export_libraries(
118-
component_parser
119121
hardware_interface
120122
)
121123
ament_export_dependencies(
122124
control_msgs
125+
pluginlib
123126
rcpputils
124127
tinyxml2_vendor
125128
TinyXML2

hardware_interface/include/hardware_interface/handle.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class ReadWriteHandle : public ReadOnlyHandle<HandleType>
139139
class StateInterface : public ReadOnlyHandle<StateInterface>
140140
{
141141
public:
142-
StateInterface(const StateInterface & other) = delete;
142+
StateInterface(const StateInterface & other) = default;
143143

144144
StateInterface(StateInterface && other) = default;
145145

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

154160
CommandInterface(CommandInterface && other) = default;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2020 Open Source Robotics Foundation, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef HARDWARE_INTERFACE__LOANED_COMMAND_INTERFACE_HPP_
16+
#define HARDWARE_INTERFACE__LOANED_COMMAND_INTERFACE_HPP_
17+
18+
#include <functional>
19+
#include <utility>
20+
21+
#include "hardware_interface/handle.hpp"
22+
23+
namespace hardware_interface
24+
{
25+
26+
class LoanedCommandInterface
27+
{
28+
public:
29+
using Deleter = std::function<void (void)>;
30+
31+
explicit LoanedCommandInterface(CommandInterface & command_interface)
32+
: LoanedCommandInterface(command_interface, nullptr)
33+
{}
34+
35+
LoanedCommandInterface(
36+
CommandInterface & command_interface,
37+
Deleter && deleter)
38+
: command_interface_(command_interface),
39+
deleter_(std::forward<Deleter>(deleter))
40+
{}
41+
42+
LoanedCommandInterface(const LoanedCommandInterface & other) = delete;
43+
44+
LoanedCommandInterface(LoanedCommandInterface && other) = default;
45+
46+
virtual ~LoanedCommandInterface()
47+
{
48+
if (deleter_) {
49+
deleter_();
50+
}
51+
}
52+
53+
void set_value(double val)
54+
{
55+
command_interface_.set_value(val);
56+
}
57+
58+
double get_value() const
59+
{
60+
return command_interface_.get_value();
61+
}
62+
63+
protected:
64+
CommandInterface & command_interface_;
65+
Deleter deleter_;
66+
};
67+
68+
} // namespace hardware_interface
69+
#endif // HARDWARE_INTERFACE__LOANED_COMMAND_INTERFACE_HPP_

0 commit comments

Comments
 (0)