3 #include <ruckig/ruckig.hpp>
10 std::unique_ptr<ruckig::Ruckig<1>> otg;
13 const double delta_time;
15 double intersection(
double s1,
double ds1,
double s2,
double ds2,
double max_ds,
double max_dds,
double max_ddds) {
19 std::tuple<double, double> max_dynamics(
double s_start,
double ds_start,
double max_ds,
double max_dds,
double max_ddds) {
25 otg = std::make_unique<ruckig::Ruckig<1>>(delta_time);
29 Trajectory parametrize(
const Path& path,
const std::array<double, 7>& max_velocity,
const std::array<double, 7>& max_acceleration,
const std::array<double, 7>& max_jerk) {
36 Vector7d max_velocity_v = Eigen::Map<const Vector7d>(max_velocity.data(), max_velocity.size());
37 Vector7d max_accleration_v = Eigen::Map<const Vector7d>(max_acceleration.data(), max_acceleration.size());
38 Vector7d max_jerk_v = Eigen::Map<const Vector7d>(max_jerk.data(), max_jerk.size());
40 std::vector<std::tuple<double, double, double>> max_path_dynamics;
42 auto max_pddq = segment->max_pddq();
43 auto max_pdddq = segment->max_pdddq();
45 double max_ds, max_dds, max_ddds;
48 if ((max_pddq.array().abs() < 1e-16).any() && (max_pdddq.array().abs() < 1e-16).any()) {
49 auto constant_pdq = segment->pdq(0.0);
51 max_ds = (max_velocity_v.array() / constant_pdq.array().abs()).minCoeff();
52 max_dds = (max_accleration_v.array() / constant_pdq.array().abs()).minCoeff();
53 max_ddds = (max_jerk_v.array() / constant_pdq.array().abs()).minCoeff();
58 double ds_acc = (max_accleration_v.array() / max_pddq.array().abs()).sqrt().minCoeff();
59 double ds_jerk = (max_jerk_v.array() / max_pdddq.array().abs()).pow(1./3).minCoeff();
60 max_ds = std::min(ds_acc, ds_jerk);
65 max_path_dynamics.push_back({max_ds, max_dds, max_ddds});
68 double current_s, current_ds, current_dds;
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);
83 trajectory.states.push_back(current_state);
85 input.current_position[0] = s_new;
86 input.current_velocity[0] = ds_new;
87 input.current_acceleration[0] = dds_new;
89 input.target_velocity[0] = 0.0;
90 std::tie(input.max_velocity[0], input.max_acceleration[0], input.max_jerk[0]) = max_path_dynamics[index_current];
92 while (otg_result == ruckig::Result::Working) {
94 otg_result = otg->update(input, output);
96 s_new = output.new_position[0];
97 ds_new = output.new_velocity[0];
98 dds_new = output.new_acceleration[0];
100 size_t index_new = path.
get_index(s_new);
103 if (index_new > index_current) {
104 index_current = index_new;
110 current_state = {time, s_new, ds_new, dds_new, 0.0};
111 trajectory.states.push_back(current_state);
113 input.current_position = output.new_position;
114 input.current_velocity = output.new_velocity;
115 input.current_acceleration = output.new_acceleration;