HEBI C++ API  3.15.0
trajectory.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "hebi.h"
4 
5 #include <memory>
6 #include <vector>
7 
8 #include "Eigen/Eigen"
9 #include "util.hpp"
10 
11 namespace hebi {
12 namespace trajectory {
13 
17 class Trajectory final {
18 private:
22  std::vector<HebiTrajectoryPtr> trajectories_;
23 
27  const size_t number_of_joints_;
28 
32  const size_t number_of_waypoints_;
33 
37  const double start_time_;
38 
42  const double end_time_;
43 
47  Trajectory(std::vector<HebiTrajectoryPtr> trajectories, size_t number_of_waypoints, double start_time,
48  double end_time);
49 
69  static Eigen::VectorXd estimateSegmentTimes(const Eigen::MatrixXd& positions,
70  const Eigen::VectorXd& max_velocities,
71  const Eigen::VectorXd& max_accelerations,
72  const HebiTimeEstimationParams& params,
73  double min_segment_time = 0.01);
74 
75 public:
104  static std::shared_ptr<Trajectory> createUnconstrainedQp(const Eigen::VectorXd& time_vector, const Eigen::MatrixXd& positions,
105  const Eigen::MatrixXd* velocities = nullptr,
106  const Eigen::MatrixXd* accelerations = nullptr);
107 
111  ~Trajectory() noexcept;
112 
117  size_t getJointCount() const { return number_of_joints_; }
118 
122  size_t getWaypointCount() const { return number_of_waypoints_; }
123 
127  double getStartTime() const { return start_time_; }
128 
132  double getEndTime() const { return end_time_; }
133 
138  double getDuration() const;
139 
156  bool getState(double time, Eigen::VectorXd* position, Eigen::VectorXd* velocity, Eigen::VectorXd* acceleration) const;
157 
171  bool getMinMaxPosition(Eigen::VectorXd& min_position, Eigen::VectorXd& max_position);
172 
184  bool getMaxVelocity(Eigen::VectorXd& max_velocity);
185 
197  bool getMaxAcceleration(Eigen::VectorXd& max_acceleration);
198 
211  static Eigen::VectorXd segmentTimesToWaypointTimes(const Eigen::VectorXd& segment_times);
212 
223  static Eigen::VectorXd waypointTimesToSegmentTimes(const Eigen::VectorXd& waypoint_times);
224 
252  static Eigen::VectorXd estimateSegmentTimesNFabian(const Eigen::MatrixXd& positions,
253  const Eigen::VectorXd& max_velocities,
254  const Eigen::VectorXd& max_accelerations,
255  double fabian_constant = 6.5,
256  double min_segment_time = 0.01) {
257  HebiTimeEstimationParams params;
258  params.method = HebiTimeEstimationMethod::HebiTimeEstimationNFabian;
259  params.params.n_fabian_params.magic_fabian_constant = fabian_constant;
260  return estimateSegmentTimes(positions, max_velocities, max_accelerations, params, min_segment_time);
261  }
262 
284  static Eigen::VectorXd estimateSegmentTimesTrapezoidal(const Eigen::MatrixXd& positions,
285  const Eigen::VectorXd& max_velocities,
286  const Eigen::VectorXd& max_accelerations,
287  double min_segment_time = 0.01) {
288  HebiTimeEstimationParams params;
289  params.method = HebiTimeEstimationMethod::HebiTimeEstimationVelocityRamp;
290  return estimateSegmentTimes(positions, max_velocities, max_accelerations, params, min_segment_time);
291  }
292 
293 private:
298 };
299 
300 } // namespace trajectory
301 } // namespace hebi
static Eigen::VectorXd segmentTimesToWaypointTimes(const Eigen::VectorXd &segment_times)
Converts a vector of segment times to a vector of time values at each waypoint. The first element of ...
Definition: trajectory.cpp:131
double getDuration() const
The time (in seconds) between the start and end of this trajectory.
Definition: trajectory.cpp:87
Definition: arm.cpp:10
static Eigen::VectorXd estimateSegmentTimesNFabian(const Eigen::MatrixXd &positions, const Eigen::VectorXd &max_velocities, const Eigen::VectorXd &max_accelerations, double fabian_constant=6.5, double min_segment_time=0.01)
Estimates the time required to move between waypoints using the N-Fabian method. It uses the both dis...
Definition: trajectory.hpp:252
bool getMinMaxPosition(Eigen::VectorXd &min_position, Eigen::VectorXd &max_position)
Returns the minimum and maximum positions reached by each joint over the entire trajectory....
Definition: trajectory.cpp:104
size_t getJointCount() const
The number of independent position trajectories over the same time domain that are managed by this ob...
Definition: trajectory.hpp:117
double getStartTime() const
Get the time (in seconds) at which the defined trajectory begins.
Definition: trajectory.hpp:127
#define HEBI_DISABLE_COPY_MOVE(Class)
Definition: util.hpp:6
bool getState(double time, Eigen::VectorXd *position, Eigen::VectorXd *velocity, Eigen::VectorXd *acceleration) const
Returns the position, velocity, and acceleration for a given point in time along the trajectory.
Definition: trajectory.cpp:92
static Eigen::VectorXd waypointTimesToSegmentTimes(const Eigen::VectorXd &waypoint_times)
Converts a vector of time values at each waypoint to a vector of segment times.
Definition: trajectory.cpp:147
size_t getWaypointCount() const
The number of fixed waypoints that each joint is moving through.
Definition: trajectory.hpp:122
bool getMaxAcceleration(Eigen::VectorXd &max_acceleration)
Returns the maximum absolute acceleration reached by each joint over the entire trajectory....
Definition: trajectory.cpp:122
bool getMaxVelocity(Eigen::VectorXd &max_velocity)
Returns the maximum absolute velocity reached by each joint over the entire trajectory....
Definition: trajectory.cpp:113
double getEndTime() const
Get the time (in seconds) at which the defined trajectory ends.
Definition: trajectory.hpp:132
static std::shared_ptr< Trajectory > createUnconstrainedQp(const Eigen::VectorXd &time_vector, const Eigen::MatrixXd &positions, const Eigen::MatrixXd *velocities=nullptr, const Eigen::MatrixXd *accelerations=nullptr)
Creates a smooth trajectory through a set of waypoints (position velocity and accelerations defined a...
Definition: trajectory.cpp:17
Represents a smooth trajectory through a set of waypoints.
Definition: trajectory.hpp:17
~Trajectory() noexcept
Destructor cleans up resources for trajectory.
Definition: trajectory.cpp:82
static Eigen::VectorXd estimateSegmentTimesTrapezoidal(const Eigen::MatrixXd &positions, const Eigen::VectorXd &max_velocities, const Eigen::VectorXd &max_accelerations, double min_segment_time=0.01)
Estimates the time required to move between waypoints based on the trapezoidal velocity profiles and ...
Definition: trajectory.hpp:284