33 #include <unordered_map>
46 const float linear_resolution,
47 const float angular_resolution,
50 const float interpolation_resolution,
51 const float grid_enumeration_resolution)
53 const int angle = std::lround(M_PI * 2 / angular_resolution);
58 for (
int syaw = 0; syaw <
angle; syaw++)
60 const float yaw = syaw * angular_resolution;
62 for (
d[0] = -range;
d[0] <= range;
d[0]++)
64 for (
d[1] = -range;
d[1] <= range;
d[1]++)
66 if (
d[0] == 0 &&
d[1] == 0)
68 if (
d.sqlen() > range * range)
73 const float yaw_e =
d[2] * angular_resolution;
74 const float diff_val[3] =
76 d[0] * linear_resolution,
77 d[1] * linear_resolution,
78 d[2] * angular_resolution,
84 motion.
rotate(-syaw * angular_resolution);
85 const float cos_v = cosf(motion[2]);
86 const float sin_v = sinf(motion[2]);
88 const int total_step =
static_cast<int>(std::round(
d.len() / grid_enumeration_resolution));
89 const int interpolation_step =
90 std::max(1,
static_cast<int>(std::round(interpolation_resolution / grid_enumeration_resolution)));
91 if (std::abs(sin_v) < 0.1)
95 const float ratio =
step /
static_cast<float>(total_step);
96 const float x = diff_val[0] * ratio;
97 const float y = diff_val[1] * ratio;
99 const CyclicVecFloat<3, 2> posf(x / linear_resolution, y / linear_resolution, yaw / angular_resolution);
103 if ((pos !=
d) && (registered.find(pos) == registered.end()))
106 for (
int i = 0; i < 3; ++i)
107 max_range[i] = std::max(max_range[i], std::abs(pos[i]));
108 registered[pos] =
true;
110 if (
step % interpolation_step == 0)
121 const float r1 = motion[1] + motion[0] * cos_v / sin_v;
122 const float r2 = std::copysign(
123 std::sqrt(std::pow(motion[0], 2) + std::pow(motion[0] * cos_v / sin_v, 2)),
126 float dyaw = yaw_e - yaw;
129 else if (dyaw > M_PI)
132 const float cx =
d[0] * linear_resolution + r2 * cosf(yaw_e + M_PI / 2);
133 const float cy =
d[1] * linear_resolution + r2 * sinf(yaw_e + M_PI / 2);
134 const float cx_s = r1 * cosf(yaw + M_PI / 2);
135 const float cy_s = r1 * sinf(yaw + M_PI / 2);
141 const float ratio =
step /
static_cast<float>(total_step);
142 const float r = r1 * (1.0 - ratio) + r2 * ratio;
143 const float cx2 = cx_s * (1.0 - ratio) + cx * ratio;
144 const float cy2 = cy_s * (1.0 - ratio) + cy * ratio;
145 const float cyaw = yaw + ratio * dyaw;
148 (cy2 - r * sinf(cyaw + M_PI / 2)) / linear_resolution,
149 cyaw / angular_resolution);
152 if ((pos !=
d) && (registered.find(pos) == registered.end()))
155 registered[pos] =
true;
157 if (
step % interpolation_step == 0)
162 distf += (posf - posf_prev).len();
172 for (
auto& cache :
cache_[syaw])
176 size_t a_baddr, a_addr;
177 size_t b_baddr, b_addr;
178 gm_addr(a, a_baddr, a_addr);
179 gm_addr(b, b_baddr, b_addr);
180 if (a_baddr == b_baddr)
182 return (a_addr < b_addr);
184 return (a_baddr < b_baddr);
186 std::sort(cache.second.motion_.begin(), cache.second.motion_.end(), comp);
194 std::list<CyclicVecFloat<3, 2>> result;
195 if (grid_path.size() < 2)
197 for (
const auto& p : grid_path)
203 auto it_prev = grid_path.begin();
204 for (
auto it = std::next(it_prev); it != grid_path.end(); ++it, ++it_prev)
206 if (((*it_prev)[0] == (*it)[0]) && ((*it_prev)[1] == (*it)[1]))
212 const auto motion_it =
find(*it_prev, *it);
213 if (motion_it ==
end((*it)[2]))
215 ROS_ERROR(
"Failed to find motion between [%d %d %d] and [%d %d %d]",
216 (*it_prev)[0], (*it_prev)[1], (*it_prev)[2], (*it)[0], (*it)[1], (*it)[2]);
221 for (
const auto& pos_diff : motion_it->second.getInterpolatedMotion())
223 result.push_back(
CyclicVecFloat<3, 2>((*it_prev)[0] + pos_diff[0], (*it_prev)[1] + pos_diff[1], pos_diff[2]));
227 result.push_back(
CyclicVecFloat<3, 2>(grid_path.back()[0], grid_path.back()[1], grid_path.back()[2]));