Skip to content

Commit 687b2a3

Browse files
committed
first version of transmissions for mock hardware
1 parent 01ed772 commit 687b2a3

File tree

9 files changed

+324
-59
lines changed

9 files changed

+324
-59
lines changed

hardware_interface/CMakeLists.txt

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,6 @@ ament_target_dependencies(hardware_interface PUBLIC ${THIS_PACKAGE_INCLUDE_DEPEN
3939
# which is appropriate when building the dll but not consuming it.
4040
target_compile_definitions(hardware_interface PRIVATE "HARDWARE_INTERFACE_BUILDING_DLL")
4141

42-
add_library(mock_components SHARED
43-
src/mock_components/generic_system.cpp
44-
)
45-
target_compile_features(mock_components PUBLIC cxx_std_17)
46-
target_include_directories(mock_components PUBLIC
47-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
48-
$<INSTALL_INTERFACE:include/hardware_interface>
49-
)
50-
ament_target_dependencies(mock_components PUBLIC ${THIS_PACKAGE_INCLUDE_DEPENDS})
51-
# Causes the visibility macros to use dllexport rather than dllimport,
52-
# which is appropriate when building the dll but not consuming it.
53-
target_compile_definitions(mock_components PRIVATE "HARDWARE_INTERFACE_BUILDING_DLL")
54-
55-
pluginlib_export_plugin_description_file(
56-
hardware_interface mock_components_plugin_description.xml)
57-
5842
if(BUILD_TESTING)
5943

6044
find_package(ament_cmake_gmock REQUIRED)
@@ -94,14 +78,6 @@ if(BUILD_TESTING)
9478
pluginlib_export_plugin_description_file(
9579
hardware_interface test/test_hardware_components/test_hardware_components.xml
9680
)
97-
98-
ament_add_gmock(test_generic_system test/mock_components/test_generic_system.cpp)
99-
target_include_directories(test_generic_system PRIVATE include)
100-
target_link_libraries(test_generic_system hardware_interface)
101-
ament_target_dependencies(test_generic_system
102-
pluginlib
103-
ros2_control_test_assets
104-
)
10581
endif()
10682

10783
install(
@@ -110,7 +86,6 @@ install(
11086
)
11187
install(
11288
TARGETS
113-
mock_components
11489
hardware_interface
11590
EXPORT export_hardware_interface
11691
RUNTIME DESTINATION bin

mock_hardware/CMakeLists.txt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(mock_hardware LANGUAGES CXX)
3+
4+
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
5+
add_compile_options(-Wall -Wextra -Werror=conversion -Werror=unused-but-set-variable -Werror=return-type -Werror=shadow)
6+
endif()
7+
8+
set(THIS_PACKAGE_INCLUDE_DEPENDS
9+
hardware_interface
10+
pluginlib
11+
rclcpp_lifecycle
12+
rcpputils
13+
rcutils
14+
transmission_interface
15+
)
16+
17+
find_package(ament_cmake REQUIRED)
18+
foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
19+
find_package(${Dependency} REQUIRED)
20+
endforeach()
21+
22+
add_library(mock_components SHARED
23+
src/generic_system.cpp
24+
)
25+
target_compile_features(mock_components PUBLIC cxx_std_17)
26+
target_include_directories(mock_components PUBLIC
27+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
28+
$<INSTALL_INTERFACE:include/mock_components>
29+
)
30+
ament_target_dependencies(mock_components PUBLIC ${THIS_PACKAGE_INCLUDE_DEPENDS})
31+
# Causes the visibility macros to use dllexport rather than dllimport,
32+
# which is appropriate when building the dll but not consuming it.
33+
target_compile_definitions(mock_components PRIVATE "MOCK_COMPONENTS_BUILDING_DLL")
34+
35+
pluginlib_export_plugin_description_file(
36+
hardware_interface mock_components_plugin_description.xml)
37+
38+
if(BUILD_TESTING)
39+
40+
find_package(ament_cmake_gmock REQUIRED)
41+
find_package(ros2_control_test_assets REQUIRED)
42+
43+
ament_add_gmock(test_generic_system test/test_generic_system.cpp)
44+
target_include_directories(test_generic_system PRIVATE include)
45+
target_link_libraries(test_generic_system mock_components)
46+
ament_target_dependencies(test_generic_system
47+
pluginlib
48+
ros2_control_test_assets
49+
)
50+
endif()
51+
52+
install(
53+
DIRECTORY include/
54+
DESTINATION include/mock_components
55+
)
56+
install(
57+
TARGETS
58+
mock_components
59+
EXPORT export_mock_components
60+
RUNTIME DESTINATION bin
61+
ARCHIVE DESTINATION lib
62+
LIBRARY DESTINATION lib
63+
)
64+
65+
ament_export_targets(export_mock_components HAS_LIBRARY_TARGET)
66+
ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})
67+
ament_package()
File renamed without changes.

hardware_interface/include/mock_components/generic_system.hpp renamed to mock_hardware/include/mock_components/generic_system.hpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef MOCK_COMPONENTS__GENERIC_SYSTEM_HPP_
1818
#define MOCK_COMPONENTS__GENERIC_SYSTEM_HPP_
1919

20+
#include <memory>
2021
#include <string>
2122
#include <vector>
2223

@@ -25,6 +26,7 @@
2526
#include "hardware_interface/system_interface.hpp"
2627
#include "hardware_interface/types/hardware_interface_return_values.hpp"
2728
#include "hardware_interface/types/hardware_interface_type_values.hpp"
29+
#include "transmission_interface/transmission.hpp"
2830

2931
using hardware_interface::return_type;
3032

@@ -55,10 +57,7 @@ class HARDWARE_INTERFACE_PUBLIC GenericSystem : public hardware_interface::Syste
5557

5658
return_type read(const rclcpp::Time & time, const rclcpp::Duration & period) override;
5759

58-
return_type write(const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/) override
59-
{
60-
return return_type::OK;
61-
}
60+
return_type write(const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/) override;
6261

6362
protected:
6463
/// Use standard interfaces for joints because they are relevant for dynamic behavior
@@ -100,6 +99,37 @@ class HARDWARE_INTERFACE_PUBLIC GenericSystem : public hardware_interface::Syste
10099
std::vector<std::vector<double>> gpio_commands_;
101100
std::vector<std::vector<double>> gpio_states_;
102101

102+
double actuator_slowdown_;
103+
104+
// used for the Transmission pass through.
105+
// read: actuator_interface.state_->Transmission->joint_interface.state_
106+
// write: joint_interface.command_->Transmission->actuator_interface.command_
107+
// And StateInterface(joint_interface.state_)
108+
struct InterfaceData
109+
{
110+
// TODO(Manuel) set initial to NaN and on_init initialize to given value in info or 0.0
111+
explicit InterfaceData(const std::string & name)
112+
: name_(name),
113+
command_(0.0), // command_(std::numeric_limits<double>::quiet_NaN()),
114+
state_(0.0), // state_(std::numeric_limits<double>::quiet_NaN()),
115+
transmission_passthrough_(
116+
0.0) // transmission_passthrough_(std::numeric_limits<double>::quiet_NaN())
117+
{
118+
}
119+
120+
std::string name_;
121+
double command_;
122+
double state_;
123+
// this is the "sink" that will be part of the transmission Joint/Actuator handles
124+
double transmission_passthrough_;
125+
};
126+
127+
std::vector<InterfaceData> joint_interfaces_;
128+
std::vector<InterfaceData> actuator_interfaces_;
129+
130+
// transmissions
131+
std::vector<std::shared_ptr<transmission_interface::Transmission>> transmissions_;
132+
103133
private:
104134
template <typename HandleType>
105135
bool get_interface(

mock_hardware/package.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0"?>
2+
<package format="2">
3+
<name>mock_hardware</name>
4+
<version>4.3.0</version>
5+
<description>ros2_control hardware interface</description>
6+
<maintainer email="[email protected]">Bence Magyar</maintainer>
7+
<maintainer email="[email protected]">Denis Štogl</maintainer>
8+
<license>Apache License 2.0</license>
9+
10+
<buildtool_depend>ament_cmake</buildtool_depend>
11+
12+
<depend>hardware_interface</depend>
13+
<depend>rclcpp_lifecycle</depend>
14+
<depend>pluginlib</depend>
15+
<depend>rcpputils</depend>
16+
<depend>transmission_interface</depend>
17+
18+
<build_depend>rcutils</build_depend>
19+
<exec_depend>rcutils</exec_depend>
20+
21+
<test_depend>ament_cmake_gmock</test_depend>
22+
<test_depend>ros2_control_test_assets</test_depend>
23+
24+
<export>
25+
<build_type>ament_cmake</build_type>
26+
</export>
27+
</package>

0 commit comments

Comments
 (0)