Skip to content

Commit 0e2a43a

Browse files
author
bailaC
authored
Fixing issue : 114 (#259)
* Fixing issue : 114 * Addressing review comments.
1 parent 37015b4 commit 0e2a43a

File tree

2 files changed

+5
-48
lines changed

2 files changed

+5
-48
lines changed

‎forward_command_controller/src/forward_command_controller.cpp‎

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <utility>
2121
#include <vector>
2222

23+
#include "controller_interface/helpers.hpp"
2324
#include "rclcpp/logging.hpp"
2425
#include "rclcpp/qos.hpp"
2526

@@ -105,37 +106,14 @@ ForwardCommandController::state_interface_configuration() const
105106
controller_interface::interface_configuration_type::NONE};
106107
}
107108

108-
// Fill ordered_interfaces with references to the matching interfaces
109-
// in the same order as in joint_names
110-
template <typename T>
111-
bool get_ordered_interfaces(
112-
std::vector<T> & unordered_interfaces, const std::vector<std::string> & joint_names,
113-
const std::string & interface_type, std::vector<std::reference_wrapper<T>> & ordered_interfaces)
114-
{
115-
for (const auto & joint_name : joint_names)
116-
{
117-
for (auto & command_interface : unordered_interfaces)
118-
{
119-
if (
120-
(command_interface.get_name() == joint_name) &&
121-
(command_interface.get_interface_name() == interface_type))
122-
{
123-
ordered_interfaces.push_back(std::ref(command_interface));
124-
}
125-
}
126-
}
127-
128-
return joint_names.size() == ordered_interfaces.size();
129-
}
130-
131109
CallbackReturn ForwardCommandController::on_activate(
132110
const rclcpp_lifecycle::State & /*previous_state*/)
133111
{
134112
// check if we have all resources defined in the "points" parameter
135113
// also verify that we *only* have the resources defined in the "points" parameter
136114
std::vector<std::reference_wrapper<LoanedCommandInterface>> ordered_interfaces;
137115
if (
138-
!get_ordered_interfaces(
116+
!controller_interface::get_ordered_interfaces(
139117
command_interfaces_, joint_names_, interface_name_, ordered_interfaces) ||
140118
command_interfaces_.size() != ordered_interfaces.size())
141119
{

‎joint_trajectory_controller/src/joint_trajectory_controller.cpp‎

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "angles/angles.h"
2727
#include "builtin_interfaces/msg/duration.hpp"
2828
#include "builtin_interfaces/msg/time.hpp"
29+
#include "controller_interface/helpers.hpp"
2930
#include "hardware_interface/types/hardware_interface_return_values.hpp"
3031
#include "hardware_interface/types/hardware_interface_type_values.hpp"
3132
#include "joint_trajectory_controller/trajectory.hpp"
@@ -697,28 +698,6 @@ CallbackReturn JointTrajectoryController::on_configure(const rclcpp_lifecycle::S
697698
return CallbackReturn::SUCCESS;
698699
}
699700

700-
// Fill ordered_interfaces with references to the matching interfaces
701-
// in the same order as in joint_names
702-
template <typename T>
703-
bool get_ordered_interfaces(
704-
std::vector<T> & unordered_interfaces, const std::vector<std::string> & joint_names,
705-
const std::string & interface_type, std::vector<std::reference_wrapper<T>> & ordered_interfaces)
706-
{
707-
for (const auto & joint_name : joint_names)
708-
{
709-
for (auto & interface : unordered_interfaces)
710-
{
711-
if (
712-
(interface.get_name() == joint_name) && (interface.get_interface_name() == interface_type))
713-
{
714-
ordered_interfaces.emplace_back(std::ref(interface));
715-
}
716-
}
717-
}
718-
719-
return joint_names.size() == ordered_interfaces.size();
720-
}
721-
722701
CallbackReturn JointTrajectoryController::on_activate(const rclcpp_lifecycle::State &)
723702
{
724703
// order all joints in the storage
@@ -727,7 +706,7 @@ CallbackReturn JointTrajectoryController::on_activate(const rclcpp_lifecycle::St
727706
auto it =
728707
std::find(allowed_interface_types_.begin(), allowed_interface_types_.end(), interface);
729708
auto index = std::distance(allowed_interface_types_.begin(), it);
730-
if (!get_ordered_interfaces(
709+
if (!controller_interface::get_ordered_interfaces(
731710
command_interfaces_, joint_names_, interface, joint_command_interface_[index]))
732711
{
733712
RCLCPP_ERROR(
@@ -741,7 +720,7 @@ CallbackReturn JointTrajectoryController::on_activate(const rclcpp_lifecycle::St
741720
auto it =
742721
std::find(allowed_interface_types_.begin(), allowed_interface_types_.end(), interface);
743722
auto index = std::distance(allowed_interface_types_.begin(), it);
744-
if (!get_ordered_interfaces(
723+
if (!controller_interface::get_ordered_interfaces(
745724
state_interfaces_, joint_names_, interface, joint_state_interface_[index]))
746725
{
747726
RCLCPP_ERROR(

0 commit comments

Comments
 (0)