10#include "trajopt/geometry/pose2.hpp"
11#include "trajopt/util/trajopt_util.hpp"
19inline void append_range(std::vector<T>& base,
20 const std::vector<T>& new_items) {
21 base.insert(base.end(), new_items.begin(), new_items.end());
24template <
typename Solution>
25inline Solution generate_linear_initial_guess(
26 const std::vector<std::vector<Pose2d>>& initial_guess_points,
27 const std::vector<size_t> control_interval_counts) {
28 size_t wpt_cnt = control_interval_counts.size() + 1;
29 size_t samp_tot = get_index(control_interval_counts, wpt_cnt - 1, 0) + 1;
31 Solution initial_guess;
33 initial_guess.
x.reserve(samp_tot);
34 initial_guess.y.reserve(samp_tot);
35 if constexpr (std::same_as<Solution, DifferentialSolution>) {
36 initial_guess.heading.reserve(samp_tot);
38 initial_guess.thetacos.reserve(samp_tot);
39 initial_guess.thetasin.reserve(samp_tot);
42 initial_guess.dt.reserve(samp_tot);
44 initial_guess.x.push_back(initial_guess_points.front().front().x());
45 initial_guess.y.push_back(initial_guess_points.front().front().y());
46 if constexpr (std::same_as<Solution, DifferentialSolution>) {
47 initial_guess.heading.push_back(
48 initial_guess_points.front().front().rotation().radians());
50 initial_guess.thetacos.push_back(
51 initial_guess_points.front().front().rotation().cos());
52 initial_guess.thetasin.push_back(
53 initial_guess_points.front().front().rotation().sin());
56 for (
size_t i = 0; i < samp_tot; ++i) {
57 initial_guess.dt.push_back((wpt_cnt * 5.0) / samp_tot);
60 for (
size_t wpt_index = 1; wpt_index < wpt_cnt; ++wpt_index) {
61 size_t N_sgmt = control_interval_counts.at(wpt_index - 1);
62 size_t guess_point_count = initial_guess_points.at(wpt_index).size();
63 size_t N_guess_sgmt = N_sgmt / guess_point_count;
66 linspace(initial_guess_points.at(wpt_index - 1).back().x(),
67 initial_guess_points.at(wpt_index).front().x(), N_guess_sgmt));
70 linspace(initial_guess_points.at(wpt_index - 1).back().y(),
71 initial_guess_points.at(wpt_index).front().y(), N_guess_sgmt));
72 auto wpt_thetas = angle_linspace(
73 initial_guess_points.at(wpt_index - 1).back().rotation().radians(),
74 initial_guess_points.at(wpt_index).front().rotation().radians(),
76 for (
auto theta : wpt_thetas) {
77 if constexpr (std::same_as<Solution, DifferentialSolution>) {
78 initial_guess.heading.push_back(theta);
80 initial_guess.thetacos.push_back(std::cos(theta));
81 initial_guess.thetasin.push_back(std::sin(theta));
84 for (
size_t guess_point_index = 1;
85 guess_point_index < guess_point_count - 1;
86 ++guess_point_index) {
90 initial_guess_points.at(wpt_index).at(guess_point_index - 1).x(),
91 initial_guess_points.at(wpt_index).at(guess_point_index).x(),
96 initial_guess_points.at(wpt_index).at(guess_point_index - 1).y(),
97 initial_guess_points.at(wpt_index).at(guess_point_index).y(),
99 auto guess_thetas = angle_linspace(initial_guess_points.at(wpt_index)
100 .at(guess_point_index - 1)
103 initial_guess_points.at(wpt_index)
104 .at(guess_point_index)
108 for (
auto theta : guess_thetas) {
109 if constexpr (std::same_as<Solution, DifferentialSolution>) {
110 initial_guess.heading.push_back(theta);
112 initial_guess.thetacos.push_back(std::cos(theta));
113 initial_guess.thetasin.push_back(std::sin(theta));
117 if (guess_point_count > 1) {
118 size_t N_last_guess_sgmt =
119 N_sgmt - (guess_point_count - 1) * N_guess_sgmt;
123 initial_guess_points.at(wpt_index).at(guess_point_count - 2).x(),
124 initial_guess_points.at(wpt_index).back().x(),
129 initial_guess_points.at(wpt_index).at(guess_point_count - 2).y(),
130 initial_guess_points.at(wpt_index).back().y(),
132 auto last_thetas = angle_linspace(
133 initial_guess_points.at(wpt_index)
134 .at(guess_point_count - 2)
137 initial_guess_points.at(wpt_index).back().rotation().radians(),
139 for (
auto theta : last_thetas) {
140 if constexpr (std::same_as<Solution, DifferentialSolution>) {
141 initial_guess.heading.push_back(theta);
143 initial_guess.thetacos.push_back(std::cos(theta));
144 initial_guess.thetasin.push_back(std::sin(theta));
150 return initial_guess;
The holonomic trajectory optimization solution.
Definition differential_trajectory_generator.hpp:47
std::vector< double > x
X positions.
Definition differential_trajectory_generator.hpp:52