Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions joint_trajectory_controller/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ set(THIS_PACKAGE_INCLUDE_DEPENDS
rclcpp_lifecycle
realtime_tools
rsl
tl_expected
trajectory_msgs
urdf
)
Expand All @@ -37,7 +36,6 @@ 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)
Expand All @@ -58,7 +56,6 @@ target_link_libraries(joint_trajectory_controller PUBLIC
rclcpp_lifecycle::rclcpp_lifecycle
realtime_tools::realtime_tools
rsl::rsl
tl_expected::tl_expected
urdf::urdf
angles::angles
${trajectory_msgs_TARGETS}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,83 @@

#include "rclcpp/parameter.hpp"
#include "rsl/algorithm.hpp"
#include "tl_expected/expected.hpp"
#include "tl/expected.hpp"

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<void, std::string> An empty expected on success, or an error message on
* failure.
*/
tl::expected<void, std::string> 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<void, std::string> An empty expected on success, or an error message on
* failure.
*/
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<std::vector<std::string>>(interface_types, "velocity") &&
interface_types.size() > 1 &&
!rsl::contains<std::vector<std::string>>(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<std::vector<std::string>>(interface_types, "acceleration") &&
(!rsl::contains<std::vector<std::string>>(interface_types, "velocity") &&
!rsl::contains<std::vector<std::string>>(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<std::vector<std::string>>(interface_types, "effort") &&
!(interface_types.size() == 1 ||
(interface_types.size() == 2 &&
rsl::contains<std::vector<std::string>>(interface_types, "position"))))
{
return tl::make_unexpected(
"'effort' command interface has to be used alone or with a 'position' interface");
}

return {};
}

tl::expected<void, std::string> state_interface_type_combinations(
rclcpp::Parameter const & parameter);
rclcpp::Parameter const & parameter)
{
auto const & interface_types = parameter.as_string_array();

// Valid combinations are
// 1. position [velocity, [acceleration]]

if (
rsl::contains<std::vector<std::string>>(interface_types, "velocity") &&
!rsl::contains<std::vector<std::string>>(interface_types, "position"))
{
return tl::make_unexpected(
"'velocity' state interface cannot be used if 'position' interface "
"is missing.");
}

if (
rsl::contains<std::vector<std::string>>(interface_types, "acceleration") &&
(!rsl::contains<std::vector<std::string>>(interface_types, "position") ||
!rsl::contains<std::vector<std::string>>(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

Expand Down
2 changes: 1 addition & 1 deletion joint_trajectory_controller/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
<depend>control_toolbox</depend>
<depend>generate_parameter_library</depend>
<depend>hardware_interface</depend>
<depend>libexpected-dev</depend>
<depend>pluginlib</depend>
<depend>rclcpp</depend>
<depend>rclcpp_action</depend>
<depend>rclcpp_lifecycle</depend>
<depend>realtime_tools</depend>
<depend>rsl</depend>
<depend>tl_expected</depend>
<depend>trajectory_msgs</depend>
<depend>urdf</depend>

Expand Down
94 changes: 0 additions & 94 deletions joint_trajectory_controller/src/validate_jtc_parameters.cpp

This file was deleted.

Loading