Skip to content

Commit

Permalink
first version of transmissions for mock hardware
Browse files Browse the repository at this point in the history
  • Loading branch information
mamueluth committed Feb 19, 2024
1 parent 01ed772 commit 687b2a3
Show file tree
Hide file tree
Showing 9 changed files with 324 additions and 59 deletions.
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,7 @@
#ifndef MOCK_COMPONENTS__GENERIC_SYSTEM_HPP_
#define MOCK_COMPONENTS__GENERIC_SYSTEM_HPP_

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

Expand All @@ -25,6 +26,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 +57,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 +99,37 @@ class HARDWARE_INTERFACE_PUBLIC GenericSystem : public hardware_interface::Syste
std::vector<std::vector<double>> gpio_commands_;
std::vector<std::vector<double>> gpio_states_;

double actuator_slowdown_;

// 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
{
// TODO(Manuel) set initial to NaN and on_init initialize to given value in info or 0.0
explicit InterfaceData(const std::string & name)
: name_(name),
command_(0.0), // command_(std::numeric_limits<double>::quiet_NaN()),
state_(0.0), // state_(std::numeric_limits<double>::quiet_NaN()),
transmission_passthrough_(
0.0) // 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_;

// 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

0 comments on commit 687b2a3

Please sign in to comment.