41 #include <moveit_msgs/msg/robot_trajectory.hpp>
42 #include <moveit_msgs/msg/robot_state.hpp>
47 #include <rcl/error_handling.h>
49 #include <rclcpp/clock.hpp>
50 #include <rclcpp/rclcpp.hpp>
51 #include <rclcpp/time.hpp>
52 #include <rclcpp/utilities.hpp>
64 explicit RobotTrajectory(
const moveit::core::RobotModelConstPtr& robot_model);
103 group_ = robot_model_->getJointModelGroup(group_name);
109 return waypoints_.size();
114 assert(waypoints_.size() == duration_from_previous_.size());
115 return waypoints_.size();
120 return *waypoints_[index];
125 return *waypoints_.back();
130 return *waypoints_.front();
135 return waypoints_[index];
140 return waypoints_.back();
145 return waypoints_.front();
150 return duration_from_previous_;
163 if (duration_from_previous_.size() > index)
164 return duration_from_previous_[index];
171 if (duration_from_previous_.size() <= index)
172 duration_from_previous_.resize(index + 1, 0.0);
173 duration_from_previous_[index] = value;
179 return waypoints_.empty();
200 waypoints_.push_back(state);
201 duration_from_previous_.push_back(dt);
213 waypoints_.push_front(state);
214 duration_from_previous_.push_front(dt);
220 return insertWayPoint(index, std::make_shared<moveit::core::RobotState>(state), dt);
226 waypoints_.insert(waypoints_.begin() + index, state);
227 duration_from_previous_.insert(duration_from_previous_.begin() + index, dt);
242 size_t end_index = std::numeric_limits<std::size_t>::max());
249 duration_from_previous_.clear();
258 const std::vector<std::string>& joint_filter = std::vector<std::string>())
const;
267 const trajectory_msgs::msg::JointTrajectory& trajectory);
276 const moveit_msgs::msg::RobotTrajectory& trajectory);
286 const moveit_msgs::msg::RobotState& state,
287 const moveit_msgs::msg::RobotTrajectory& trajectory);
313 std::deque<moveit::core::RobotStatePtr>::iterator waypoint_iterator_;
314 std::deque<double>::iterator duration_iterator_;
317 explicit Iterator(
const std::deque<moveit::core::RobotStatePtr>::iterator& waypoint_iterator,
318 const std::deque<double>::iterator& duration_iterator)
319 : waypoint_iterator_(waypoint_iterator), duration_iterator_(duration_iterator)
324 waypoint_iterator_++;
325 duration_iterator_++;
336 return ((waypoint_iterator_ == other.waypoint_iterator_) && (duration_iterator_ == other.duration_iterator_));
340 return !(*
this == other);
342 std::pair<moveit::core::RobotStatePtr, double>
operator*()
const
344 return std::pair{ *waypoint_iterator_, *duration_iterator_ };
349 using value_type = std::pair<moveit::core::RobotStatePtr, double>;
350 using pointer =
const std::pair<moveit::core::RobotStatePtr, double>*;
351 using reference = std::pair<moveit::core::RobotStatePtr, double>;
357 assert(waypoints_.size() == duration_from_previous_.size());
358 return Iterator(waypoints_.begin(), duration_from_previous_.begin());
362 assert(waypoints_.size() == duration_from_previous_.size());
363 return Iterator(waypoints_.end(), duration_from_previous_.end());
378 void print(std::ostream& out, std::vector<int> variable_indexes = std::vector<int>())
const;
381 moveit::core::RobotModelConstPtr robot_model_;
383 std::deque<moveit::core::RobotStatePtr> waypoints_;
384 std::deque<double> duration_from_previous_;
385 rclcpp::Clock clock_ros_;
389 std::ostream&
operator<<(std::ostream& out,
const RobotTrajectory& trajectory);
397 [[nodiscard]]
double path_length(RobotTrajectory
const& trajectory);
403 [[nodiscard]] std::optional<double>
smoothness(RobotTrajectory
const& trajectory);
409 [[nodiscard]] std::optional<double>
waypoint_density(RobotTrajectory
const& trajectory);
Representation of a robot's state. This includes position, velocity, acceleration and effort.
const std::pair< moveit::core::RobotStatePtr, double > * pointer
Iterator(const std::deque< moveit::core::RobotStatePtr >::iterator &waypoint_iterator, const std::deque< double >::iterator &duration_iterator)
std::pair< moveit::core::RobotStatePtr, double > reference
std::pair< moveit::core::RobotStatePtr, double > value_type
std::input_iterator_tag iterator_category
bool operator!=(const Iterator &other) const
bool operator==(const Iterator &other) const
std::pair< moveit::core::RobotStatePtr, double > operator*() const
Maintain a sequence of waypoints and the time durations between these waypoints.
RobotTrajectory & insertWayPoint(std::size_t index, const moveit::core::RobotStatePtr &state, double dt)
RobotTrajectory & reverse()
void swap(robot_trajectory::RobotTrajectory &other)
RobotTrajectory & setWayPointDurationFromPrevious(std::size_t index, double value)
double getWaypointDurationFromStart(std::size_t index) const
RobotTrajectory & addPrefixWayPoint(const moveit::core::RobotStatePtr &state, double dt)
const std::string & getGroupName() const
const moveit::core::RobotModelConstPtr & getRobotModel() const
double getWayPointDurationFromStart(std::size_t index) const
Returns the duration after start that a waypoint will be reached.
RobotTrajectory(const moveit::core::RobotModelConstPtr &robot_model)
construct a trajectory for the whole robot
RobotTrajectory::Iterator end()
double getAverageSegmentDuration() const
void print(std::ostream &out, std::vector< int > variable_indexes=std::vector< int >()) const
Print information about the trajectory.
bool getStateAtDurationFromStart(const double request_duration, moveit::core::RobotStatePtr &output_state) const
Gets a robot state corresponding to a supplied duration from start for the trajectory,...
const moveit::core::JointModelGroup * getGroup() const
void getRobotTrajectoryMsg(moveit_msgs::msg::RobotTrajectory &trajectory, const std::vector< std::string > &joint_filter=std::vector< std::string >()) const
RobotTrajectory & unwind()
RobotTrajectory & setGroupName(const std::string &group_name)
RobotTrajectory & addSuffixWayPoint(const moveit::core::RobotState &state, double dt)
Add a point to the trajectory.
const moveit::core::RobotState & getFirstWayPoint() const
RobotTrajectory & setRobotTrajectoryMsg(const moveit::core::RobotState &reference_state, const trajectory_msgs::msg::JointTrajectory &trajectory)
Copy the content of the trajectory message into this class. The trajectory message itself is not requ...
RobotTrajectory::Iterator begin()
RobotTrajectory & operator=(const RobotTrajectory &)=default
RobotTrajectory & append(const RobotTrajectory &source, double dt, size_t start_index=0, size_t end_index=std::numeric_limits< std::size_t >::max())
Add a specified part of a trajectory to the end of the current trajectory. The default (when start_in...
moveit::core::RobotStatePtr & getWayPointPtr(std::size_t index)
const std::deque< double > & getWayPointDurations() const
RobotTrajectory & insertWayPoint(std::size_t index, const moveit::core::RobotState &state, double dt)
std::size_t getWayPointCount() const
double getWayPointDurationFromPrevious(std::size_t index) const
void findWayPointIndicesForDurationAfterStart(const double &duration, int &before, int &after, double &blend) const
Finds the waypoint indices before and after a duration from start.
RobotTrajectory & addPrefixWayPoint(const moveit::core::RobotState &state, double dt)
RobotTrajectory & addSuffixWayPoint(const moveit::core::RobotStatePtr &state, double dt)
Add a point to the trajectory.
RobotTrajectory & clear()
moveit::core::RobotStatePtr & getLastWayPointPtr()
const moveit::core::RobotState & getWayPoint(std::size_t index) const
moveit::core::RobotStatePtr & getFirstWayPointPtr()
double getDuration() const
const moveit::core::RobotState & getLastWayPoint() const
double path_length(RobotTrajectory const &trajectory)
Calculate the path length of a given trajectory based on the accumulated robot state distances....
std::optional< double > waypoint_density(RobotTrajectory const &trajectory)
Calculate the waypoint density of a trajectory.
std::ostream & operator<<(std::ostream &out, const RobotTrajectory &trajectory)
Operator overload for printing trajectory to a stream.
std::optional< double > smoothness(RobotTrajectory const &trajectory)
Calculate the smoothness of a given trajectory.
MOVEIT_CLASS_FORWARD(RobotTrajectory)