@@ -39,27 +39,6 @@ CallbackReturn GenericSystem::on_init(
3939 return CallbackReturn::ERROR;
4040 }
4141
42- auto populate_non_standard_interfaces =
43- [this ](auto interface_list, auto & non_standard_interfaces)
44- {
45- for (const auto & interface : interface_list)
46- {
47- // add to list if non-standard interface
48- if (
49- std::find (standard_interfaces_.begin (), standard_interfaces_.end (), interface.name ) ==
50- standard_interfaces_.end ())
51- {
52- if (
53- std::find (
54- non_standard_interfaces.begin (), non_standard_interfaces.end (), interface.name ) ==
55- non_standard_interfaces.end ())
56- {
57- non_standard_interfaces.emplace_back (interface.name );
58- }
59- }
60- }
61- };
62-
6342 // check if to create mock command interface for sensor
6443 auto it = get_hardware_info ().hardware_parameters .find (" mock_sensor_commands" );
6544 if (it != get_hardware_info ().hardware_parameters .end ())
@@ -128,21 +107,44 @@ CallbackReturn GenericSystem::on_init(
128107 }
129108
130109 // search for non-standard joint interfaces
110+ std::vector<std::string> other_interfaces;
111+ auto populate_non_standard_interfaces =
112+ [this ](auto interface_list, auto & non_standard_interfaces)
113+ {
114+ for (const auto & interface : interface_list)
115+ {
116+ // add to list if non-standard interface
117+ if (
118+ std::find (standard_interfaces_.begin (), standard_interfaces_.end (), interface.name ) ==
119+ standard_interfaces_.end ())
120+ {
121+ // and does not exist yet
122+ if (
123+ std::find (
124+ non_standard_interfaces.begin (), non_standard_interfaces.end (), interface.name ) ==
125+ non_standard_interfaces.end ())
126+ {
127+ non_standard_interfaces.emplace_back (interface.name );
128+ }
129+ }
130+ }
131+ };
131132 for (const auto & joint : get_hardware_info ().joints )
132133 {
133- // populate non-standard command interfaces to other_interfaces_
134- populate_non_standard_interfaces (joint.command_interfaces , other_interfaces_ );
134+ // populate non-standard command interfaces to other_interfaces
135+ populate_non_standard_interfaces (joint.command_interfaces , other_interfaces );
135136
136- // populate non-standard state interfaces to other_interfaces_
137- populate_non_standard_interfaces (joint.state_interfaces , other_interfaces_ );
137+ // populate non-standard state interfaces to other_interfaces
138+ populate_non_standard_interfaces (joint.state_interfaces , other_interfaces );
138139 }
139140
140141 // when following offset is used on custom interface then find its index
141142 if (!custom_interface_with_following_offset_.empty ())
142143 {
143- auto if_it = std::find (
144- other_interfaces_.begin (), other_interfaces_.end (), custom_interface_with_following_offset_);
145- if (if_it != other_interfaces_.end ())
144+ if (
145+ std::find (
146+ other_interfaces.begin (), other_interfaces.end (),
147+ custom_interface_with_following_offset_) != other_interfaces.end ())
146148 {
147149 RCLCPP_INFO (
148150 get_logger (), " Custom interface with following offset '%s' found." ,
@@ -157,19 +159,6 @@ CallbackReturn GenericSystem::on_init(
157159 }
158160 }
159161
160- for (const auto & sensor : get_hardware_info ().sensors )
161- {
162- for (const auto & interface : sensor.state_interfaces )
163- {
164- if (
165- std::find (sensor_interfaces_.begin (), sensor_interfaces_.end (), interface.name ) ==
166- sensor_interfaces_.end ())
167- {
168- sensor_interfaces_.emplace_back (interface.name );
169- }
170- }
171- }
172-
173162 return CallbackReturn::SUCCESS;
174163}
175164
@@ -231,26 +220,10 @@ return_type GenericSystem::prepare_command_mode_switch(
231220 }
232221 if (key == info.joints [joint_index].name + " /" + hardware_interface::HW_IF_VELOCITY)
233222 {
234- if (!calculate_dynamics_)
235- {
236- RCLCPP_WARN (
237- get_logger (),
238- " Requested velocity mode for joint '%s' without dynamics calculation enabled - this "
239- " might lead to wrong feedback and unexpected behavior." ,
240- info.joints [joint_index].name .c_str ());
241- }
242223 joint_found_in_x_requests_[joint_index] += 1 ;
243224 }
244225 if (key == info.joints [joint_index].name + " /" + hardware_interface::HW_IF_ACCELERATION)
245226 {
246- if (!calculate_dynamics_)
247- {
248- RCLCPP_WARN (
249- get_logger (),
250- " Requested acceleration mode for joint '%s' without dynamics calculation enabled - "
251- " this might lead to wrong feedback and unexpected behavior." ,
252- info.joints [joint_index].name .c_str ());
253- }
254227 joint_found_in_x_requests_[joint_index] += 1 ;
255228 }
256229 }
@@ -412,14 +385,13 @@ return_type GenericSystem::read(const rclcpp::Time & /*time*/, const rclcpp::Dur
412385 for (size_t i = 0 ; i < 3 ; ++i)
413386 {
414387 const auto full_name = joint_name + " /" + standard_interfaces_[i];
415- if (joint_command_interfaces_. find (full_name) != joint_command_interfaces_. end ( ))
388+ if (has_command (full_name))
416389 {
417- joint_command_values_[i] =
418- get_command (joint_command_interfaces_.at (full_name).get_name ());
390+ joint_command_values_[i] = get_command (full_name);
419391 }
420- if (joint_state_interfaces_. find (full_name) != joint_state_interfaces_. end ( ))
392+ if (has_state (full_name))
421393 {
422- joint_state_values_[i] = get_state (joint_state_interfaces_. at ( full_name). get_name () );
394+ joint_state_values_[i] = get_state (full_name);
423395 }
424396 }
425397
@@ -513,7 +485,7 @@ return_type GenericSystem::read(const rclcpp::Time & /*time*/, const rclcpp::Dur
513485 if (joint_command.get ()->get_interface_name () == hardware_interface::HW_IF_POSITION)
514486 {
515487 const std::string & name = joint_command.get ()->get_name ();
516- if (joint_state_interfaces_. find (name) != joint_state_interfaces_. end ( ))
488+ if (has_state (name))
517489 {
518490 set_state (
519491 name, get_command (name) + (custom_interface_with_following_offset_.empty ()
@@ -536,7 +508,7 @@ return_type GenericSystem::read(const rclcpp::Time & /*time*/, const rclcpp::Dur
536508 continue ;
537509 }
538510 const std::string & full_interface_name = joint_state.get ()->get_name ();
539- if (joint_command_interfaces_. find (full_interface_name) != joint_command_interfaces_. end ( ))
511+ if (has_command (full_interface_name))
540512 {
541513 if (
542514 mirror_command_to_state (full_interface_name, joint_state.get ()->get_data_type ()) !=
@@ -561,29 +533,22 @@ return_type GenericSystem::read(const rclcpp::Time & /*time*/, const rclcpp::Dur
561533 {
562534 const auto & mimic_joint_name = joints.at (mimic_joint.joint_index ).name ;
563535 const auto & mimicked_joint_name = joints.at (mimic_joint.mimicked_joint_index ).name ;
564- if (
565- joint_state_interfaces_.find (mimic_joint_name + " /" + hardware_interface::HW_IF_POSITION) !=
566- joint_state_interfaces_.end ())
536+ if (has_state (mimic_joint_name + " /" + hardware_interface::HW_IF_POSITION))
567537 {
568538 set_state (
569539 mimic_joint_name + " /" + hardware_interface::HW_IF_POSITION,
570540 mimic_joint.offset +
571541 mimic_joint.multiplier *
572542 get_state (mimicked_joint_name + " /" + hardware_interface::HW_IF_POSITION));
573543 }
574- if (
575- joint_state_interfaces_.find (mimic_joint_name + " /" + hardware_interface::HW_IF_VELOCITY) !=
576- joint_state_interfaces_.end ())
544+ if (has_state (mimic_joint_name + " /" + hardware_interface::HW_IF_VELOCITY))
577545 {
578546 set_state (
579547 mimic_joint_name + " /" + hardware_interface::HW_IF_VELOCITY,
580548 mimic_joint.multiplier *
581549 get_state (mimicked_joint_name + " /" + hardware_interface::HW_IF_VELOCITY));
582550 }
583- if (
584- joint_state_interfaces_.find (
585- mimic_joint_name + " /" + hardware_interface::HW_IF_ACCELERATION) !=
586- joint_state_interfaces_.end ())
551+ if (has_state (mimic_joint_name + " /" + hardware_interface::HW_IF_ACCELERATION))
587552 {
588553 set_state (
589554 mimic_joint_name + " /" + hardware_interface::HW_IF_ACCELERATION,
@@ -624,7 +589,7 @@ return_type GenericSystem::read(const rclcpp::Time & /*time*/, const rclcpp::Dur
624589 for (const auto & gpio_command : gpio_commands_)
625590 {
626591 const std::string & name = gpio_command.get ()->get_name ();
627- if (gpio_state_interfaces_. find (name) != gpio_state_interfaces_. end ( ))
592+ if (has_state (name))
628593 {
629594 if (mirror_command_to_state (name, gpio_command.get ()->get_data_type ()) != return_type::OK)
630595 {
0 commit comments