6 Trajectory::Trajectory(std::vector<HebiTrajectoryPtr> trajectories,
size_t number_of_waypoints,
double start_time,
double end_time)
7 : trajectories_(trajectories),
8 number_of_joints_ (trajectories.
size()),
9 number_of_waypoints_(number_of_waypoints),
10 start_time_(start_time),
16 const VectorXd& time_vector,
17 const MatrixXd& positions,
18 const MatrixXd* velocities,
19 const MatrixXd* accelerations)
21 std::shared_ptr<Trajectory> res;
24 size_t num_joints = positions.rows();
25 size_t num_waypoints = positions.cols();
26 if (time_vector.size() != num_waypoints)
28 if (velocities !=
nullptr && (velocities->rows() != num_joints && velocities->cols() != num_waypoints))
30 if (accelerations !=
nullptr && (accelerations->rows() != num_joints && accelerations->cols() != num_waypoints))
32 if (num_waypoints < 2)
36 double* time_vector_c =
nullptr;
37 double* positions_c =
nullptr;
38 double* velocities_c =
nullptr;
39 double* accelerations_c =
nullptr;
40 time_vector_c =
new double[num_joints * num_waypoints];
45 positions_c =
new double[num_joints * num_waypoints];
50 if (velocities !=
nullptr)
52 velocities_c =
new double[num_joints * num_waypoints];
58 velocities_c =
new double[num_joints * num_waypoints];
59 for (
size_t joint = 0; joint < num_joints; ++joint)
61 velocities_c[joint * num_waypoints + 0] = 0.0f;
62 velocities_c[joint * num_waypoints + num_waypoints - 1] = 0.0f;
63 for (
size_t waypoint = 1; waypoint < num_waypoints - 1; ++waypoint)
64 velocities_c[joint * num_waypoints + waypoint] = std::numeric_limits<double>::quiet_NaN();
67 if (accelerations !=
nullptr)
69 accelerations_c =
new double[num_joints * num_waypoints];
75 accelerations_c =
new double[num_joints * num_waypoints];
76 for (
size_t joint = 0; joint < num_joints; ++joint)
78 accelerations_c[joint * num_waypoints + 0] = 0.0f;
79 accelerations_c[joint * num_waypoints + num_waypoints - 1] = 0.0f;
80 for (
size_t waypoint = 1; waypoint < num_waypoints - 1; ++waypoint)
81 accelerations_c[joint * num_waypoints + waypoint] = std::numeric_limits<double>::quiet_NaN();
86 std::vector<HebiTrajectoryPtr> trajectories(num_joints,
nullptr);
87 for (
size_t i = 0; i < num_joints; ++i)
90 (positions_c + i * num_waypoints),
91 velocities_c ==
nullptr ?
nullptr : (velocities_c + i * num_waypoints),
92 accelerations_c ==
nullptr ?
nullptr : (accelerations_c + i * num_waypoints),
95 if (trajectory ==
nullptr)
97 for (
size_t j = 0; j < i; ++j)
103 trajectories[i] = trajectory;
106 delete[] positions_c;
107 if (velocities_c !=
nullptr)
108 delete[] velocities_c;
109 if (accelerations_c !=
nullptr)
110 delete[] accelerations_c;
113 return std::shared_ptr<Trajectory>(
new Trajectory(trajectories, num_waypoints, time_vector[0], time_vector[time_vector.size() - 1]));
130 double tmp_p, tmp_v, tmp_a;
137 position ==
nullptr ? &tmp_p : &(*position)[i],
138 velocity ==
nullptr ? &tmp_v : &(*velocity)[i],
139 acceleration ==
nullptr ? &tmp_a : &(*acceleration)[i]) == 0) && success;
HebiTrajectoryPtr hebiTrajectoryCreateUnconstrainedQp(size_t num_waypoints, const double *positions, const double *velocities, const double *accelerations, const double *time_vector)
Creates a HebiTrajectory object for a single joint using the given parameters; this must be released ...
A matrix or vector expression mapping an existing array of data.
Trajectory(std::vector< HebiTrajectoryPtr > trajectories, size_t number_of_waypoints, double start_time, double end_time)
static std::shared_ptr< Trajectory > createUnconstrainedQp(const VectorXd &time_vector, const MatrixXd &positions, const MatrixXd *velocities=nullptr, const MatrixXd *accelerations=nullptr)
Creates a smooth trajectory through a set of waypoints (position velocity and accelerations defined a...
static constexpr size_t size(Tuple< Args... > &)
Provides access to the number of elements in a tuple as a compile-time constant expression.
HebiStatusCode hebiTrajectoryGetState(HebiTrajectoryPtr trajectory, double time, double *position, double *velocity, double *acceleration)
Gets the value of the trajectory at a given time.
double hebiTrajectoryGetDuration(HebiTrajectoryPtr trajectory)
Returns the length of this trajectory (in seconds).
void hebiTrajectoryRelease(HebiTrajectoryPtr trajectory)
Frees resources created by this trajectory.
double getDuration() const
The time (in seconds) between the start and end of this trajectory.
bool getState(double time, VectorXd *position, VectorXd *velocity, VectorXd *acceleration) const
Returns the position, velocity, and acceleration for a given point in time along the trajectory...
struct _HebiTrajectory * HebiTrajectoryPtr
The C-style's API representation of a trajectory.
~Trajectory() noexcept
Destructor cleans up resources for trajectory.
std::vector< HebiTrajectoryPtr > trajectories_