Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <list>
00031
00032 #include <planner_cspace/cyclic_vec.h>
00033 #include <planner_cspace/planner_3d/rotation_cache.h>
00034 #include <planner_cspace/planner_3d/path_interpolator.h>
00035
00036 std::list<CyclicVecFloat<3, 2>> PathInterpolator::interpolate(
00037 const std::list<CyclicVecInt<3, 2>>& path_grid,
00038 const float interval,
00039 const int local_range) const
00040 {
00041 CyclicVecInt<3, 2> p_prev(0, 0, 0);
00042 bool init = false;
00043
00044 std::list<CyclicVecFloat<3, 2>> path;
00045
00046 for (auto p : path_grid)
00047 {
00048 p.cycleUnsigned(angle_);
00049
00050 if (init)
00051 {
00052 const CyclicVecInt<3, 2> ds = path_grid.front() - p;
00053 CyclicVecInt<3, 2> d = p - p_prev;
00054 d.cycle(angle_);
00055 const CyclicVecInt<3, 2> d2(d[0] + range_, d[1] + range_, p[2]);
00056
00057 const float inter = interval / d.len();
00058
00059 if (d[0] == 0 && d[1] == 0)
00060 {
00061 const int yaw_inc = std::copysign(1, d[2]);
00062 for (int yaw = p_prev[2]; yaw != p_prev[2] + d[2]; yaw += yaw_inc)
00063 {
00064 path.push_back(CyclicVecFloat<3, 2>(p[0], p[1], yaw));
00065 }
00066 }
00067 else if (d[2] == 0 || ds.sqlen() > local_range * local_range)
00068 {
00069 for (float i = 0; i < 1.0; i += inter)
00070 {
00071 const float x2 = p_prev[0] * (1 - i) + p[0] * i;
00072 const float y2 = p_prev[1] * (1 - i) + p[1] * i;
00073 const float yaw2 = p_prev[2] + i * d[2];
00074
00075 path.push_back(CyclicVecFloat<3, 2>(x2, y2, yaw2));
00076 }
00077 }
00078 else
00079 {
00080 const auto& radiuses = rot_cache_.getRadiuses(p_prev[2], d2);
00081 const float r1 = radiuses.first;
00082 const float r2 = radiuses.second;
00083 const float yawf = p[2] * M_PI * 2.0 / angle_;
00084 const float yawf_prev = p_prev[2] * M_PI * 2.0 / angle_;
00085
00086 const float cx = p[0] + r2 * cosf(yawf + M_PI / 2);
00087 const float cy = p[1] + r2 * sinf(yawf + M_PI / 2);
00088 const float cx_prev = p_prev[0] + r1 * cosf(yawf_prev + M_PI / 2);
00089 const float cy_prev = p_prev[1] + r1 * sinf(yawf_prev + M_PI / 2);
00090
00091 for (float i = 0; i < 1.0; i += inter)
00092 {
00093 const float r = r1 * (1.0 - i) + r2 * i;
00094 const float cx2 = cx_prev * (1.0 - i) + cx * i;
00095 const float cy2 = cy_prev * (1.0 - i) + cy * i;
00096 const float cyaw = p_prev[2] + i * d[2];
00097 const float cyawf = cyaw * M_PI * 2.0 / angle_;
00098
00099 const float x2 = cx2 - r * cosf(cyawf + M_PI / 2);
00100 const float y2 = cy2 - r * sinf(cyawf + M_PI / 2);
00101
00102 path.push_back(CyclicVecFloat<3, 2>(x2, y2, cyaw));
00103 }
00104 }
00105 }
00106 p_prev = p;
00107 init = true;
00108 }
00109 path.push_back(CyclicVecFloat<3, 2>(path_grid.back()));
00110 return path;
00111 }