Franky  0.9.1
A High-Level Motion API for Franka
aggregated_path.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 
5 #include "franky/path/path.hpp"
6 #include "franky/robot_pose.hpp"
7 
8 namespace franky {
9 
10 template<size_t state_dimensions>
11 class AggregatedPath : public Path<state_dimensions> {
12  using Vector = Eigen::Matrix<double, state_dimensions, 1>;
13  public:
14  AggregatedPath() = default;
15 
17  : segments_(aggregated_path.segments_), cumulative_lengths_(aggregated_path.cumulative_lengths_) {}
18 
19  explicit AggregatedPath(const std::vector<std::shared_ptr<Path<state_dimensions>>> &segments)
20  : segments_(segments) {
21  if (segments_.empty())
22  throw std::runtime_error("AggregatedPath needs at least one segment..");
23  cumulative_lengths_.resize(segments_.size());
24  double cumulative_length = 0.0;
25  for (size_t i = 1; i < segments_.size() - 1; i += 1) {
26  cumulative_length += segments_[i]->length();
27  cumulative_lengths_[i] = cumulative_length;
28  }
29  }
30 
31  [[nodiscard]] inline double length() const override {
32  return cumulative_lengths_.back();
33  }
34 
35  Vector max_ddq() const override {
36  Vector result;
37  for (size_t i = 0; i < state_dimensions; i++) {
38  auto max_ptr = *std::max_element(
39  segments_.begin(), segments_.end(),
40  [&](std::shared_ptr<Path<state_dimensions>> l, std::shared_ptr<Path<state_dimensions>> r) {
41  return std::abs(l->max_ddq()(i)) < std::abs(r->max_ddq()(i));
42  });
43  result(i) = std::abs(max_ptr->max_ddq()(i));
44  }
45  return result;
46  }
47 
48  Vector max_dddq() const override {
49  Vector result;
50  for (size_t i = 0; i < state_dimensions; i++) {
51  auto max_ptr = *std::max_element(
52  segments_.begin(), segments_.end(),
53  [&](std::shared_ptr<Path<state_dimensions>> l, std::shared_ptr<Path<state_dimensions>> r) {
54  return std::abs(l->max_dddq()(i)) < std::abs(r->max_dddq()(i));
55  });
56  result(i) = std::abs(max_ptr->max_dddq()(i));
57  }
58  return result;
59  }
60 
61  PathStep<state_dimensions> operator()(double s) const override {
62  size_t index = get_index(s);
63  double s_local = (index == 0) ? s : s - cumulative_lengths_[index - 1];
64  return (*segments_[index])(s_local);
65  }
66 
67  [[nodiscard]] size_t get_index(double s) const {
68  auto ptr = std::lower_bound(cumulative_lengths_.begin(), cumulative_lengths_.end(), s);
69  size_t index = std::distance(cumulative_lengths_.begin(), ptr);
70  return std::min(index, segments_.size() - 1);
71  }
72 
73  inline std::vector<std::shared_ptr<Path<state_dimensions>>> segments() const {
74  return segments_;
75  }
76 
77  private:
78  std::vector<std::shared_ptr<Path<state_dimensions>>> segments_;
79  std::vector<double> cumulative_lengths_;
80 };
81 
82 struct PathWaypoint {
84 
86  double blend_max_distance{0.0};
87 };
88 
89 AggregatedPath<7>
90 mk_path_from_waypoints(const std::vector<PathWaypoint> &waypoints, double default_initial_elbow_pos = 0.0);
91 
92 } // namespace franky
Definition: aggregated_path.hpp:11
AggregatedPath(const AggregatedPath< state_dimensions > &aggregated_path)
Definition: aggregated_path.hpp:16
AggregatedPath(const std::vector< std::shared_ptr< Path< state_dimensions >>> &segments)
Definition: aggregated_path.hpp:19
size_t get_index(double s) const
Definition: aggregated_path.hpp:67
Vector max_ddq() const override
Definition: aggregated_path.hpp:35
Vector max_dddq() const override
Definition: aggregated_path.hpp:48
PathStep< state_dimensions > operator()(double s) const override
Definition: aggregated_path.hpp:61
double length() const override
Definition: aggregated_path.hpp:31
std::vector< std::shared_ptr< Path< state_dimensions > > > segments() const
Definition: aggregated_path.hpp:73
Definition: path.hpp:16
Cartesian pose of a robot.
Definition: robot_pose.hpp:16
Definition: gripper.cpp:3
AggregatedPath< 7 > mk_path_from_waypoints(const std::vector< PathWaypoint > &waypoints, double default_initial_elbow_pos)
Definition: aggregated_path.cpp:8
Definition: path.hpp:8
Definition: aggregated_path.hpp:82
double blend_max_distance
Path Waypoint: Maximum distance for blending.
Definition: aggregated_path.hpp:86
RobotPose robot_pose
Definition: aggregated_path.hpp:83