ros2_control - galactic
generic_system.hpp
1 // Copyright (c) 2021 PickNik, 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 // Author: Jafar Abdi, Denis Stogl
16 
17 #ifndef FAKE_COMPONENTS__GENERIC_SYSTEM_HPP_
18 #define FAKE_COMPONENTS__GENERIC_SYSTEM_HPP_
19 
20 #include <string>
21 #include <vector>
22 
23 #include "hardware_interface/handle.hpp"
24 #include "hardware_interface/hardware_info.hpp"
25 #include "hardware_interface/system_interface.hpp"
26 #include "hardware_interface/types/hardware_interface_return_values.hpp"
27 #include "hardware_interface/types/hardware_interface_type_values.hpp"
28 
29 using hardware_interface::return_type;
30 
31 namespace fake_components
32 {
33 class HARDWARE_INTERFACE_PUBLIC GenericSystem : public hardware_interface::SystemInterface
34 {
35 public:
36  CallbackReturn on_init(const hardware_interface::HardwareInfo & info) override;
37 
38  std::vector<hardware_interface::StateInterface> export_state_interfaces() override;
39 
40  std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;
41 
42  return_type read() override;
43 
44  return_type write() override { return return_type::OK; }
45 
46 protected:
48 
54  const std::vector<std::string> standard_interfaces_ = {
57 
58  const size_t POSITION_INTERFACE_INDEX = 0;
59 
60  struct MimicJoint
61  {
62  std::size_t joint_index;
63  std::size_t mimicked_joint_index;
64  double multiplier = 1.0;
65  };
66  std::vector<MimicJoint> mimic_joints_;
67 
69  std::vector<std::vector<double>> joint_commands_;
70  std::vector<std::vector<double>> joint_states_;
71 
72  std::vector<std::string> other_interfaces_;
74  std::vector<std::vector<double>> other_commands_;
75  std::vector<std::vector<double>> other_states_;
76 
77  std::vector<std::string> sensor_interfaces_;
79  std::vector<std::vector<double>> sensor_fake_commands_;
80  std::vector<std::vector<double>> sensor_states_;
81 
82  std::vector<std::string> gpio_interfaces_;
84  std::vector<std::vector<double>> gpio_fake_commands_;
85  std::vector<std::vector<double>> gpio_commands_;
86  std::vector<std::vector<double>> gpio_states_;
87 
88 private:
89  template <typename HandleType>
90  bool get_interface(
91  const std::string & name, const std::vector<std::string> & interface_list,
92  const std::string & interface_name, const size_t vector_index,
93  std::vector<std::vector<double>> & values, std::vector<HandleType> & interfaces);
94 
95  void initialize_storage_vectors(
96  std::vector<std::vector<double>> & commands, std::vector<std::vector<double>> & states,
97  const std::vector<std::string> & interfaces);
98 
99  void populate_gpio_interfaces();
100 
101  bool fake_gpio_command_interfaces_;
102  bool fake_sensor_command_interfaces_;
103  double position_state_following_offset_;
104  std::string custom_interface_with_following_offset_;
105  size_t index_custom_interface_with_following_offset_;
106 };
107 
109 
110 } // namespace fake_components
111 
112 #endif // FAKE_COMPONENTS__GENERIC_SYSTEM_HPP_
Definition: generic_system.hpp:34
std::vector< std::vector< double > > other_commands_
The size of this vector is (other_interfaces_.size() x nr_joints)
Definition: generic_system.hpp:74
return_type write() override
Write the current command values to the actuator.
Definition: generic_system.hpp:44
std::vector< std::vector< double > > gpio_fake_commands_
The size of this vector is (gpio_interfaces_.size() x nr_joints)
Definition: generic_system.hpp:84
std::vector< std::vector< double > > joint_commands_
The size of this vector is (standard_interfaces_.size() x nr_joints)
Definition: generic_system.hpp:69
std::vector< std::vector< double > > sensor_fake_commands_
The size of this vector is (sensor_interfaces_.size() x nr_joints)
Definition: generic_system.hpp:79
Virtual Class to implement when integrating a complex system into ros2_control.
Definition: system_interface.hpp:68
constexpr char HW_IF_EFFORT[]
Constant defining effort interface.
Definition: hardware_interface_type_values.hpp:27
constexpr char HW_IF_ACCELERATION[]
Constant defining acceleration interface.
Definition: hardware_interface_type_values.hpp:25
constexpr char HW_IF_VELOCITY[]
Constant defining velocity interface.
Definition: hardware_interface_type_values.hpp:23
constexpr char HW_IF_POSITION[]
Constant defining position interface.
Definition: hardware_interface_type_values.hpp:21
Definition: generic_system.hpp:61
This structure stores information about hardware defined in a robot's URDF.
Definition: hardware_info.hpp:101