From 1d214b4aca9702d1d0a22f2b5c3b91b95cc3046b Mon Sep 17 00:00:00 2001 From: Surya Date: Sun, 25 Jan 2026 10:41:14 +0530 Subject: [PATCH 1/3] refactor(jtc): fixed jtc params validation Previously validate_jtc_parameters defined validation functions in the header file but didn't marked them with inline. This caused errors when we try to use it in more than one header file. While I was refactoring other files I got the linker error, so seperated the declaration and definitions. --- joint_trajectory_controller/CMakeLists.txt | 1 + .../validate_jtc_parameters.hpp | 87 ++++------------- .../src/validate_jtc_parameters.cpp | 96 +++++++++++++++++++ 3 files changed, 113 insertions(+), 71 deletions(-) create mode 100644 joint_trajectory_controller/src/validate_jtc_parameters.cpp diff --git a/joint_trajectory_controller/CMakeLists.txt b/joint_trajectory_controller/CMakeLists.txt index 5efdd52886..aede22d0ee 100644 --- a/joint_trajectory_controller/CMakeLists.txt +++ b/joint_trajectory_controller/CMakeLists.txt @@ -37,6 +37,7 @@ generate_parameter_library(joint_trajectory_controller_parameters add_library(joint_trajectory_controller SHARED src/joint_trajectory_controller.cpp src/trajectory.cpp + src/validate_jtc_parameters.cpp ) target_compile_features(joint_trajectory_controller PUBLIC cxx_std_17) if(WIN32) diff --git a/joint_trajectory_controller/include/joint_trajectory_controller/validate_jtc_parameters.hpp b/joint_trajectory_controller/include/joint_trajectory_controller/validate_jtc_parameters.hpp index e0cb4313d5..9e4f315f5f 100644 --- a/joint_trajectory_controller/include/joint_trajectory_controller/validate_jtc_parameters.hpp +++ b/joint_trajectory_controller/include/joint_trajectory_controller/validate_jtc_parameters.hpp @@ -24,79 +24,24 @@ namespace joint_trajectory_controller { -tl::expected command_interface_type_combinations( - rclcpp::Parameter const & parameter) -{ - auto const & interface_types = parameter.as_string_array(); - - // Check if command interfaces combination is valid. Valid combinations are: - // 1. effort - // 2. velocity - // 3. position [velocity, [acceleration]] - // 4. position, effort - - if ( - rsl::contains>(interface_types, "velocity") && - interface_types.size() > 1 && - !rsl::contains>(interface_types, "position")) - { - return tl::make_unexpected( - "'velocity' command interface can be used either alone or 'position' " - "command interface has to be present"); - } - - if ( - rsl::contains>(interface_types, "acceleration") && - (!rsl::contains>(interface_types, "velocity") && - !rsl::contains>(interface_types, "position"))) - { - return tl::make_unexpected( - "'acceleration' command interface can only be used if 'velocity' and " - "'position' command interfaces are present"); - } - - if ( - rsl::contains>(interface_types, "effort") && - !(interface_types.size() == 1 || - (interface_types.size() == 2 && - rsl::contains>(interface_types, "position")))) - { - return tl::make_unexpected( - "'effort' command interface has to be used alone or with a 'position' interface"); - } - - return {}; -} +/** + * \brief Validate command interface type combinations for joint trajectory controller. + * + * \param[in] parameter The rclcpp parameter containing the command interface types. + * \return tl::expected An empty expected on success, or an error message on failure. + */ +tl::expected command_interface_type_combinations( + rclcpp::Parameter const & parameter); + +/** + * \brief Validate state interface type combinations for joint trajectory controller. + * + * \param[in] parameter The rclcpp parameter containing the state interface types. + * \return tl::expected An empty expected on success, or an error message on failure. + */ tl::expected state_interface_type_combinations( - rclcpp::Parameter const & parameter) -{ - auto const & interface_types = parameter.as_string_array(); - - // Valid combinations are - // 1. position [velocity, [acceleration]] - - if ( - rsl::contains>(interface_types, "velocity") && - !rsl::contains>(interface_types, "position")) - { - return tl::make_unexpected( - "'velocity' state interface cannot be used if 'position' interface " - "is missing."); - } - - if ( - rsl::contains>(interface_types, "acceleration") && - (!rsl::contains>(interface_types, "position") || - !rsl::contains>(interface_types, "velocity"))) - { - return tl::make_unexpected( - "'acceleration' state interface cannot be used if 'position' and 'velocity' " - "interfaces are not present."); - } - - return {}; -} + rclcpp::Parameter const & parameter); } // namespace joint_trajectory_controller diff --git a/joint_trajectory_controller/src/validate_jtc_parameters.cpp b/joint_trajectory_controller/src/validate_jtc_parameters.cpp new file mode 100644 index 0000000000..f5186fdebb --- /dev/null +++ b/joint_trajectory_controller/src/validate_jtc_parameters.cpp @@ -0,0 +1,96 @@ +// Copyright (c) 2022 ros2_control Development Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "joint_trajectory_controller/validate_jtc_parameters.hpp" + +namespace joint_trajectory_controller +{ + +tl::expected command_interface_type_combinations( + rclcpp::Parameter const & parameter) +{ + auto const & interface_types = parameter.as_string_array(); + + // Check if command interfaces combination is valid. Valid combinations are: + // 1. effort + // 2. velocity + // 3. position [velocity, [acceleration]] + // 4. position, effort + + if ( + rsl::contains>(interface_types, "velocity") && + interface_types.size() > 1 && + !rsl::contains>(interface_types, "position")) + { + return tl::make_unexpected( + "'velocity' command interface can be used either alone or 'position' " + "command interface has to be present"); + } + + if ( + rsl::contains>(interface_types, "acceleration") && + (!rsl::contains>(interface_types, "velocity") && + !rsl::contains>(interface_types, "position"))) + { + return tl::make_unexpected( + "'acceleration' command interface can only be used if 'velocity' and " + "'position' command interfaces are present"); + } + + if ( + rsl::contains>(interface_types, "effort") && + !(interface_types.size() == 1 || + (interface_types.size() == 2 && + rsl::contains>(interface_types, "position")))) + { + return tl::make_unexpected( + "'effort' command interface has to be used alone or with a 'position' interface"); + } + + return {}; +} + +tl::expected state_interface_type_combinations( + rclcpp::Parameter const & parameter) +{ + auto const & interface_types = parameter.as_string_array(); + + // Valid combinations are + // 1. position [velocity, [acceleration]] + + if ( + rsl::contains>(interface_types, "velocity") && + !rsl::contains>(interface_types, "position")) + { + return tl::make_unexpected( + "'velocity' state interface cannot be used if 'position' interface " + "is missing."); + } + + if ( + rsl::contains>(interface_types, "acceleration") && + (!rsl::contains>(interface_types, "position") || + !rsl::contains>(interface_types, "velocity"))) + { + return tl::make_unexpected( + "'acceleration' state interface cannot be used if 'position' and 'velocity' " + "interfaces are not present."); + } + + return {}; +} + +} // namespace joint_trajectory_controller + +#endif // JOINT_TRAJECTORY_CONTROLLER__VALIDATE_JTC_PARAMETERS_HPP_ From ee358e3bd3ac533074b1118e11c44460c5e2c6a8 Mon Sep 17 00:00:00 2001 From: Surya Date: Sun, 25 Jan 2026 10:57:02 +0530 Subject: [PATCH 2/3] fix(jtc): header guards --- joint_trajectory_controller/src/validate_jtc_parameters.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/joint_trajectory_controller/src/validate_jtc_parameters.cpp b/joint_trajectory_controller/src/validate_jtc_parameters.cpp index f5186fdebb..1a186ffc6a 100644 --- a/joint_trajectory_controller/src/validate_jtc_parameters.cpp +++ b/joint_trajectory_controller/src/validate_jtc_parameters.cpp @@ -92,5 +92,3 @@ tl::expected state_interface_type_combinations( } } // namespace joint_trajectory_controller - -#endif // JOINT_TRAJECTORY_CONTROLLER__VALIDATE_JTC_PARAMETERS_HPP_ From 40bfcf91216478a833a27a4e43539a9bce3d019a Mon Sep 17 00:00:00 2001 From: Surya Date: Sun, 25 Jan 2026 11:45:08 +0530 Subject: [PATCH 3/3] docs(jtc): fix comments via pre-commit --- .../validate_jtc_parameters.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/joint_trajectory_controller/include/joint_trajectory_controller/validate_jtc_parameters.hpp b/joint_trajectory_controller/include/joint_trajectory_controller/validate_jtc_parameters.hpp index 9e4f315f5f..f9dfb7543b 100644 --- a/joint_trajectory_controller/include/joint_trajectory_controller/validate_jtc_parameters.hpp +++ b/joint_trajectory_controller/include/joint_trajectory_controller/validate_jtc_parameters.hpp @@ -29,16 +29,18 @@ namespace joint_trajectory_controller * \brief Validate command interface type combinations for joint trajectory controller. * * \param[in] parameter The rclcpp parameter containing the command interface types. - * \return tl::expected An empty expected on success, or an error message on failure. + * \return tl::expected An empty expected on success, or an error message on + * failure. */ tl::expected command_interface_type_combinations( rclcpp::Parameter const & parameter); /** * \brief Validate state interface type combinations for joint trajectory controller. - * + * * \param[in] parameter The rclcpp parameter containing the state interface types. - * \return tl::expected An empty expected on success, or an error message on failure. + * \return tl::expected An empty expected on success, or an error message on + * failure. */ tl::expected state_interface_type_combinations( rclcpp::Parameter const & parameter);