Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first version of transmissions for mock hardware #15

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ DerivePointerAlignment: false
PointerAlignment: Middle
ReflowComments: true
IncludeBlocks: Preserve
InsertBraces: true
...
25 changes: 0 additions & 25 deletions hardware_interface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,6 @@ ament_target_dependencies(hardware_interface PUBLIC ${THIS_PACKAGE_INCLUDE_DEPEN
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(hardware_interface PRIVATE "HARDWARE_INTERFACE_BUILDING_DLL")

add_library(mock_components SHARED
src/mock_components/generic_system.cpp
)
target_compile_features(mock_components PUBLIC cxx_std_17)
target_include_directories(mock_components PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/hardware_interface>
)
ament_target_dependencies(mock_components PUBLIC ${THIS_PACKAGE_INCLUDE_DEPENDS})
# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(mock_components PRIVATE "HARDWARE_INTERFACE_BUILDING_DLL")

pluginlib_export_plugin_description_file(
hardware_interface mock_components_plugin_description.xml)

if(BUILD_TESTING)

find_package(ament_cmake_gmock REQUIRED)
Expand Down Expand Up @@ -94,14 +78,6 @@ if(BUILD_TESTING)
pluginlib_export_plugin_description_file(
hardware_interface test/test_hardware_components/test_hardware_components.xml
)

ament_add_gmock(test_generic_system test/mock_components/test_generic_system.cpp)
target_include_directories(test_generic_system PRIVATE include)
target_link_libraries(test_generic_system hardware_interface)
ament_target_dependencies(test_generic_system
pluginlib
ros2_control_test_assets
)
endif()

install(
Expand All @@ -110,7 +86,6 @@ install(
)
install(
TARGETS
mock_components
hardware_interface
EXPORT export_hardware_interface
RUNTIME DESTINATION bin
Expand Down
67 changes: 67 additions & 0 deletions mock_hardware/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
cmake_minimum_required(VERSION 3.16)
project(mock_hardware LANGUAGES CXX)

if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
add_compile_options(-Wall -Wextra -Werror=conversion -Werror=unused-but-set-variable -Werror=return-type -Werror=shadow)
endif()

set(THIS_PACKAGE_INCLUDE_DEPENDS
hardware_interface
pluginlib
rclcpp_lifecycle
rcpputils
rcutils
transmission_interface
)

find_package(ament_cmake REQUIRED)
foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
find_package(${Dependency} REQUIRED)
endforeach()

add_library(mock_components SHARED
src/generic_system.cpp
)
target_compile_features(mock_components PUBLIC cxx_std_17)
target_include_directories(mock_components PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/mock_components>
)
ament_target_dependencies(mock_components PUBLIC ${THIS_PACKAGE_INCLUDE_DEPENDS})
# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(mock_components PRIVATE "MOCK_COMPONENTS_BUILDING_DLL")

pluginlib_export_plugin_description_file(
hardware_interface mock_components_plugin_description.xml)

if(BUILD_TESTING)

find_package(ament_cmake_gmock REQUIRED)
find_package(ros2_control_test_assets REQUIRED)

ament_add_gmock(test_generic_system test/test_generic_system.cpp)
target_include_directories(test_generic_system PRIVATE include)
target_link_libraries(test_generic_system mock_components)
ament_target_dependencies(test_generic_system
pluginlib
ros2_control_test_assets
)
endif()

install(
DIRECTORY include/
DESTINATION include/mock_components
)
install(
TARGETS
mock_components
EXPORT export_mock_components
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)

ament_export_targets(export_mock_components HAS_LIBRARY_TARGET)
ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})
ament_package()
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef MOCK_COMPONENTS__GENERIC_SYSTEM_HPP_
#define MOCK_COMPONENTS__GENERIC_SYSTEM_HPP_

#include <limits>
#include <memory>
#include <string>
#include <vector>

Expand All @@ -25,6 +27,7 @@
#include "hardware_interface/system_interface.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "hardware_interface/types/hardware_interface_type_values.hpp"
#include "transmission_interface/transmission.hpp"

using hardware_interface::return_type;

Expand Down Expand Up @@ -55,10 +58,7 @@ class HARDWARE_INTERFACE_PUBLIC GenericSystem : public hardware_interface::Syste

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

return_type write(const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/) override
{
return return_type::OK;
}
return_type write(const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/) override;

protected:
/// Use standard interfaces for joints because they are relevant for dynamic behavior
Expand Down Expand Up @@ -100,6 +100,33 @@ class HARDWARE_INTERFACE_PUBLIC GenericSystem : public hardware_interface::Syste
std::vector<std::vector<double>> gpio_commands_;
std::vector<std::vector<double>> gpio_states_;

// used for the Transmission pass through.
// read: actuator_interface.state_->Transmission->joint_interface.state_
// write: joint_interface.command_->Transmission->actuator_interface.command_
// And StateInterface(joint_interface.state_)
struct InterfaceData
{
explicit InterfaceData(const std::string & name)
: name_(name),
command_(std::numeric_limits<double>::quiet_NaN()),
state_(std::numeric_limits<double>::quiet_NaN()),
transmission_passthrough_(std::numeric_limits<double>::quiet_NaN())
{
}

std::string name_;
double command_;
double state_;
// this is the "sink" that will be part of the transmission Joint/Actuator handles
double transmission_passthrough_;
};

std::vector<InterfaceData> joint_interfaces_;
std::vector<InterfaceData> actuator_interfaces_;
mamueluth marked this conversation as resolved.
Show resolved Hide resolved

// transmissions
std::vector<std::shared_ptr<transmission_interface::Transmission>> transmissions_;

private:
template <typename HandleType>
bool get_interface(
Expand Down
27 changes: 27 additions & 0 deletions mock_hardware/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<package format="2">
<name>mock_hardware</name>
<version>4.3.0</version>
<description>ros2_control hardware interface</description>
<maintainer email="[email protected]">Bence Magyar</maintainer>
<maintainer email="[email protected]">Denis Štogl</maintainer>
<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<depend>hardware_interface</depend>
<depend>rclcpp_lifecycle</depend>
<depend>pluginlib</depend>
<depend>rcpputils</depend>
<depend>transmission_interface</depend>

<build_depend>rcutils</build_depend>
<exec_depend>rcutils</exec_depend>

<test_depend>ament_cmake_gmock</test_depend>
<test_depend>ros2_control_test_assets</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Loading
Loading