Skip to content

Commit 3466439

Browse files
Karsten1987bmagyardestogl
authored
Remodel component interfaces (#203)
* introducing handles * component interfaces & tests Signed-off-by: Karsten Knese <[email protected]> Co-authored-by: Bence Magyar <[email protected]> Co-authored-by: Denis Štogl <[email protected]>
1 parent bce8d90 commit 3466439

File tree

16 files changed

+525
-681
lines changed

16 files changed

+525
-681
lines changed

hardware_interface/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ if(BUILD_TESTING)
103103
target_link_libraries(test_joint_handle hardware_interface)
104104
ament_target_dependencies(test_joint_handle rcpputils)
105105

106+
ament_add_gmock(test_component_interfaces test/test_component_interfaces.cpp)
107+
target_link_libraries(test_component_interfaces hardware_interface)
108+
106109
ament_add_gmock(test_component_parser test/test_component_parser.cpp)
107110
target_link_libraries(test_component_parser component_parser)
108111
ament_target_dependencies(test_component_parser TinyXML2)

hardware_interface/include/hardware_interface/actuator_handle.hpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,14 @@
1818
#include <string>
1919

2020
#include "hardware_interface/handle.hpp"
21-
#include "hardware_interface/macros.hpp"
22-
#include "hardware_interface/visibility_control.h"
2321

2422
namespace hardware_interface
2523
{
2624
/** A handle used to get and set a value on a given actuator interface. */
27-
class ActuatorHandle : public Handle<ActuatorHandle>
25+
class ActuatorHandle : public ReadWriteHandle<ActuatorHandle>
2826
{
2927
public:
30-
HARDWARE_INTERFACE_PUBLIC
31-
ActuatorHandle(
32-
const std::string & name, const std::string & interface_name,
33-
double * value_ptr = nullptr)
34-
: Handle(name, interface_name, value_ptr)
35-
{
36-
}
28+
using ReadWriteHandle<ActuatorHandle>::ReadWriteHandle;
3729
};
3830

3931
} // namespace hardware_interface

hardware_interface/include/hardware_interface/components/actuator.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
#define HARDWARE_INTERFACE__COMPONENTS__ACTUATOR_HPP_
1717

1818
#include <memory>
19+
#include <vector>
1920

21+
#include "hardware_interface/handle.hpp"
2022
#include "hardware_interface/hardware_info.hpp"
2123
#include "hardware_interface/types/hardware_interface_return_values.hpp"
2224
#include "hardware_interface/types/hardware_interface_status_values.hpp"
@@ -34,18 +36,35 @@ class Actuator final
3436
public:
3537
Actuator() = default;
3638

39+
HARDWARE_INTERFACE_PUBLIC
3740
explicit Actuator(std::unique_ptr<ActuatorInterface> impl);
3841

3942
~Actuator() = default;
4043

44+
HARDWARE_INTERFACE_PUBLIC
4145
return_type configure(const HardwareInfo & actuator_info);
4246

47+
HARDWARE_INTERFACE_PUBLIC
48+
std::vector<StateHandle> export_state_handles();
49+
50+
HARDWARE_INTERFACE_PUBLIC
51+
std::vector<CommandHandle> export_command_handles();
52+
53+
HARDWARE_INTERFACE_PUBLIC
4354
return_type start();
4455

56+
HARDWARE_INTERFACE_PUBLIC
4557
return_type stop();
4658

59+
HARDWARE_INTERFACE_PUBLIC
4760
status get_status() const;
4861

62+
HARDWARE_INTERFACE_PUBLIC
63+
return_type read();
64+
65+
HARDWARE_INTERFACE_PUBLIC
66+
return_type write();
67+
4968
private:
5069
std::unique_ptr<ActuatorInterface> impl_;
5170
};

hardware_interface/include/hardware_interface/components/actuator_interface.hpp

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
#define HARDWARE_INTERFACE__COMPONENTS__ACTUATOR_INTERFACE_HPP_
1717

1818
#include <memory>
19+
#include <vector>
1920

21+
#include "hardware_interface/handle.hpp"
2022
#include "hardware_interface/hardware_info.hpp"
2123
#include "hardware_interface/types/hardware_interface_return_values.hpp"
2224
#include "hardware_interface/types/hardware_interface_status_values.hpp"
23-
#include "hardware_interface/visibility_control.h"
2425

2526
namespace hardware_interface
2627
{
@@ -46,16 +47,38 @@ class ActuatorInterface
4647
* \return return_type::OK if required data are provided and can be parsed,
4748
* return_type::ERROR otherwise.
4849
*/
49-
HARDWARE_INTERFACE_PUBLIC
5050
virtual
5151
return_type configure(const HardwareInfo & actuator_info) = 0;
5252

53+
/// Exports all state handles for this actuator.
54+
/**
55+
* The state handles have to be created and transfered according
56+
* to the actuator info passed in for the configuration.
57+
*
58+
* Note the ownership over the state handles must be released.
59+
*
60+
* \return vector of state handles
61+
*/
62+
virtual
63+
std::vector<StateHandle> export_state_handles() = 0;
64+
65+
/// Exports all command handles for this actuator.
66+
/**
67+
* The command handles have to be created and transfered according
68+
* to the actuator info passed in for the configuration.
69+
*
70+
* Note the ownership over the command handles must be released.
71+
*
72+
* \return vector of command handles
73+
*/
74+
virtual
75+
std::vector<CommandHandle> export_command_handles() = 0;
76+
5377
/**
5478
* \brief Start exchange data with the hardware.
5579
*
5680
* \return return_type:OK if everything worked as expected, return_type::ERROR otherwise.
5781
*/
58-
HARDWARE_INTERFACE_PUBLIC
5982
virtual
6083
return_type start() = 0;
6184

@@ -64,7 +87,6 @@ class ActuatorInterface
6487
*
6588
* \return return_type:OK if everything worked as expected, return_type::ERROR otherwise.
6689
*/
67-
HARDWARE_INTERFACE_PUBLIC
6890
virtual
6991
return_type stop() = 0;
7092

@@ -73,9 +95,29 @@ class ActuatorInterface
7395
*
7496
* \return status current status.
7597
*/
76-
HARDWARE_INTERFACE_PUBLIC
7798
virtual
7899
status get_status() const = 0;
100+
101+
/// Read the current state values from the actuator.
102+
/**
103+
* The data readings from the physical hardware has to be updated
104+
* and reflected accordingly in the exported state handles.
105+
* That is, the data pointed by the handles shall be updated.
106+
*
107+
* \return return_type::OK if the read was successful, return_type::ERROR otherwise.
108+
*/
109+
virtual
110+
return_type read() = 0;
111+
112+
/// Write the current command values to the actuator.
113+
/**
114+
* The physical hardware shall be updated with the latest value from
115+
* the exported command handles.
116+
*
117+
* \return return_type::OK if the read was successful, return_type::ERROR otherwise.
118+
*/
119+
virtual
120+
return_type write() = 0;
79121
};
80122

81123
} // namespace components

hardware_interface/include/hardware_interface/components/sensor.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <utility>
2121
#include <vector>
2222

23+
#include "hardware_interface/handle.hpp"
2324
#include "hardware_interface/hardware_info.hpp"
2425
#include "hardware_interface/types/hardware_interface_return_values.hpp"
2526
#include "hardware_interface/types/hardware_interface_status_values.hpp"
@@ -37,13 +38,17 @@ class Sensor final
3738
public:
3839
Sensor() = default;
3940

41+
HARDWARE_INTERFACE_PUBLIC
4042
explicit Sensor(std::unique_ptr<SensorInterface> impl);
4143

4244
~Sensor() = default;
4345

4446
HARDWARE_INTERFACE_PUBLIC
4547
return_type configure(const HardwareInfo & sensor_info);
4648

49+
HARDWARE_INTERFACE_PUBLIC
50+
std::vector<StateHandle> export_state_handles();
51+
4752
HARDWARE_INTERFACE_PUBLIC
4853
return_type start();
4954

@@ -53,6 +58,9 @@ class Sensor final
5358
HARDWARE_INTERFACE_PUBLIC
5459
status get_status() const;
5560

61+
HARDWARE_INTERFACE_PUBLIC
62+
return_type read();
63+
5664
private:
5765
std::unique_ptr<SensorInterface> impl_;
5866
};

hardware_interface/include/hardware_interface/components/sensor_interface.hpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,26 @@ class SensorInterface
4747
* \return return_type::OK if required data are provided and can be parsed,
4848
* return_type::ERROR otherwise.
4949
*/
50-
HARDWARE_INTERFACE_PUBLIC
5150
virtual
5251
return_type configure(const HardwareInfo & sensor_info) = 0;
5352

53+
/// Exports all state handles for this sensor.
54+
/**
55+
* The state handles have to be created and transfered according
56+
* to the sensor info passed in for the configuration.
57+
*
58+
* Note the ownership over the state handles must be released.
59+
*
60+
* \return vector of state handles
61+
*/
62+
virtual
63+
std::vector<StateHandle> export_state_handles() = 0;
64+
5465
/**
5566
* \brief Start exchange data with the hardware.
5667
*
5768
* \return return_type:OK if everything worked as expected, return_type::ERROR otherwise.
5869
*/
59-
HARDWARE_INTERFACE_PUBLIC
6070
virtual
6171
return_type start() = 0;
6272

@@ -65,7 +75,6 @@ class SensorInterface
6575
*
6676
* \return return_type:OK if everything worked as expected, return_type::ERROR otherwise.
6777
*/
68-
HARDWARE_INTERFACE_PUBLIC
6978
virtual
7079
return_type stop() = 0;
7180

@@ -74,9 +83,19 @@ class SensorInterface
7483
*
7584
* \return status current status.
7685
*/
77-
HARDWARE_INTERFACE_PUBLIC
7886
virtual
7987
status get_status() const = 0;
88+
89+
/// Read the current state values from the sensor.
90+
/**
91+
* The data readings from the physical hardware has to be updated
92+
* and reflected accordingly in the exported state handles.
93+
* That is, the data pointed by the handles shall be updated.
94+
*
95+
* \return return_type::OK if the read was successful, return_type::ERROR otherwise.
96+
*/
97+
virtual
98+
return_type read() = 0;
8099
};
81100

82101
} // namespace components

hardware_interface/include/hardware_interface/components/system.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <utility>
2121
#include <vector>
2222

23+
#include "hardware_interface/handle.hpp"
2324
#include "hardware_interface/hardware_info.hpp"
2425
#include "hardware_interface/types/hardware_interface_return_values.hpp"
2526
#include "hardware_interface/types/hardware_interface_status_values.hpp"
@@ -43,6 +44,12 @@ class System final
4344
HARDWARE_INTERFACE_PUBLIC
4445
return_type configure(const HardwareInfo & system_info);
4546

47+
HARDWARE_INTERFACE_PUBLIC
48+
std::vector<StateHandle> export_state_handles();
49+
50+
HARDWARE_INTERFACE_PUBLIC
51+
std::vector<CommandHandle> export_command_handles();
52+
4653
HARDWARE_INTERFACE_PUBLIC
4754
return_type start();
4855

@@ -52,6 +59,12 @@ class System final
5259
HARDWARE_INTERFACE_PUBLIC
5360
status get_status() const;
5461

62+
HARDWARE_INTERFACE_PUBLIC
63+
return_type read();
64+
65+
HARDWARE_INTERFACE_PUBLIC
66+
return_type write();
67+
5568
private:
5669
std::unique_ptr<SystemInterface> impl_;
5770
};

hardware_interface/include/hardware_interface/components/system_interface.hpp

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,38 @@ class SystemInterface
4848
* \return return_type::OK if required data are provided and can be parsed,
4949
* return_type::ERROR otherwise.
5050
*/
51-
HARDWARE_INTERFACE_PUBLIC
5251
virtual
5352
return_type configure(const HardwareInfo & system_info) = 0;
5453

54+
/// Exports all state handles for this system.
55+
/**
56+
* The state handles have to be created and transfered according
57+
* to the system info passed in for the configuration.
58+
*
59+
* Note the ownership over the state handles must be released.
60+
*
61+
* \return vector of state handles
62+
*/
63+
virtual
64+
std::vector<StateHandle> export_state_handles() = 0;
65+
66+
/// Exports all command handles for this system.
67+
/**
68+
* The command handles have to be created and transfered according
69+
* to the system info passed in for the configuration.
70+
*
71+
* Note the ownership over the command handles must be released.
72+
*
73+
* \return vector of command handles
74+
*/
75+
virtual
76+
std::vector<CommandHandle> export_command_handles() = 0;
77+
5578
/**
5679
* \brief Start exchange data with the hardware.
5780
*
5881
* \return return_type:OK if everything worked as expected, return_type::ERROR otherwise.
5982
*/
60-
HARDWARE_INTERFACE_PUBLIC
6183
virtual
6284
return_type start() = 0;
6385

@@ -66,7 +88,6 @@ class SystemInterface
6688
*
6789
* \return return_type:OK if everything worked as expected, return_type::ERROR otherwise.
6890
*/
69-
HARDWARE_INTERFACE_PUBLIC
7091
virtual
7192
return_type stop() = 0;
7293

@@ -75,9 +96,29 @@ class SystemInterface
7596
*
7697
* \return status current status.
7798
*/
78-
HARDWARE_INTERFACE_PUBLIC
7999
virtual
80100
status get_status() const = 0;
101+
102+
/// Read the current state values from the actuators and sensors within the system.
103+
/**
104+
* The data readings from the physical hardware has to be updated
105+
* and reflected accordingly in the exported state handles.
106+
* That is, the data pointed by the handles shall be updated.
107+
*
108+
* \return return_type::OK if the read was successful, return_type::ERROR otherwise.
109+
*/
110+
virtual
111+
return_type read() = 0;
112+
113+
/// Write the current command values to the actuator within the system.
114+
/**
115+
* The physical hardware shall be updated with the latest value from
116+
* the exported command handles.
117+
*
118+
* \return return_type::OK if the read was successful, return_type::ERROR otherwise.
119+
*/
120+
virtual
121+
return_type write() = 0;
81122
};
82123

83124
} // namespace components

0 commit comments

Comments
 (0)