Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1199a54
Refactor: interpolation_method.hpp
thedevmystic Nov 21, 2025
011ca30
Refactor: Changed InterpolationMap to ReverseInterpolationMap to refl…
thedevmystic Nov 21, 2025
f211ae9
Merge branch 'master' into joint-trajectory-controller-refactor
thedevmystic Nov 21, 2025
1c8a66f
Merge branch 'master' into joint-trajectory-controller-refactor
thedevmystic Nov 22, 2025
dfe48b9
Refactor: Fixed pre-commit stylistic issues.
thedevmystic Nov 24, 2025
ce2a7d9
Merge branch 'joint-trajectory-controller-refactor' of github.com:The…
thedevmystic Nov 24, 2025
84975fd
Refactor: Changed ReverseInterpolationMethodMap lookup to interpolati…
thedevmystic Nov 24, 2025
e4922c8
Remove: Removed redundant ReverseInterpolationMethodMap.
thedevmystic Nov 24, 2025
1ec2608
Refactor: Fixed Stylistic Inconsistency.
thedevmystic Nov 24, 2025
2aec5a0
Update joint_trajectory_controller/include/joint_trajectory_controlle…
thedevmystic Nov 24, 2025
f5f4c0d
Update joint_trajectory_controller/include/joint_trajectory_controlle…
thedevmystic Nov 24, 2025
8f2257b
Add pre-commit fixes
saikishor Nov 24, 2025
a256bc1
Refactor: Changed RCLCPP_INFO to RCLCPP_WARN.
thedevmystic Nov 25, 2025
3a54333
Addition: Lowercase conversion function for case-agnostic checking.
thedevmystic Nov 25, 2025
1d9fd74
Refactor: Fixed minor stylistic issues.
thedevmystic Nov 25, 2025
dcc31af
Addition: Added to_string function.
thedevmystic Nov 25, 2025
e685997
Fixed pre-commit failures.
thedevmystic Nov 25, 2025
d0ba3f1
Refactor: Fixed whitespace spacing.
thedevmystic Nov 25, 2025
2b1d3fa
Addition: Added to_string function.
thedevmystic Nov 25, 2025
bc53617
Addition: Added warning for unknown value in to_string function.
thedevmystic Nov 25, 2025
6a98061
Addition: Added warning for unknown value in to_string function.
thedevmystic Nov 25, 2025
712d588
Addition: Added warning for unknown value in to_string function.
thedevmystic Nov 25, 2025
6085b05
Doc: Fixed grammatic mistakes and polished the documentation.
thedevmystic Nov 25, 2025
84f4cac
Remove: Removed helper convert_to_lowercase function.
thedevmystic Nov 26, 2025
fcb7832
Refactor: Refactored from_string to directly use string comparision.
thedevmystic Nov 26, 2025
185e9d1
Refactor: Fixed pre-commit stylistic issues.
thedevmystic Nov 26, 2025
19c353b
Merge branch 'test/jtc' of github.com:TheDevMystic/ros2_controllers i…
thedevmystic Nov 26, 2025
bc81c92
Refactor: Readded InterpolationMethodMap, and deprecated it, in favou…
thedevmystic Nov 28, 2025
9f4309a
Refactor: Fixed documentations.
thedevmystic Nov 29, 2025
e07b712
Refactor: Fixed documentations.
thedevmystic Nov 29, 2025
5d5e962
Merge branch 'master' into joint-trajectory-controller-refactor
thedevmystic Nov 29, 2025
ce2f2db
Doc: Fixed grammatic mistakes.
thedevmystic Nov 29, 2025
d502dd3
Merge branch 'joint-trajectory-controller-refactor' of github.com:The…
thedevmystic Nov 29, 2025
7f2790f
Doc: Fixed deprecated message.
thedevmystic Nov 29, 2025
8af0833
Doc: Fixed wording of depreciation of InterpolationMethodMap.
thedevmystic Dec 1, 2025
db8f06a
Doc: Removed Linear Interpolation Advise.
thedevmystic Dec 1, 2025
bbe3bb7
Merge branch 'master' into joint-trajectory-controller-refactor
thedevmystic Dec 1, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,134 @@
#include <string>
#include <unordered_map>

#include "hardware_interface/lexical_casts.hpp"
#include "rclcpp/rclcpp.hpp"

namespace joint_trajectory_controller
{

/// \brief Setup interpolation_methods' rclcpp::Logger instance.
static const rclcpp::Logger LOGGER =
rclcpp::get_logger("joint_trajectory_controller.interpolation_methods");

namespace interpolation_methods
{

/**
* \brief Defines the available interpolation methods used for fitting data curves.
* This enumeration specifies how intermediate values between data points
* should be calculated.
*/
enum class InterpolationMethod
{
/**
* \brief No interpolation is performed.
* This is typically used when data points are discrete and should not be
* connected by a curve.
*
* It returns the initial point until the time for the first trajectory data
* point is reached. Then, it simply takes the next given datapoint.
*/
NONE,

/**
* \brief Uses a variable-degree spline interpolation.
* The degree of the spline is determined dynamically based on the number of
* available derivatives. This provides a smooth, continuous curve between data points.
*
* Based on available derivatives, it uses the following degree interpolation,
* 1. If only position is available: `Linear Interpolation`.
* 2. If position, and velocity are available: `Cubic Spline Interpolation`.
* 3. If position, velocity, and acceleration are available: `Quintic Spline Interpolation`.
*/
VARIABLE_DEGREE_SPLINE
};

/**
* \brief The default interpolation method is set to `InterpolationMethod::VARIABLE_DEGREE_SPLINE`.
* As it provides the most realistic, jerk-free and smooth motion.
*/
const InterpolationMethod DEFAULT_INTERPOLATION = InterpolationMethod::VARIABLE_DEGREE_SPLINE;

const std::unordered_map<InterpolationMethod, std::string> InterpolationMethodMap(
{{InterpolationMethod::NONE, "none"}, {InterpolationMethod::VARIABLE_DEGREE_SPLINE, "splines"}});
/**
* @brief Maps string representations to their corresponding InterpolationMethod enum values.
*
* @deprecated This map is deprecated. Use the direct lookup methods instead.
* (Original use: Converting strings into the InterpolationMethod).
*/
[[deprecated(
"InterpolationMethodMap will be removed in future releases. "
"Instead, use the direct lookup methods.")]]
const std::unordered_map<std::string, InterpolationMethod> InterpolationMethodMap(
{{"none", InterpolationMethod::NONE}, {"splines", InterpolationMethod::VARIABLE_DEGREE_SPLINE}});

/**
* \brief Returns corresponding string value for the `InterpolationMethod`.
* This function uses simple switch-case lookup to directly assign string value to
* `InterpolationMethod`.
*
* \param[in] interpolation_method The InterpolationMethod enum value.
*
* \returns The corresponding string.
*
* \note Defaults to return "UNKNOWN".
*/
[[nodiscard]] inline std::string to_string(const InterpolationMethod & interpolation_method)
{
switch (interpolation_method)
{
case InterpolationMethod::NONE:
return "none";
case InterpolationMethod::VARIABLE_DEGREE_SPLINE:
return "splines";
// Default
default:
RCLCPP_WARN(
LOGGER,
"Unknown interpolation method enum value was given. Returning default: "
"UNKNOWN");
return "UNKNOWN";
}
}

/**
* \brief Creates a `InterpolationMethod` enum class value from a string.
* This function directly looks up for corresponding `InterpolationMethod` based
* on interpolation_method string (case-agnostic).
*
* \param[in] interpolation_method The given interpolation method string.
*
* \returns The corresponding InterpolationMethod.
*
* \note If interpolation_method does not have any corresponding InterpolationMethod
* (i.e., "Unknown"), it defaults to `DEFAULT_INTERPOLATION`.
*/
[[nodiscard]] inline InterpolationMethod from_string(const std::string & interpolation_method)
{
if (interpolation_method.compare(InterpolationMethodMap.at(InterpolationMethod::NONE)) == 0)
// Convert to lowercase, so we have a case-agnostic checking,
// (i.e., "None, NONE, and none" are treated same.)
std::string method = ::hardware_interface::to_lower_case(interpolation_method);

if (method == "none")
{
return InterpolationMethod::NONE;
}
else if (
interpolation_method.compare(
InterpolationMethodMap.at(InterpolationMethod::VARIABLE_DEGREE_SPLINE)) == 0)
else if (method == "splines")
{
return InterpolationMethod::VARIABLE_DEGREE_SPLINE;
}
// Default
else
{
RCLCPP_INFO(
RCLCPP_WARN(
LOGGER,
"No interpolation method parameter was given. Using the default, VARIABLE_DEGREE_SPLINE.");
return InterpolationMethod::VARIABLE_DEGREE_SPLINE;
"Unknown interpolation method parameter '%s' was given. Using the default: "
"DEFAULT_INTERPOLATION (%s).",
interpolation_method.c_str(), to_string(DEFAULT_INTERPOLATION).c_str());
return DEFAULT_INTERPOLATION;
}
}

} // namespace interpolation_methods
} // namespace joint_trajectory_controller

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -940,9 +940,7 @@ controller_interface::CallbackReturn JointTrajectoryController::on_configure(
const std::string interpolation_string =
get_node()->get_parameter("interpolation_method").as_string();
interpolation_method_ = interpolation_methods::from_string(interpolation_string);
RCLCPP_INFO(
logger, "Using '%s' interpolation method.",
interpolation_methods::InterpolationMethodMap.at(interpolation_method_).c_str());
RCLCPP_INFO(logger, "Using '%s' interpolation method.", interpolation_string.c_str());

// prepare hold_position_msg
init_hold_position_msg();
Expand Down