Skip to content

Commit 9d5d524

Browse files
[MockHardware] Use consequently 'mock' instead of 'fake'. (backport #1026) – And deprecate parameters. (#1051)
* Use consequently 'mock' instead of 'fake'. (#1026) (cherry picked from commit 7174a1d) # Conflicts: # hardware_interface/include/mock_components/generic_system.hpp # hardware_interface/src/mock_components/generic_system.cpp # hardware_interface/test/mock_components/test_generic_system.cpp --------- Co-authored-by: Dr. Denis <[email protected]>
1 parent 297159d commit 9d5d524

File tree

3 files changed

+163
-50
lines changed

3 files changed

+163
-50
lines changed

hardware_interface/include/mock_components/generic_system.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ class HARDWARE_INTERFACE_PUBLIC GenericSystem : public hardware_interface::Syste
8181

8282
std::vector<std::string> sensor_interfaces_;
8383
/// The size of this vector is (sensor_interfaces_.size() x nr_joints)
84-
std::vector<std::vector<double>> sensor_fake_commands_;
84+
std::vector<std::vector<double>> sensor_mock_commands_;
8585
std::vector<std::vector<double>> sensor_states_;
8686

8787
std::vector<std::string> gpio_interfaces_;
8888
/// The size of this vector is (gpio_interfaces_.size() x nr_joints)
89-
std::vector<std::vector<double>> gpio_fake_commands_;
89+
std::vector<std::vector<double>> gpio_mock_commands_;
9090
std::vector<std::vector<double>> gpio_commands_;
9191
std::vector<std::vector<double>> gpio_states_;
9292

@@ -108,8 +108,8 @@ class HARDWARE_INTERFACE_PUBLIC GenericSystem : public hardware_interface::Syste
108108
std::vector<std::string> & interfaces, std::vector<std::vector<double>> & storage,
109109
std::vector<InterfaceType> & target_interfaces, bool using_state_interfaces);
110110

111-
bool use_fake_gpio_command_interfaces_;
112-
bool use_fake_sensor_command_interfaces_;
111+
bool use_mock_gpio_command_interfaces_;
112+
bool use_mock_sensor_command_interfaces_;
113113

114114
double position_state_following_offset_;
115115
std::string custom_interface_with_following_offset_;

hardware_interface/src/mock_components/generic_system.cpp

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,52 @@ CallbackReturn GenericSystem::on_init(const hardware_interface::HardwareInfo & i
5858
}
5959
};
6060

61-
// check if to create fake command interface for sensor
62-
auto it = info_.hardware_parameters.find("fake_sensor_commands");
61+
// check if to create mock command interface for sensor
62+
auto it = info_.hardware_parameters.find("mock_sensor_commands");
6363
if (it != info_.hardware_parameters.end())
6464
{
65-
use_fake_sensor_command_interfaces_ = hardware_interface::parse_bool(it->second);
65+
use_mock_sensor_command_interfaces_ = hardware_interface::parse_bool(it->second);
6666
}
6767
else
6868
{
69-
use_fake_sensor_command_interfaces_ = false;
69+
// check if fake_sensor_commands was set instead and issue warning.
70+
it = info_.hardware_parameters.find("fake_sensor_commands");
71+
if (it != info_.hardware_parameters.end())
72+
{
73+
use_mock_sensor_command_interfaces_ = hardware_interface::parse_bool(it->second);
74+
RCUTILS_LOG_WARN_NAMED(
75+
"mock_generic_system",
76+
"Parameter 'fake_sensor_commands' has been deprecated from usage. Use"
77+
"'mock_sensor_commands' instead.");
78+
}
79+
else
80+
{
81+
use_mock_sensor_command_interfaces_ = false;
82+
}
7083
}
7184

72-
// check if to create fake command interface for gpio
73-
it = info_.hardware_parameters.find("fake_gpio_commands");
85+
// check if to create mock command interface for gpio
86+
it = info_.hardware_parameters.find("mock_gpio_commands");
7487
if (it != info_.hardware_parameters.end())
7588
{
76-
use_fake_gpio_command_interfaces_ = hardware_interface::parse_bool(it->second);
89+
use_mock_gpio_command_interfaces_ = hardware_interface::parse_bool(it->second);
7790
}
7891
else
7992
{
80-
use_fake_gpio_command_interfaces_ = false;
93+
// check if fake_gpio_commands was set instead and issue warning
94+
it = info_.hardware_parameters.find("fake_gpio_commands");
95+
if (it != info_.hardware_parameters.end())
96+
{
97+
use_mock_gpio_command_interfaces_ = hardware_interface::parse_bool(it->second);
98+
RCUTILS_LOG_WARN_NAMED(
99+
"mock_generic_system",
100+
"Parameter 'fake_gpio_commands' has been deprecated from usage. Use"
101+
"'mock_gpio_commands' instead.");
102+
}
103+
else
104+
{
105+
use_mock_gpio_command_interfaces_ = false;
106+
}
81107
}
82108

83109
// process parameters about state following
@@ -162,14 +188,14 @@ CallbackReturn GenericSystem::on_init(const hardware_interface::HardwareInfo & i
162188
index_custom_interface_with_following_offset_ =
163189
std::distance(other_interfaces_.begin(), if_it);
164190
RCUTILS_LOG_INFO_NAMED(
165-
"fake_generic_system", "Custom interface with following offset '%s' found at index: %zu.",
191+
"mock_generic_system", "Custom interface with following offset '%s' found at index: %zu.",
166192
custom_interface_with_following_offset_.c_str(),
167193
index_custom_interface_with_following_offset_);
168194
}
169195
else
170196
{
171197
RCUTILS_LOG_WARN_NAMED(
172-
"fake_generic_system",
198+
"mock_generic_system",
173199
"Custom interface with following offset '%s' does not exist. Offset will not be applied",
174200
custom_interface_with_following_offset_.c_str());
175201
}
@@ -188,7 +214,7 @@ CallbackReturn GenericSystem::on_init(const hardware_interface::HardwareInfo & i
188214
}
189215
}
190216
initialize_storage_vectors(
191-
sensor_fake_commands_, sensor_states_, sensor_interfaces_, info_.sensors);
217+
sensor_mock_commands_, sensor_states_, sensor_interfaces_, info_.sensors);
192218

193219
// search for gpio interfaces
194220
for (const auto & gpio : info_.gpios)
@@ -200,10 +226,10 @@ CallbackReturn GenericSystem::on_init(const hardware_interface::HardwareInfo & i
200226
populate_non_standard_interfaces(gpio.state_interfaces, gpio_interfaces_);
201227
}
202228

203-
// Fake gpio command interfaces
204-
if (use_fake_gpio_command_interfaces_)
229+
// Mock gpio command interfaces
230+
if (use_mock_gpio_command_interfaces_)
205231
{
206-
initialize_storage_vectors(gpio_fake_commands_, gpio_states_, gpio_interfaces_, info_.gpios);
232+
initialize_storage_vectors(gpio_mock_commands_, gpio_states_, gpio_interfaces_, info_.gpios);
207233
}
208234
// Real gpio command interfaces
209235
else
@@ -283,22 +309,22 @@ std::vector<hardware_interface::CommandInterface> GenericSystem::export_command_
283309
}
284310
}
285311

286-
// Fake sensor command interfaces
287-
if (use_fake_sensor_command_interfaces_)
312+
// Mock sensor command interfaces
313+
if (use_mock_sensor_command_interfaces_)
288314
{
289315
if (!populate_interfaces(
290-
info_.sensors, sensor_interfaces_, sensor_fake_commands_, command_interfaces, true))
316+
info_.sensors, sensor_interfaces_, sensor_mock_commands_, command_interfaces, true))
291317
{
292318
throw std::runtime_error(
293319
"Interface is not found in the standard nor other list. This should never happen!");
294320
}
295321
}
296322

297-
// Fake gpio command interfaces (consider all state interfaces for command interfaces)
298-
if (use_fake_gpio_command_interfaces_)
323+
// Mock gpio command interfaces (consider all state interfaces for command interfaces)
324+
if (use_mock_gpio_command_interfaces_)
299325
{
300326
if (!populate_interfaces(
301-
info_.gpios, gpio_interfaces_, gpio_fake_commands_, command_interfaces, true))
327+
info_.gpios, gpio_interfaces_, gpio_mock_commands_, command_interfaces, true))
302328
{
303329
throw std::runtime_error(
304330
"Interface is not found in the gpio list. This should never happen!");
@@ -375,15 +401,15 @@ return_type GenericSystem::read(const rclcpp::Time & /*time*/, const rclcpp::Dur
375401
}
376402
}
377403

378-
if (use_fake_sensor_command_interfaces_)
404+
if (use_mock_sensor_command_interfaces_)
379405
{
380-
mirror_command_to_state(sensor_states_, sensor_fake_commands_);
406+
mirror_command_to_state(sensor_states_, sensor_mock_commands_);
381407
}
382408

383409
// do loopback on all gpio interfaces
384-
if (use_fake_gpio_command_interfaces_)
410+
if (use_mock_gpio_command_interfaces_)
385411
{
386-
mirror_command_to_state(gpio_states_, gpio_fake_commands_);
412+
mirror_command_to_state(gpio_states_, gpio_mock_commands_);
387413
}
388414
else
389415
{

0 commit comments

Comments
 (0)