3 #include <ruckig/ruckig.hpp>
12 const std::unique_ptr<ruckig::Ruckig<1>> otg;
15 const double delta_time;
19 : delta_time(delta_time), otg(std::make_unique<ruckig::Ruckig<1>>(delta_time)) {}
22 template<
size_t state_dimensions>
25 const std::array<double, state_dimensions> &max_velocity,
26 const std::array<double, state_dimensions> &max_acceleration,
27 const std::array<double, state_dimensions> &max_jerk) {
34 Eigen::Vector<double, state_dimensions> max_velocity_v = \
35 Eigen::Map<const Eigen::Vector<double, state_dimensions>>(max_velocity.data(), max_velocity.size());
36 Eigen::Vector<double, state_dimensions> max_accleration_v = \
37 Eigen::Map<const Eigen::Vector<double, state_dimensions>>(max_acceleration.data(), max_acceleration.size());
38 Eigen::Vector<double, state_dimensions> max_jerk_v = \
39 Eigen::Map<const Eigen::Vector<double, state_dimensions>>(max_jerk.data(), max_jerk.size());
41 std::vector<std::tuple<double, double, double>> max_path_dynamics;
42 for (
auto segment : path.
segments()) {
43 auto max_pddq = segment->
max_ddq();
44 auto max_pdddq = segment->max_dddq();
46 double max_ds, max_dds, max_ddds;
49 if ((max_pddq.array().abs() < 1e-16).any() && (max_pdddq.array().abs() < 1e-16).any()) {
50 auto constant_pdq = (*segment)(0.0).dq;
52 max_ds = (max_velocity_v.array() / constant_pdq.array().abs()).minCoeff();
53 max_dds = (max_accleration_v.array() / constant_pdq.array().abs()).minCoeff();
54 max_ddds = (max_jerk_v.array() / constant_pdq.array().abs()).minCoeff();
59 double ds_acc = (max_accleration_v.array() / max_pddq.array().abs()).sqrt().minCoeff();
60 double ds_jerk = (max_jerk_v.array() / max_pdddq.array().abs()).pow(1. / 3).minCoeff();
61 max_ds = std::min(ds_acc, ds_jerk);
66 max_path_dynamics.emplace_back(max_ds, max_dds, max_ddds);
73 ruckig::InputParameter<1> input;
74 ruckig::OutputParameter<1> output;
75 ruckig::Result otg_result{ruckig::Result::Working};
78 double s_new{0.0}, ds_new{0.0}, dds_new{0.0};
79 size_t index_current = path.
get_index(s_new);
81 trajectory.states.push_back(
TrajectoryState{time, s_new, ds_new, dds_new, 0.0});
83 input.current_position[0] = s_new;
84 input.current_velocity[0] = ds_new;
85 input.current_acceleration[0] = dds_new;
86 input.target_position[0] = path.
length();
87 input.target_velocity[0] = 0.0;
88 std::tie(input.max_velocity[0], input.max_acceleration[0], input.max_jerk[0]) = max_path_dynamics[index_current];
90 while (otg_result == ruckig::Result::Working) {
92 otg_result = otg->update(input, output);
94 s_new = output.new_position[0];
95 ds_new = output.new_velocity[0];
96 dds_new = output.new_acceleration[0];
101 if (index_new > index_current) {
102 index_current = index_new;
105 trajectory.states.push_back(
TrajectoryState{time, s_new, ds_new, dds_new, 0.0});
106 output.pass_to_input(input);
Definition: aggregated_path.hpp:11
size_t get_index(double s) const
Definition: aggregated_path.hpp:67
Vector max_ddq() const override
Definition: aggregated_path.hpp:35
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: time_parametrization.hpp:10
Trajectory< AggregatedPath< state_dimensions > > parametrize(const AggregatedPath< state_dimensions > &path, const std::array< double, state_dimensions > &max_velocity, const std::array< double, state_dimensions > &max_acceleration, const std::array< double, state_dimensions > &max_jerk)
Returns list of path positions s at delta time.
Definition: time_parametrization.hpp:23
TimeParametrization(double delta_time)
Definition: time_parametrization.hpp:18
Definition: gripper.cpp:3
Definition: trajectory.hpp:16
Definition: trajectory.hpp:7