ros2_control - foxy
Loading...
Searching...
No Matches
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/base_interface.hpp"
24#include "hardware_interface/handle.hpp"
25#include "hardware_interface/hardware_info.hpp"
26#include "hardware_interface/system_interface.hpp"
27#include "hardware_interface/types/hardware_interface_return_values.hpp"
28#include "hardware_interface/types/hardware_interface_status_values.hpp"
29#include "hardware_interface/types/hardware_interface_type_values.hpp"
30
31using hardware_interface::return_type;
32
33namespace fake_components
34{
35class HARDWARE_INTERFACE_PUBLIC GenericSystem
36: public hardware_interface::BaseInterface<hardware_interface::SystemInterface>
37{
38public:
39 return_type configure(const hardware_interface::HardwareInfo & info) override;
40
41 std::vector<hardware_interface::StateInterface> export_state_interfaces() override;
42
43 std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;
44
45 return_type start() override
46 {
47 status_ = hardware_interface::status::STARTED;
48 return return_type::OK;
49 }
50
51 return_type stop() override
52 {
53 status_ = hardware_interface::status::STOPPED;
54 return return_type::OK;
55 }
56
57 return_type read() override;
58
59 return_type write() override { return return_type::OK; }
60
61protected:
63
69 const std::vector<std::string> standard_interfaces_ = {
70 hardware_interface::HW_IF_POSITION, hardware_interface::HW_IF_VELOCITY,
71 hardware_interface::HW_IF_ACCELERATION, hardware_interface::HW_IF_EFFORT};
72
73 const size_t POSITION_INTERFACE_INDEX = 0;
74
76 {
77 std::size_t joint_index;
78 std::size_t mimicked_joint_index;
79 double multiplier = 1.0;
80 };
81 std::vector<MimicJoint> mimic_joints_;
82
84 std::vector<std::vector<double>> joint_commands_;
85 std::vector<std::vector<double>> joint_states_;
86
87 std::vector<std::string> other_interfaces_;
89 std::vector<std::vector<double>> other_commands_;
90 std::vector<std::vector<double>> other_states_;
91
92 std::vector<std::string> sensor_interfaces_;
94 std::vector<std::vector<double>> sensor_fake_commands_;
95 std::vector<std::vector<double>> sensor_states_;
96
97private:
98 template <typename HandleType>
99 bool get_interface(
100 const std::string & name, const std::vector<std::string> & interface_list,
101 const std::string & interface_name, const size_t vector_index,
102 std::vector<std::vector<double>> & values, std::vector<HandleType> & interfaces);
103
104 void initialize_storage_vectors(
105 std::vector<std::vector<double>> & commands, std::vector<std::vector<double>> & states,
106 const std::vector<std::string> & interfaces);
107
108 bool fake_sensor_command_interfaces_;
109 double position_state_following_offset_;
110 std::string custom_interface_with_following_offset_;
111 size_t index_custom_interface_with_following_offset_;
112};
113
115
116} // namespace fake_components
117
118#endif // FAKE_COMPONENTS__GENERIC_SYSTEM_HPP_
Definition generic_system.hpp:37
return_type stop() override
Stop exchange data with the hardware.
Definition generic_system.hpp:51
std::vector< std::vector< double > > other_commands_
The size of this vector is (other_interfaces_.size() x nr_joints)
Definition generic_system.hpp:89
return_type write() override
Write the current command values to the actuator within the system.
Definition generic_system.hpp:59
std::vector< std::vector< double > > joint_commands_
The size of this vector is (standard_interfaces_.size() x nr_joints)
Definition generic_system.hpp:84
std::vector< std::vector< double > > sensor_fake_commands_
The size of this vector is (other_interfaces_.size() x nr_joints)
Definition generic_system.hpp:94
return_type start() override
Start exchange data with the hardware.
Definition generic_system.hpp:45
Definition base_interface.hpp:28
Definition generic_system.hpp:76
This structure stores information about hardware defined in a robot's URDF.
Definition hardware_info.hpp:103