41#include <rclcpp/logger.hpp>
42#include <rclcpp/logging.hpp>
56 return trajectory.joint_trajectory.points.empty() && trajectory.multi_dof_joint_trajectory.points.empty();
61 return std::max(trajectory.joint_trajectory.points.size(), trajectory.multi_dof_joint_trajectory.points.size());
64 double acceleration_scaling_factor,
double path_tolerance,
double resample_dt,
65 double min_angle_change)
68 return totg.
computeTimeStamps(trajectory, velocity_scaling_factor, acceleration_scaling_factor);
71 double acceleration_scaling_factor,
bool mitigate_overshoot,
double overshoot_threshold)
74 return time_param.
applySmoothing(trajectory, velocity_scaling_factor, acceleration_scaling_factor, mitigate_overshoot,
80 const int sampling_rate)
82 trajectory_msgs::msg::JointTrajectory trajectory_msg;
83 if (sampling_rate <= 0)
85 RCLCPP_ERROR(getLogger(),
"Cannot sample trajectory with sampling rate <= 0. Returning empty trajectory.");
86 return trajectory_msg;
88 trajectory_msg.joint_names = joint_names;
89 const double time_step = 1.0 /
static_cast<double>(sampling_rate);
90 const int n_samples =
static_cast<int>(std::ceil(trajectory.
getDuration() / time_step)) + 1;
91 trajectory_msg.points.reserve(n_samples);
92 for (
int sample = 0; sample < n_samples; ++sample)
94 const double t = sample * time_step;
95 trajectory_msgs::msg::JointTrajectoryPoint point;
99 for (std::size_t i = 0; i < joint_names.size(); i++)
101 point.positions.push_back(position[i]);
102 point.velocities.push_back(velocity[i]);
103 point.accelerations.push_back(acceleration[i]);
105 point.time_from_start = rclcpp::Duration(std::chrono::duration<double>(t));
106 trajectory_msg.points.push_back(std::move(point));
108 return trajectory_msg;
Maintain a sequence of waypoints and the time durations between these waypoints.
static bool applySmoothing(robot_trajectory::RobotTrajectory &trajectory, const double max_velocity_scaling_factor=1.0, const double max_acceleration_scaling_factor=1.0, const bool mitigate_overshoot=false, const double overshoot_threshold=0.01)
Apply smoothing to a time-parameterized trajectory so that jerk limits are not violated.
bool computeTimeStamps(robot_trajectory::RobotTrajectory &trajectory, const double max_velocity_scaling_factor=1.0, const double max_acceleration_scaling_factor=1.0) const override
Compute a trajectory with waypoints spaced equally in time (according to resample_dt_)....
Eigen::VectorXd getAcceleration(double time) const
Return the acceleration vector for a given point in time.
Eigen::VectorXd getPosition(double time) const
Return the position/configuration vector for a given point in time.
double getDuration() const
Returns the optimal duration of the trajectory.
Eigen::VectorXd getVelocity(double time) const
Return the velocity vector for a given point in time.
rclcpp::Logger getLogger()
rclcpp::Logger getLogger(const std::string &name)
Creates a namespaced logger.
bool applyTOTGTimeParameterization(robot_trajectory::RobotTrajectory &trajectory, double velocity_scaling_factor, double acceleration_scaling_factor, double path_tolerance=0.1, double resample_dt=0.1, double min_angle_change=0.001)
Applies time parameterization to a robot trajectory using the Time-Optimal Trajectory Generation (TOT...
bool applyRuckigSmoothing(robot_trajectory::RobotTrajectory &trajectory, double velocity_scaling_factor, double acceleration_scaling_factor, bool mitigate_overshoot=false, double overshoot_threshold=0.01)
Applies Ruckig smoothing to a robot trajectory.
trajectory_msgs::msg::JointTrajectory createTrajectoryMessage(const std::vector< std::string > &joint_names, const trajectory_processing::Trajectory &trajectory, const int sampling_rate)
Converts a trajectory_processing::Trajectory into a JointTrajectory message with a given sampling rat...
bool isTrajectoryEmpty(const moveit_msgs::msg::RobotTrajectory &trajectory)
Checks if a robot trajectory is empty.
std::size_t trajectoryWaypointCount(const moveit_msgs::msg::RobotTrajectory &trajectory)
Returns the number of waypoints in a robot trajectory.