ros2_control - rolling
system.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__SYSTEM_HPP_
16 #define HARDWARE_INTERFACE__SYSTEM_HPP_
17 
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
22 #include "hardware_interface/handle.hpp"
23 #include "hardware_interface/hardware_info.hpp"
24 #include "hardware_interface/system_interface.hpp"
25 #include "hardware_interface/types/hardware_interface_return_values.hpp"
26 #include "hardware_interface/visibility_control.h"
27 #include "rclcpp/duration.hpp"
28 #include "rclcpp/logger.hpp"
29 #include "rclcpp/node_interfaces/node_clock_interface.hpp"
30 #include "rclcpp/time.hpp"
31 #include "rclcpp_lifecycle/state.hpp"
32 
33 namespace hardware_interface
34 {
35 class SystemInterface;
36 
37 class System final
38 {
39 public:
40  System() = default;
41 
42  HARDWARE_INTERFACE_PUBLIC
43  explicit System(std::unique_ptr<SystemInterface> impl);
44 
45  HARDWARE_INTERFACE_PUBLIC
46  explicit System(System && other) noexcept;
47 
48  ~System() = default;
49 
50  HARDWARE_INTERFACE_PUBLIC
51  const rclcpp_lifecycle::State & initialize(
52  const HardwareInfo & system_info, rclcpp::Logger logger,
53  rclcpp::node_interfaces::NodeClockInterface::SharedPtr clock_interface);
54 
55  HARDWARE_INTERFACE_PUBLIC
56  const rclcpp_lifecycle::State & configure();
57 
58  HARDWARE_INTERFACE_PUBLIC
59  const rclcpp_lifecycle::State & cleanup();
60 
61  HARDWARE_INTERFACE_PUBLIC
62  const rclcpp_lifecycle::State & shutdown();
63 
64  HARDWARE_INTERFACE_PUBLIC
65  const rclcpp_lifecycle::State & activate();
66 
67  HARDWARE_INTERFACE_PUBLIC
68  const rclcpp_lifecycle::State & deactivate();
69 
70  HARDWARE_INTERFACE_PUBLIC
71  const rclcpp_lifecycle::State & error();
72 
73  HARDWARE_INTERFACE_PUBLIC
74  std::vector<StateInterface::ConstSharedPtr> export_state_interfaces();
75 
76  HARDWARE_INTERFACE_PUBLIC
77  std::vector<CommandInterface::SharedPtr> export_command_interfaces();
78 
79  HARDWARE_INTERFACE_PUBLIC
80  return_type prepare_command_mode_switch(
81  const std::vector<std::string> & start_interfaces,
82  const std::vector<std::string> & stop_interfaces);
83 
84  HARDWARE_INTERFACE_PUBLIC
85  return_type perform_command_mode_switch(
86  const std::vector<std::string> & start_interfaces,
87  const std::vector<std::string> & stop_interfaces);
88 
89  HARDWARE_INTERFACE_PUBLIC
90  std::string get_name() const;
91 
92  HARDWARE_INTERFACE_PUBLIC
93  std::string get_group_name() const;
94 
95  HARDWARE_INTERFACE_PUBLIC
96  const rclcpp_lifecycle::State & get_lifecycle_state() const;
97 
98  HARDWARE_INTERFACE_PUBLIC
99  const rclcpp::Time & get_last_read_time() const;
100 
101  HARDWARE_INTERFACE_PUBLIC
102  const rclcpp::Time & get_last_write_time() const;
103 
104  HARDWARE_INTERFACE_PUBLIC
105  return_type read(const rclcpp::Time & time, const rclcpp::Duration & period);
106 
107  HARDWARE_INTERFACE_PUBLIC
108  return_type write(const rclcpp::Time & time, const rclcpp::Duration & period);
109 
110  HARDWARE_INTERFACE_PUBLIC
111  std::recursive_mutex & get_mutex();
112 
113 private:
114  std::unique_ptr<SystemInterface> impl_;
115  mutable std::recursive_mutex system_mutex_;
116  // Last read cycle time
117  rclcpp::Time last_read_cycle_time_;
118  // Last write cycle time
119  rclcpp::Time last_write_cycle_time_;
120 };
121 
122 } // namespace hardware_interface
123 #endif // HARDWARE_INTERFACE__SYSTEM_HPP_
Definition: system.hpp:38
Definition: actuator.hpp:34
This structure stores information about hardware defined in a robot's URDF.
Definition: hardware_info.hpp:170