15 #ifndef JOINT_TRAJECTORY_CONTROLLER__TRAJECTORY_HPP_
16 #define JOINT_TRAJECTORY_CONTROLLER__TRAJECTORY_HPP_
21 #include "joint_trajectory_controller/interpolation_methods.hpp"
22 #include "joint_trajectory_controller/visibility_control.h"
23 #include "rclcpp/time.hpp"
24 #include "trajectory_msgs/msg/joint_trajectory.hpp"
25 #include "trajectory_msgs/msg/joint_trajectory_point.hpp"
28 using TrajectoryPointIter = std::vector<trajectory_msgs::msg::JointTrajectoryPoint>::iterator;
29 using TrajectoryPointConstIter =
30 std::vector<trajectory_msgs::msg::JointTrajectoryPoint>::const_iterator;
35 JOINT_TRAJECTORY_CONTROLLER_PUBLIC
38 JOINT_TRAJECTORY_CONTROLLER_PUBLIC
39 explicit Trajectory(std::shared_ptr<trajectory_msgs::msg::JointTrajectory> joint_trajectory);
41 JOINT_TRAJECTORY_CONTROLLER_PUBLIC
43 const rclcpp::Time & current_time,
44 const trajectory_msgs::msg::JointTrajectoryPoint & current_point,
45 std::shared_ptr<trajectory_msgs::msg::JointTrajectory> joint_trajectory);
55 JOINT_TRAJECTORY_CONTROLLER_PUBLIC
57 const rclcpp::Time & current_time,
58 const trajectory_msgs::msg::JointTrajectoryPoint & current_point,
59 const std::vector<bool> & joints_angle_wraparound = std::vector<bool>());
61 JOINT_TRAJECTORY_CONTROLLER_PUBLIC
62 void update(std::shared_ptr<trajectory_msgs::msg::JointTrajectory> joint_trajectory);
102 JOINT_TRAJECTORY_CONTROLLER_PUBLIC
104 const rclcpp::Time & sample_time,
105 const interpolation_methods::InterpolationMethod interpolation_method,
106 trajectory_msgs::msg::JointTrajectoryPoint & output_state,
107 TrajectoryPointConstIter & start_segment_itr, TrajectoryPointConstIter & end_segment_itr,
108 const bool search_monotonically_increasing =
true);
131 JOINT_TRAJECTORY_CONTROLLER_PUBLIC
133 const rclcpp::Time & time_a,
const trajectory_msgs::msg::JointTrajectoryPoint & state_a,
134 const rclcpp::Time & time_b,
const trajectory_msgs::msg::JointTrajectoryPoint & state_b,
135 const rclcpp::Time & sample_time, trajectory_msgs::msg::JointTrajectoryPoint & output);
137 JOINT_TRAJECTORY_CONTROLLER_PUBLIC
138 TrajectoryPointConstIter begin()
const;
140 JOINT_TRAJECTORY_CONTROLLER_PUBLIC
141 TrajectoryPointConstIter end()
const;
143 JOINT_TRAJECTORY_CONTROLLER_PUBLIC
144 rclcpp::Time time_from_start()
const;
146 JOINT_TRAJECTORY_CONTROLLER_PUBLIC
147 bool has_trajectory_msg()
const;
149 JOINT_TRAJECTORY_CONTROLLER_PUBLIC
150 bool has_nontrivial_msg()
const;
152 JOINT_TRAJECTORY_CONTROLLER_PUBLIC
153 std::shared_ptr<trajectory_msgs::msg::JointTrajectory> get_trajectory_msg()
const
155 return trajectory_msg_;
158 JOINT_TRAJECTORY_CONTROLLER_PUBLIC
159 bool is_sampled_already()
const {
return sampled_already_; }
166 JOINT_TRAJECTORY_CONTROLLER_PUBLIC
170 void deduce_from_derivatives(
171 trajectory_msgs::msg::JointTrajectoryPoint & first_state,
172 trajectory_msgs::msg::JointTrajectoryPoint & second_state,
const size_t dim,
173 const double delta_t);
175 std::shared_ptr<trajectory_msgs::msg::JointTrajectory> trajectory_msg_;
176 rclcpp::Time trajectory_start_time_;
178 rclcpp::Time time_before_traj_msg_;
179 trajectory_msgs::msg::JointTrajectoryPoint state_before_traj_msg_;
181 bool sampled_already_ =
false;
182 size_t last_sample_idx_ = 0;
191 inline std::vector<size_t>
mapping(
const T & t1,
const T & t2)
194 if (t1.size() > t2.size())
196 return std::vector<size_t>();
199 std::vector<size_t> mapping_vector(t1.size());
200 for (
auto t1_it = t1.begin(); t1_it != t1.end(); ++t1_it)
202 auto t2_it = std::find(t2.begin(), t2.end(), *t1_it);
203 if (t2.end() == t2_it)
205 return std::vector<size_t>();
209 const size_t t1_dist =
static_cast<size_t>(std::distance(t1.begin(), t1_it));
210 const size_t t2_dist =
static_cast<size_t>(std::distance(t2.begin(), t2_it));
211 mapping_vector[t1_dist] = t2_dist;
214 return mapping_vector;
225 std::vector<double> & current_position,
const std::vector<double> next_position,
226 const std::vector<bool> & joints_angle_wraparound);
Definition: trajectory.hpp:33
JOINT_TRAJECTORY_CONTROLLER_PUBLIC void interpolate_between_points(const rclcpp::Time &time_a, const trajectory_msgs::msg::JointTrajectoryPoint &state_a, const rclcpp::Time &time_b, const trajectory_msgs::msg::JointTrajectoryPoint &state_b, const rclcpp::Time &sample_time, trajectory_msgs::msg::JointTrajectoryPoint &output)
Definition: trajectory.cpp:205
JOINT_TRAJECTORY_CONTROLLER_PUBLIC size_t last_sample_index() const
Get the index of the segment start returned by the last sample() operation.
Definition: trajectory.hpp:167
JOINT_TRAJECTORY_CONTROLLER_PUBLIC bool sample(const rclcpp::Time &sample_time, const interpolation_methods::InterpolationMethod interpolation_method, trajectory_msgs::msg::JointTrajectoryPoint &output_state, TrajectoryPointConstIter &start_segment_itr, TrajectoryPointConstIter &end_segment_itr, const bool search_monotonically_increasing=true)
Definition: trajectory.cpp:90
JOINT_TRAJECTORY_CONTROLLER_PUBLIC void set_point_before_trajectory_msg(const rclcpp::Time ¤t_time, const trajectory_msgs::msg::JointTrajectoryPoint ¤t_point, const std::vector< bool > &joints_angle_wraparound=std::vector< bool >())
Definition: trajectory.cpp:45
Definition: interpolation_methods.hpp:24
std::vector< size_t > mapping(const T &t1, const T &t2)
Definition: trajectory.hpp:191
void wraparound_joint(std::vector< double > ¤t_position, const std::vector< double > next_position, const std::vector< bool > &joints_angle_wraparound)
Definition: trajectory.cpp:59