Skip to content

Commit ad416ce

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

File tree

16 files changed

+406
-609
lines changed

16 files changed

+406
-609
lines changed

hardware_interface/include/hardware_interface/handle.hpp

Lines changed: 5 additions & 27 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;
@@ -79,9 +61,6 @@ class Handle
7961

8062
virtual ~Handle() = default;
8163

82-
/// Returns true if handle references a value.
83-
inline operator bool() const { return value_ptr_ != nullptr; }
84-
8564
const std::string get_name() const { return prefix_name_ + "/" + interface_name_; }
8665

8766
const std::string & get_interface_name() const { return interface_name_; }
@@ -183,7 +162,6 @@ class Handle
183162
std::string prefix_name_;
184163
std::string interface_name_;
185164
HANDLE_DATATYPE value_;
186-
double * value_ptr_;
187165
};
188166

189167
class StateInterface : public Handle

hardware_interface/include/mock_components/generic_system.hpp

Lines changed: 28 additions & 39 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,54 +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

75-
/// The size of this vector is (standard_interfaces_.size() x nr_joints)
76-
std::vector<std::vector<double>> joint_commands_;
77-
std::vector<std::vector<double>> joint_states_;
78-
79-
std::vector<std::string> other_interfaces_;
80-
/// The size of this vector is (other_interfaces_.size() x nr_joints)
81-
std::vector<std::vector<double>> other_commands_;
82-
std::vector<std::vector<double>> other_states_;
83-
84-
std::vector<std::string> sensor_interfaces_;
85-
/// The size of this vector is (sensor_interfaces_.size() x nr_joints)
86-
std::vector<std::vector<double>> sensor_mock_commands_;
87-
std::vector<std::vector<double>> sensor_states_;
88-
89-
std::vector<std::string> gpio_interfaces_;
90-
/// The size of this vector is (gpio_interfaces_.size() x nr_joints)
91-
std::vector<std::vector<double>> gpio_mock_commands_;
92-
std::vector<std::vector<double>> gpio_commands_;
93-
std::vector<std::vector<double>> gpio_states_;
77+
struct MimicJoint
78+
{
79+
std::string joint_name;
80+
std::string mimic_joint_name;
81+
double multiplier = 1.0;
82+
};
83+
std::vector<MimicJoint> mimic_joints_;
84+
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_;
90+
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_;
9496

9597
private:
96-
template <typename HandleType>
97-
bool get_interface(
98-
const std::string & name, const std::vector<std::string> & interface_list,
99-
const std::string & interface_name, const size_t vector_index,
100-
std::vector<std::vector<double>> & values, std::vector<HandleType> & interfaces);
101-
102-
void initialize_storage_vectors(
103-
std::vector<std::vector<double>> & commands, std::vector<std::vector<double>> & states,
104-
const std::vector<std::string> & interfaces,
105-
const std::vector<hardware_interface::ComponentInfo> & component_infos);
106-
107-
template <typename InterfaceType>
108-
bool populate_interfaces(
98+
void search_and_add_interface_names(
10999
const std::vector<hardware_interface::ComponentInfo> & components,
110-
std::vector<std::string> & interfaces, std::vector<std::vector<double>> & storage,
111-
std::vector<InterfaceType> & target_interfaces, bool using_state_interfaces);
100+
const std::vector<std::string> & interface_list, std::vector<std::string> & vector_to_add);
112101

113102
bool use_mock_gpio_command_interfaces_;
114103
bool use_mock_sensor_command_interfaces_;
115104

116105
double position_state_following_offset_;
117106
std::string custom_interface_with_following_offset_;
118-
size_t index_custom_interface_with_following_offset_;
107+
std::string custom_interface_name_with_following_offset_;
119108

120109
bool calculate_dynamics_;
121-
std::vector<size_t> joint_control_mode_;
110+
std::unordered_map<std::string, size_t> joint_control_mode_;
122111

123112
bool command_propagation_disabled_;
124113
};

0 commit comments

Comments
 (0)