Skip to content

Commit 9fbd1d6

Browse files
committed
tmp commit! remove deprecated handle constructor -> adjust generic system
! not compiling not all tests have been adjusted still wip!
1 parent d31f042 commit 9fbd1d6

File tree

7 files changed

+331
-474
lines changed

7 files changed

+331
-474
lines changed

hardware_interface/include/hardware_interface/handle.hpp

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ class Handle
3636
public:
3737
[[deprecated("Use InterfaceDescription for initializing the Interface")]]
3838

39-
Handle(
40-
const std::string & prefix_name, const std::string & interface_name,
41-
double * value_ptr = nullptr)
42-
: prefix_name_(prefix_name), interface_name_(interface_name), value_ptr_(value_ptr)
39+
Handle(const std::string & prefix_name, const std::string & interface_name)
40+
: prefix_name_(prefix_name), interface_name_(interface_name)
4341
{
44-
// default to double
45-
value_ = std::numeric_limits<double>::quiet_NaN();
42+
// init to default value defined by init_handle_value()
43+
InterfaceInfo info;
44+
init_handle_value(info);
4645
}
4746

4847
explicit Handle(const InterfaceDescription & interface_description)
@@ -52,23 +51,6 @@ class Handle
5251
init_handle_value(interface_description.interface_info);
5352
}
5453

55-
[[deprecated("Use InterfaceDescription for initializing the Interface")]]
56-
57-
explicit Handle(const std::string & interface_name)
58-
: interface_name_(interface_name), value_ptr_(nullptr)
59-
{
60-
// default to double
61-
value_ = std::numeric_limits<double>::quiet_NaN();
62-
}
63-
64-
[[deprecated("Use InterfaceDescription for initializing the Interface")]]
65-
66-
explicit Handle(const char * interface_name)
67-
: interface_name_(interface_name), value_ptr_(nullptr)
68-
{ // default to double
69-
value_ = std::numeric_limits<double>::quiet_NaN();
70-
}
71-
7254
Handle(const Handle & other) = default;
7355

7456
Handle(Handle && other) = default;

hardware_interface/include/mock_components/generic_system.hpp

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#define MOCK_COMPONENTS__GENERIC_SYSTEM_HPP_
1919

2020
#include <string>
21+
#include <unordered_map>
22+
#include <unordered_set>
2123
#include <vector>
2224

2325
#include "hardware_interface/handle.hpp"
@@ -41,9 +43,7 @@ class HARDWARE_INTERFACE_PUBLIC GenericSystem : public hardware_interface::Syste
4143
public:
4244
CallbackReturn on_init(const hardware_interface::HardwareInfo & info) override;
4345

44-
std::vector<hardware_interface::StateInterface> export_state_interfaces() override;
45-
46-
std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;
46+
std::vector<hardware_interface::InterfaceDescription> export_command_interfaces_2() override;
4747

4848
return_type prepare_command_mode_switch(
4949
const std::vector<std::string> & start_interfaces,
@@ -71,62 +71,43 @@ class HARDWARE_INTERFACE_PUBLIC GenericSystem : public hardware_interface::Syste
7171
const std::vector<std::string> standard_interfaces_ = {
7272
hardware_interface::HW_IF_POSITION, hardware_interface::HW_IF_VELOCITY,
7373
hardware_interface::HW_IF_ACCELERATION, hardware_interface::HW_IF_EFFORT};
74+
// added dynamically during on_init
75+
std::vector<std::string> non_standard_interfaces_;
7476

7577
struct MimicJoint
7678
{
77-
std::size_t joint_index;
78-
std::size_t mimicked_joint_index;
79+
std::string joint_name;
80+
std::string mimic_joint_name;
7981
double multiplier = 1.0;
8082
};
8183
std::vector<MimicJoint> mimic_joints_;
8284

83-
/// The size of this vector is (standard_interfaces_.size() x nr_joints)
84-
std::vector<std::vector<double>> joint_commands_;
85-
std::vector<std::vector<double>> joint_states_;
86-
87-
std::vector<std::string> other_interfaces_;
88-
/// The size of this vector is (other_interfaces_.size() x nr_joints)
89-
std::vector<std::vector<double>> other_commands_;
90-
std::vector<std::vector<double>> other_states_;
91-
92-
std::vector<std::string> sensor_interfaces_;
93-
/// The size of this vector is (sensor_interfaces_.size() x nr_joints)
94-
std::vector<std::vector<double>> sensor_mock_commands_;
95-
std::vector<std::vector<double>> sensor_states_;
85+
// All the joints that are of type defined by standard_interfaces_ vector -> In {pos, vel, acc,
86+
// effort}
87+
std::vector<std::string> std_joint_names_;
88+
std::unordered_set<std::string> std_joint_command_interface_names_;
89+
std::unordered_set<std::string> std_joint_state_interface_names_;
9690

97-
std::vector<std::string> gpio_interfaces_;
98-
/// The size of this vector is (gpio_interfaces_.size() x nr_joints)
99-
std::vector<std::vector<double>> gpio_mock_commands_;
100-
std::vector<std::vector<double>> gpio_commands_;
101-
std::vector<std::vector<double>> gpio_states_;
91+
// All the joints that are of not of a type defined by standard_interfaces_ vector -> Not in {pos,
92+
// vel, acc, effort}
93+
std::vector<std::string> other_joint_names_;
94+
std::unordered_set<std::string> other_joint_command_interface_names_;
95+
std::unordered_set<std::string> other_joint_state_interface_names_;
10296

10397
private:
104-
template <typename HandleType>
105-
bool get_interface(
106-
const std::string & name, const std::vector<std::string> & interface_list,
107-
const std::string & interface_name, const size_t vector_index,
108-
std::vector<std::vector<double>> & values, std::vector<HandleType> & interfaces);
109-
110-
void initialize_storage_vectors(
111-
std::vector<std::vector<double>> & commands, std::vector<std::vector<double>> & states,
112-
const std::vector<std::string> & interfaces,
113-
const std::vector<hardware_interface::ComponentInfo> & component_infos);
114-
115-
template <typename InterfaceType>
116-
bool populate_interfaces(
98+
void search_and_add_interface_names(
11799
const std::vector<hardware_interface::ComponentInfo> & components,
118-
std::vector<std::string> & interfaces, std::vector<std::vector<double>> & storage,
119-
std::vector<InterfaceType> & target_interfaces, bool using_state_interfaces);
100+
const std::vector<std::string> & interface_list, std::vector<std::string> & vector_to_add);
120101

121102
bool use_mock_gpio_command_interfaces_;
122103
bool use_mock_sensor_command_interfaces_;
123104

124105
double position_state_following_offset_;
125106
std::string custom_interface_with_following_offset_;
126-
size_t index_custom_interface_with_following_offset_;
107+
std::string custom_interface_name_with_following_offset_;
127108

128109
bool calculate_dynamics_;
129-
std::vector<size_t> joint_control_mode_;
110+
std::unordered_map<std::string, size_t> joint_control_mode_;
130111

131112
bool command_propagation_disabled_;
132113
};

0 commit comments

Comments
 (0)