ros2_control - foxy
Loading...
Searching...
No Matches
resource_manager.hpp
1// Copyright 2020 Open Source Robotics Foundation, Inc.
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__RESOURCE_MANAGER_HPP_
16#define HARDWARE_INTERFACE__RESOURCE_MANAGER_HPP_
17
18#include <memory>
19#include <mutex>
20#include <string>
21#include <unordered_map>
22#include <vector>
23
24#include "hardware_interface/hardware_info.hpp"
25#include "hardware_interface/loaned_command_interface.hpp"
26#include "hardware_interface/loaned_state_interface.hpp"
27#include "hardware_interface/types/hardware_interface_status_values.hpp"
28
29namespace hardware_interface
30{
32class SensorInterface;
33class SystemInterface;
34class ResourceStorage;
35
36class HARDWARE_INTERFACE_PUBLIC ResourceManager
37{
38public:
41
43
55 explicit ResourceManager(const std::string & urdf, bool validate_interfaces = true);
56
57 ResourceManager(const ResourceManager &) = delete;
58
60
62
71 void load_urdf(const std::string & urdf, bool validate_interfaces = true);
72
74
82 LoanedStateInterface claim_state_interface(const std::string & key);
83
85
90 std::vector<std::string> state_interface_keys() const;
91
93
96 bool state_interface_exists(const std::string & key) const;
97
99
107 bool command_interface_is_claimed(const std::string & key) const;
108
110
118 LoanedCommandInterface claim_command_interface(const std::string & key);
119
121
126 std::vector<std::string> command_interface_keys() const;
127
129
133 bool command_interface_exists(const std::string & key) const;
134
136
139 size_t actuator_components_size() const;
140
142
151 void import_component(std::unique_ptr<ActuatorInterface> actuator);
152
154
157 size_t sensor_components_size() const;
158
160
169 void import_component(std::unique_ptr<SensorInterface> sensor);
170
172
175 size_t system_components_size() const;
176
178
187 void import_component(std::unique_ptr<SystemInterface> system);
188
190
193 std::unordered_map<std::string, status> get_components_status();
194
196
211 const std::vector<std::string> & start_interfaces,
212 const std::vector<std::string> & stop_interfaces);
213
215
226 const std::vector<std::string> & start_interfaces,
227 const std::vector<std::string> & stop_interfaces);
228
230 void start_components();
231
233 void stop_components();
234
236 void read();
237
239 void write();
240
241private:
242 void validate_storage(const std::vector<hardware_interface::HardwareInfo> & hardware_info) const;
243
244 void release_command_interface(const std::string & key);
245
246 std::unordered_map<std::string, bool> claimed_command_interface_map_;
247
248 mutable std::recursive_mutex resource_lock_;
249 std::unique_ptr<ResourceStorage> resource_storage_;
250};
251
252} // namespace hardware_interface
253#endif // HARDWARE_INTERFACE__RESOURCE_MANAGER_HPP_
Virtual Class to implement when integrating a 1 DoF actuator into ros2_control.
Definition actuator_interface.hpp:34
Definition loaned_command_interface.hpp:27
Definition loaned_state_interface.hpp:27
void load_urdf(const std::string &urdf, bool validate_interfaces=true)
Load resources from on a given URDF.
Definition resource_manager.cpp:163
std::vector< std::string > command_interface_keys() const
Returns all registered command interfaces keys.
Definition resource_manager.cpp:256
bool command_interface_exists(const std::string &key) const
Checks whether a command interface is registered under the given key.
Definition resource_manager.cpp:266
bool command_interface_is_claimed(const std::string &key) const
Checks whether a command interface is already claimed.
Definition resource_manager.cpp:225
void import_component(std::unique_ptr< ActuatorInterface > actuator)
Import a hardware component which is not listed in the URDF.
Definition resource_manager.cpp:272
void read()
Reads all loaded hardware components.
Definition resource_manager.cpp:435
void stop_components()
Stops all loaded hardware components.
Definition resource_manager.cpp:419
void write()
Write all loaded hardware components.
Definition resource_manager.cpp:451
size_t sensor_components_size() const
Return the number of loaded sensor components.
Definition resource_manager.cpp:291
std::vector< std::string > state_interface_keys() const
Returns all registered state interfaces keys.
Definition resource_manager.cpp:209
size_t system_components_size() const
Return the number of loaded system components.
Definition resource_manager.cpp:304
std::unordered_map< std::string, status > get_components_status()
Return status for all components.
Definition resource_manager.cpp:309
void start_components()
Start all loaded hardware components.
Definition resource_manager.cpp:403
bool state_interface_exists(const std::string &key) const
Checks whether a state interface is registered under the given key.
Definition resource_manager.cpp:219
size_t actuator_components_size() const
Return the number size_t of loaded actuator components.
Definition resource_manager.cpp:280
bool prepare_command_mode_switch(const std::vector< std::string > &start_interfaces, const std::vector< std::string > &stop_interfaces)
Prepare the hardware components for a new command interface mode.
Definition resource_manager.cpp:347
ResourceManager()
Default constructor for the Resource Manager.
Definition resource_manager.cpp:153
bool perform_command_mode_switch(const std::vector< std::string > &start_interfaces, const std::vector< std::string > &stop_interfaces)
Notify the hardware components that realtime hardware mode switching should occur.
Definition resource_manager.cpp:376
LoanedCommandInterface claim_command_interface(const std::string &key)
Claim a command interface given its key.
Definition resource_manager.cpp:236
LoanedStateInterface claim_state_interface(const std::string &key)
Claim a state interface given its key.
Definition resource_manager.cpp:199
Definition resource_manager.cpp:38
Definition sensor_interface.hpp:35
Virtual Class to implement when integrating a complex system into ros2_control.
Definition system_interface.hpp:36