path_interpolator.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2019, the neonavigation authors
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the copyright holder nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
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 }


planner_cspace
Author(s): Atsushi Watanabe
autogenerated on Sat Jun 22 2019 20:07:27