Skip to content
Merged
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
38 changes: 29 additions & 9 deletions hardware_interface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ endif()
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rcpputils REQUIRED)
find_package(robot_control_components REQUIRED)
find_package(tinyxml2_vendor REQUIRED)
find_package(TinyXML2 REQUIRED)

add_library(
hardware_interface
Expand All @@ -26,26 +27,38 @@ add_library(
target_include_directories(
hardware_interface
PUBLIC
include)
include
)
ament_target_dependencies(
hardware_interface
rclcpp
rcpputils
robot_control_components
)

# 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
src/utils/component_parser.cpp
)
target_include_directories(
component_parser
PUBLIC
include
)
ament_target_dependencies(
component_parser
TinyXML2
)

install(
DIRECTORY include/
DESTINATION include
)

install(
TARGETS
hardware_interface
TARGETS hardware_interface component_parser
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
Expand All @@ -54,17 +67,24 @@ if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()

ament_add_gtest(test_macros test/test_macros.cpp)
ament_add_gmock(test_macros test/test_macros.cpp)
target_include_directories(test_macros PRIVATE include)
ament_target_dependencies(test_macros rcpputils)

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)
endif()

ament_export_dependencies(
robot_control_components
rclcpp
rcpputils
)
ament_export_include_directories(
include
)
ament_export_libraries(
hardware_interface)
hardware_interface
component_parser
)
ament_package()
87 changes: 87 additions & 0 deletions hardware_interface/include/hardware_interface/actuator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2020 ROS2-Control Development Team
//
// 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__ACTUATOR_HPP_
#define HARDWARE_INTERFACE__ACTUATOR_HPP_

#include <algorithm>
#include <memory>
#include <string>
#include <utility>

#include "hardware_interface/component_info.hpp"
#include "hardware_interface/component_interfaces/actuator_interface.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "hardware_interface/visibility_control.h"

namespace hardware_interface
{

class Actuator final
Comment thread
destogl marked this conversation as resolved.
{
public:
explicit Actuator(std::unique_ptr<ActuatorInterface> impl)
: impl_(std::move(impl))
{}

~Actuator() = default;

HARDWARE_INTERFACE_PUBLIC
hardware_interface_ret_t configure(const ComponentInfo & actuator_info)
{
return impl_->configure(actuator_info);
}

HARDWARE_INTERFACE_PUBLIC
hardware_interface_ret_t start()
{
return impl_->start();
}

HARDWARE_INTERFACE_PUBLIC
hardware_interface_ret_t stop()
{
return impl_->stop();
}

HARDWARE_INTERFACE_PUBLIC
bool is_started() const
{
return impl_->is_started();
}

HARDWARE_INTERFACE_PUBLIC
hardware_interface_ret_t read(double & data)
{
return impl_->read(data);
}

HARDWARE_INTERFACE_PUBLIC
hardware_interface_ret_t write(const double & data)
{
return impl_->write(data);
}

HARDWARE_INTERFACE_PUBLIC
std::string get_interface_name() const
{
return impl_->get_interface_name();
}

Comment thread
destogl marked this conversation as resolved.
private:
std::unique_ptr<ActuatorInterface> impl_;
};

} // namespace hardware_interface
#endif // HARDWARE_INTERFACE__ACTUATOR_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
// limitations under the License.


#ifndef ROBOT_CONTROL_COMPONENTS__COMPONENT_INFO_HPP_
#define ROBOT_CONTROL_COMPONENTS__COMPONENT_INFO_HPP_
#ifndef HARDWARE_INTERFACE__COMPONENT_INFO_HPP_
#define HARDWARE_INTERFACE__COMPONENT_INFO_HPP_

#include <map>
#include <string>
#include <vector>

#include "robot_control_components/visibility_control.h"

namespace robot_control_components
namespace hardware_interface
{

struct ComponentInfo
Expand All @@ -39,6 +37,6 @@ struct ComponentInfo
std::map<std::string, std::string> hardware_parameters;
};

} // namespace robot_control_components
} // namespace hardware_interface

#endif // ROBOT_CONTROL_COMPONENTS__COMPONENT_INFO_HPP_
#endif // HARDWARE_INTERFACE__COMPONENT_INFO_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2020 ROS2-Control Development Team
//
// 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__COMPONENT_INTERFACES__ACTUATOR_INTERFACE_HPP_
#define HARDWARE_INTERFACE__COMPONENT_INTERFACES__ACTUATOR_INTERFACE_HPP_

#include <algorithm>
#include <array>
#include <string>
#include <vector>

#include "hardware_interface/component_info.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
Comment thread
Karsten1987 marked this conversation as resolved.
#include "hardware_interface/visibility_control.h"

namespace hardware_interface
{

class ActuatorInterface
Comment thread
destogl marked this conversation as resolved.
{
public:
HARDWARE_INTERFACE_PUBLIC
ActuatorInterface() = default;

HARDWARE_INTERFACE_PUBLIC
virtual
~ActuatorInterface() = default;

HARDWARE_INTERFACE_PUBLIC
virtual
hardware_interface_ret_t configure(const ComponentInfo & actuator_info) = 0;

HARDWARE_INTERFACE_PUBLIC
virtual
std::string get_interface_name() const = 0;

HARDWARE_INTERFACE_PUBLIC
virtual
hardware_interface_ret_t start() = 0;

HARDWARE_INTERFACE_PUBLIC
virtual
hardware_interface_ret_t stop() = 0;

HARDWARE_INTERFACE_PUBLIC
virtual
bool is_started() const = 0;

HARDWARE_INTERFACE_PUBLIC
virtual
hardware_interface_ret_t read(double & data) = 0;

HARDWARE_INTERFACE_PUBLIC
virtual
hardware_interface_ret_t write(const double & data) = 0;
};

} // namespace hardware_interface
#endif // HARDWARE_INTERFACE__COMPONENT_INTERFACES__ACTUATOR_INTERFACE_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2020 ROS2-Control Development Team
//
// 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__COMPONENT_INTERFACES__SENSOR_INTERFACE_HPP_
#define HARDWARE_INTERFACE__COMPONENT_INTERFACES__SENSOR_INTERFACE_HPP_

#include <string>

#include "hardware_interface/component_info.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "hardware_interface/visibility_control.h"

namespace hardware_interface
{

class SensorInterface
Comment thread
destogl marked this conversation as resolved.
{
public:
HARDWARE_INTERFACE_PUBLIC
SensorInterface() = default;

HARDWARE_INTERFACE_PUBLIC
virtual
~SensorInterface() = default;

HARDWARE_INTERFACE_PUBLIC
virtual
hardware_interface_ret_t configure(const ComponentInfo & sensor_info) = 0;

HARDWARE_INTERFACE_PUBLIC
virtual
std::string get_interface_name() const = 0;

HARDWARE_INTERFACE_PUBLIC
virtual
hardware_interface_ret_t start() = 0;

HARDWARE_INTERFACE_PUBLIC
virtual
hardware_interface_ret_t stop() = 0;

HARDWARE_INTERFACE_PUBLIC
virtual
bool is_started() const = 0;

HARDWARE_INTERFACE_PUBLIC
virtual
hardware_interface_ret_t read(double & data) = 0;
};

} // namespace hardware_interface
#endif // HARDWARE_INTERFACE__COMPONENT_INTERFACES__SENSOR_INTERFACE_HPP_
Loading