Skip to content

Commit

Permalink
Hardware component interfaces (ros-controls#121)
Browse files Browse the repository at this point in the history
* Initial version of new package implementing components for controlling the robot.
* Add control component interfaces.
* Added initial tests for Joint and  JointInterface
* Extended SensorInterface to work with hardware. Added Example for DummySensor and HW in tests. Added lifecycle management for components #10
* Remove component types since they are not used yet.
* Added tests for all interfaces and implemented review comments
* Added HardwareInfo as the main structure in the robot's URDF file
* Add Hardware and Component base classes and tests.
* Split Component and Hardware Infos into two files
* Use separated headers for components_info and hardware_info
* Style corrections
* Add documentation for joint and sensor components
* Update hardware_interface/test/test_component_interfaces.cpp
* Style corrections
* The base classes for Joints and Sensors are implemented
* Add more tests to get better coverage
* Updated after comments and added helper header
* Implementation moved to cpp files
* Removed virtual function for checking limits
* Use inline functions in helper header and make API-consistent return values
* move components into components folder
  • Loading branch information
destogl committed Aug 22, 2020
1 parent 6eee12b commit 3a1fad5
Show file tree
Hide file tree
Showing 23 changed files with 2,294 additions and 7 deletions.
37 changes: 33 additions & 4 deletions hardware_interface/CMakeLists.txt
Expand Up @@ -18,33 +18,52 @@ find_package(rcpputils REQUIRED)
add_library(
hardware_interface
SHARED
src/actuator_hardware.cpp
src/joint_command_handle.cpp
src/joint_state_handle.cpp
src/operation_mode_handle.cpp
src/robot_hardware.cpp
src/sensor_hardware.cpp
src/system_hardware.cpp
)
target_include_directories(
hardware_interface
PUBLIC
include)
include
)
ament_target_dependencies(
hardware_interface
control_msgs
rclcpp
rcpputils
)

# 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(
components
SHARED
src/components/joint.cpp
src/components/sensor.cpp
)
target_include_directories(
components
PUBLIC
include
)
# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(components PRIVATE "HARDWARE_INTERFACE_BUILDING_DLL")

install(
DIRECTORY include/
DESTINATION include
)

install(
TARGETS
components
hardware_interface
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
Expand Down Expand Up @@ -74,13 +93,23 @@ if(BUILD_TESTING)
target_link_libraries(test_actuator_handle hardware_interface)
ament_target_dependencies(test_actuator_handle rcpputils)

ament_add_gmock(test_component_interfaces test/test_component_interfaces.cpp)
target_include_directories(test_component_interfaces PRIVATE include)
target_link_libraries(test_component_interfaces components hardware_interface)
endif()

ament_export_include_directories(
include
)
ament_export_libraries(
hardware_interface)
components
hardware_interface
)
ament_export_dependencies(
control_msgs)
control_msgs
rclcpp
rcpputils
tinyxml2_vendor
TinyXML2
)
ament_package()
@@ -0,0 +1,60 @@
// 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_HARDWARE_HPP_
#define HARDWARE_INTERFACE__ACTUATOR_HARDWARE_HPP_

#include <memory>

#include "hardware_interface/hardware_info.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "hardware_interface/types/hardware_interface_status_values.hpp"
#include "hardware_interface/visibility_control.h"

namespace hardware_interface
{

namespace components
{
class Joint;
} // namespace components
class ActuatorHardwareInterface;

class ActuatorHardware final
{
public:
ActuatorHardware() = default;

explicit ActuatorHardware(std::unique_ptr<ActuatorHardwareInterface> impl);

~ActuatorHardware() = default;

return_type configure(const HardwareInfo & actuator_info);

return_type start();

return_type stop();

hardware_interface_status get_status() const;

return_type read_joint(std::shared_ptr<components::Joint> joint);

return_type write_joint(const std::shared_ptr<components::Joint> joint);

private:
std::unique_ptr<ActuatorHardwareInterface> impl_;
};

} // namespace hardware_interface
#endif // HARDWARE_INTERFACE__ACTUATOR_HARDWARE_HPP_
@@ -0,0 +1,105 @@
// 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_HARDWARE_INTERFACE_HPP_
#define HARDWARE_INTERFACE__ACTUATOR_HARDWARE_INTERFACE_HPP_

#include <memory>

#include "hardware_interface/components/joint.hpp"
#include "hardware_interface/hardware_info.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "hardware_interface/types/hardware_interface_status_values.hpp"
#include "hardware_interface/visibility_control.h"

namespace hardware_interface
{

/**
* \brief Virtual Class to implement when integrating a 1 DoF actuator into ros2_control.
* The typical examples are conveyors or motors.
*/
class ActuatorHardwareInterface
{
public:
HARDWARE_INTERFACE_PUBLIC
ActuatorHardwareInterface() = default;

HARDWARE_INTERFACE_PUBLIC
virtual
~ActuatorHardwareInterface() = default;

/**
* \brief Configuration of the actuator from data parsed from the robot's URDF.
*
* \param actuator_info structure with data from URDF.
* \return return_type::OK if required data are provided and can be parsed,
* return_type::ERROR otherwise.
*/
HARDWARE_INTERFACE_PUBLIC
virtual
return_type configure(const HardwareInfo & actuator_info) = 0;

/**
* \brief Start exchange data with the hardware.
*
* \return return_type:OK if everything worked as expected, return_type::ERROR otherwise.
*/
HARDWARE_INTERFACE_PUBLIC
virtual
return_type start() = 0;

/**
* \brief Stop exchange data with the hardware.
*
* \return return_type:OK if everything worked as expected, return_type::ERROR otherwise.
*/
HARDWARE_INTERFACE_PUBLIC
virtual
return_type stop() = 0;

/**
* \brief Get current state of the system hardware.
*
* \return hardware_interface_status current status.
*/
HARDWARE_INTERFACE_PUBLIC
virtual
hardware_interface_status get_status() const = 0;

/**
* \brief Read data fromt the hardware into the joint using "set_state" function of the Joint class.
* This function is always called by the resource manager.
*
* \param joint joint where data from the hardware are stored.
* \return return_type:OK if everything worked as expected, return_type::ERROR otherwise.
*/
HARDWARE_INTERFACE_PUBLIC
virtual
return_type read_joint(std::shared_ptr<components::Joint> joint) const = 0;

/**
* \brief Write data from the joint to the hardware using "get_command" function of the Joint class.
* This function is always called by the resource manager.
*
* \param joint the joint from which data are written to the hardware.
* \return return_type:OK if everything worked as expected, return_type::ERROR otherwise.
*/
HARDWARE_INTERFACE_PUBLIC
virtual
return_type write_joint(const std::shared_ptr<components::Joint> joint) = 0;
};

} // namespace hardware_interface
#endif // HARDWARE_INTERFACE__ACTUATOR_HARDWARE_INTERFACE_HPP_
@@ -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__COMPONENTS__COMPONENT_INFO_HPP_
#define HARDWARE_INTERFACE__COMPONENTS__COMPONENT_INFO_HPP_

#include <string>
#include <unordered_map>
#include <vector>

namespace hardware_interface
{
namespace components
{

/**
* \brief This structure stores information about components defined for a specific hardware
* in robot's URDF.
*/
struct ComponentInfo
{
/**
* \brief name of the component.
*/
std::string name;
/**
* \brief type of the component: sensor or actuator.
*/
std::string type;
/**
* \brief component's class, which will be dynamically loaded.
*/
std::string class_type;
/**
* \brief name of the command interfaces that can be set, e.g. "position", "velocity", etc.
* Used by joints.
*/
std::vector<std::string> command_interfaces;
/**
* \brief name of the state interfaces that can be read, e.g. "position", "velocity", etc.
* Used by Joints and Sensors.
*/
std::vector<std::string> state_interfaces;
/**
* \brief (optional) key-value pairs of components parameters.
*/
std::unordered_map<std::string, std::string> parameters;
};

} // namespace components
} // namespace hardware_interface
#endif // HARDWARE_INTERFACE__COMPONENTS__COMPONENT_INFO_HPP_

0 comments on commit 3a1fad5

Please sign in to comment.