-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
planner_3d: remove duplicated interpolation method #733
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cb101ed
Remove duplicated interpolation method
nhatao 322ffbd
Remove unnecessary change
nhatao 5c9e66a
Add multiple resolution
nhatao 76c12c1
Small fixes
nhatao 0205166
Fix some parameter names
nhatao 77e3ddf
Address comments
nhatao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 0 additions & 66 deletions
66
planner_cspace/include/planner_cspace/planner_3d/path_interpolator.h
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ | |
#include <unordered_map> | ||
#include <vector> | ||
|
||
#include <ros/ros.h> | ||
|
||
#include <planner_cspace/cyclic_vec.h> | ||
#include <planner_cspace/planner_3d/motion_cache.h> | ||
|
||
|
@@ -43,7 +45,8 @@ void MotionCache::reset( | |
const float linear_resolution, | ||
const float angular_resolution, | ||
const int range, | ||
const std::function<void(CyclicVecInt<3, 2>, size_t&, size_t&)> gm_addr) | ||
const std::function<void(CyclicVecInt<3, 2>, size_t&, size_t&)> gm_addr, | ||
const float interpolation_interval) | ||
{ | ||
const int angle = std::lround(M_PI * 2 / angular_resolution); | ||
|
||
|
@@ -80,17 +83,17 @@ void MotionCache::reset( | |
const float cos_v = cosf(motion[2]); | ||
const float sin_v = sinf(motion[2]); | ||
|
||
const float inter = 1.0 / d.len(); | ||
const float inter = interpolation_interval / d.len(); | ||
|
||
if (std::abs(sin_v) < 0.1) | ||
{ | ||
for (float i = 0; i < 1.0; i += inter) | ||
for (float i = 0; i < 1.0 - inter / 2; i += inter) | ||
{ | ||
const float x = diff_val[0] * i; | ||
const float y = diff_val[1] * i; | ||
|
||
CyclicVecInt<3, 2> pos( | ||
x / linear_resolution, y / linear_resolution, yaw / angular_resolution); | ||
CyclicVecFloat<3, 2> posf(x / linear_resolution, y / linear_resolution, yaw / angular_resolution); | ||
CyclicVecInt<3, 2> pos(posf[0], posf[1], posf[2]); | ||
pos.cycleUnsigned(angle); | ||
if (registered.find(pos) == registered.end()) | ||
{ | ||
|
@@ -99,6 +102,7 @@ void MotionCache::reset( | |
max_range[i] = std::max(max_range[i], std::abs(pos[i])); | ||
registered[pos] = true; | ||
} | ||
page.motion_f_.push_back(posf); | ||
} | ||
page.distance_ = d.len(); | ||
cache_[syaw][d] = page; | ||
|
@@ -124,7 +128,7 @@ void MotionCache::reset( | |
|
||
CyclicVecFloat<3, 2> posf_prev(0, 0, 0); | ||
|
||
for (float i = 0; i < 1.0; i += inter) | ||
for (float i = 0; i < 1.0 - inter / 2; i += inter) | ||
{ | ||
const float r = r1 * (1.0 - i) + r2 * i; | ||
const float cx2 = cx_s * (1.0 - i) + cx * i; | ||
|
@@ -137,14 +141,15 @@ void MotionCache::reset( | |
(cy2 - r * sinf(cyaw + M_PI / 2)) / linear_resolution, | ||
cyaw / angular_resolution, | ||
}; | ||
const CyclicVecFloat<3, 2> posf(posf_raw[0], posf_raw[1], posf_raw[2]); | ||
CyclicVecFloat<3, 2> posf(posf_raw[0], posf_raw[1], posf_raw[2]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it required to remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
CyclicVecInt<3, 2> pos(posf_raw[0], posf_raw[1], posf_raw[2]); | ||
pos.cycleUnsigned(angle); | ||
if (registered.find(pos) == registered.end()) | ||
{ | ||
page.motion_.push_back(pos); | ||
registered[pos] = true; | ||
} | ||
page.motion_f_.push_back(posf); | ||
distf += (posf - posf_prev).len(); | ||
posf_prev = posf; | ||
} | ||
|
@@ -174,5 +179,42 @@ void MotionCache::reset( | |
} | ||
max_range_ = max_range; | ||
} | ||
|
||
std::list<CyclicVecFloat<3, 2>> MotionCache::interpolatePath(const std::list<CyclicVecInt<3, 2>>& grid_path) const | ||
{ | ||
std::list<CyclicVecFloat<3, 2>> result; | ||
if (grid_path.size() < 2) | ||
{ | ||
return result; | ||
} | ||
auto it_prev = grid_path.begin(); | ||
for (auto it = std::next(it_prev); it != grid_path.end(); ++it, ++it_prev) | ||
{ | ||
if (((*it_prev)[0] == (*it)[0]) && ((*it_prev)[1] == (*it)[1])) | ||
{ | ||
result.push_back(CyclicVecFloat<3, 2>((*it_prev)[0], (*it_prev)[1], (*it_prev)[2])); | ||
continue; | ||
} | ||
|
||
const auto motion_it = find(*it_prev, *it); | ||
if (motion_it == end((*it)[2])) | ||
{ | ||
ROS_ERROR("Failed to find motion between [%d %d %d] and [%d %d %d]", | ||
(*it_prev)[0], (*it_prev)[1], (*it_prev)[2], (*it)[0], (*it)[1], (*it)[2]); | ||
result.push_back(CyclicVecFloat<3, 2>((*it_prev)[0], (*it_prev)[1], (*it_prev)[2])); | ||
} | ||
else | ||
{ | ||
const auto& motion = motion_it->second.getInterpolatedMotion(); | ||
for (const auto& pos_diff : motion) | ||
{ | ||
result.push_back(CyclicVecFloat<3, 2>((*it_prev)[0] + pos_diff[0], (*it_prev)[1] + pos_diff[1], pos_diff[2])); | ||
} | ||
} | ||
} | ||
result.push_back(CyclicVecFloat<3, 2>(grid_path.back()[0], grid_path.back()[1], grid_path.back()[2])); | ||
return result; | ||
} | ||
|
||
} // namespace planner_3d | ||
} // namespace planner_cspace |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done