ros2_control - rolling
Loading...
Searching...
No Matches
hardware_component.hpp
1// Copyright 2020 - 2021 ros2_control Development Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef HARDWARE_INTERFACE__HARDWARE_COMPONENT_HPP_
16#define HARDWARE_INTERFACE__HARDWARE_COMPONENT_HPP_
17
18#include <cstdint>
19#include <memory>
20#include <mutex>
21#include <string>
22#include <vector>
23
24#include "hardware_interface/handle.hpp"
25#include "hardware_interface/hardware_component_interface.hpp"
26#include "hardware_interface/hardware_info.hpp"
27#include "hardware_interface/types/hardware_component_params.hpp"
28#include "hardware_interface/types/hardware_interface_return_values.hpp"
29#include "hardware_interface/types/statistics_types.hpp"
30#include "rclcpp/duration.hpp"
31#include "rclcpp/logger.hpp"
32#include "rclcpp/node_interfaces/node_clock_interface.hpp"
33#include "rclcpp/time.hpp"
34#include "rclcpp_lifecycle/state.hpp"
35
36namespace hardware_interface
37{
38class HardwareComponentInterface;
39
41{
42public:
43 HardwareComponent() = default;
44
45 explicit HardwareComponent(std::unique_ptr<HardwareComponentInterface> impl);
46
47 explicit HardwareComponent(HardwareComponent && other) noexcept;
48
50
51 HardwareComponent(const HardwareComponent & other) = delete;
52
53 HardwareComponent & operator=(const HardwareComponent & other) = delete;
54
55 HardwareComponent & operator=(HardwareComponent && other) = delete;
56
57 const rclcpp_lifecycle::State & initialize(
59
60 const rclcpp_lifecycle::State & configure();
61
62 const rclcpp_lifecycle::State & cleanup();
63
64 const rclcpp_lifecycle::State & shutdown();
65
66 const rclcpp_lifecycle::State & activate();
67
68 const rclcpp_lifecycle::State & deactivate();
69
70 const rclcpp_lifecycle::State & error();
71
72 std::vector<StateInterface::ConstSharedPtr> export_state_interfaces();
73
74 std::vector<CommandInterface::SharedPtr> export_command_interfaces();
75
76 return_type prepare_command_mode_switch(
77 const std::vector<std::string> & start_interfaces,
78 const std::vector<std::string> & stop_interfaces);
79
80 return_type perform_command_mode_switch(
81 const std::vector<std::string> & start_interfaces,
82 const std::vector<std::string> & stop_interfaces);
83
84 const std::string & get_name() const;
85
86 const std::string & get_group_name() const;
87
88 const rclcpp_lifecycle::State & get_lifecycle_state() const;
89
90 uint8_t get_lifecycle_id() const;
91
92 const rclcpp::Time & get_last_read_time() const;
93
94 const rclcpp::Time & get_last_write_time() const;
95
96 const HardwareComponentStatisticsCollector & get_read_statistics() const;
97
98 const HardwareComponentStatisticsCollector & get_write_statistics() const;
99
100 return_type read(const rclcpp::Time & time, const rclcpp::Duration & period);
101
102 return_type write(const rclcpp::Time & time, const rclcpp::Duration & period);
103
104 std::recursive_mutex & get_mutex();
105
106private:
107 std::unique_ptr<HardwareComponentInterface> impl_;
108 mutable std::recursive_mutex component_mutex_;
109 // Last read cycle time
110 rclcpp::Time last_read_cycle_time_;
111 // Last write cycle time
112 rclcpp::Time last_write_cycle_time_;
113 // Component statistics
114 HardwareComponentStatisticsCollector read_statistics_;
115 HardwareComponentStatisticsCollector write_statistics_;
116};
117
118} // namespace hardware_interface
119#endif // HARDWARE_INTERFACE__HARDWARE_COMPONENT_HPP_
Definition hardware_component.hpp:41
Definition mujoco_system_interface.hpp:57
Parameters required for the initialization of a specific hardware component plugin....
Definition hardware_component_params.hpp:33