grid_astar_model_2dof_joints.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020, the neonavigation authors
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <cmath>
31 #include <utility>
32 #include <vector>
33 
37 
39 
40 namespace planner_cspace
41 {
42 namespace planner_2dof_serial_joints
43 {
45  const Vecf& euclid_cost_coef,
46  const int resolution,
48  const CostCoeff& cc,
49  const int range)
50  : euclid_cost_coef_(euclid_cost_coef)
51  , resolution_(resolution)
52  , cm_(cm)
53  , cc_(cc)
54  , range_(range)
55 {
56  for (Vec p(-range, -range); p[0] <= range; p[0]++)
57  {
58  for (p[1] = -range; p[1] <= range; p[1]++)
59  {
60  search_list_.push_back(p);
61  }
62  }
63 }
65 {
66  auto vc = v;
67  float cost = 0;
68  for (int i = 0; i < 2; i++)
69  {
70  cost += std::abs(euclid_cost_coef_[i] * vc[i]);
71  }
72  return cost;
73 }
75  const Vec& cur, const Vec& next, const std::vector<VecWithCost>& start, const Vec& goal) const
76 {
77  if ((unsigned int)next[0] >= (unsigned int)resolution_ * 2 ||
78  (unsigned int)next[1] >= (unsigned int)resolution_ * 2)
79  return -1;
80  Vec d = next - cur;
81  d.cycle(resolution_, resolution_);
82 
83  float cost = euclidCost(d);
84 
85  float distf = std::hypot(static_cast<float>(d[0]), static_cast<float>(d[1]));
86  float v[2], dp[2];
87  int sum = 0;
88  const int dist = distf;
89  distf /= dist;
90  v[0] = cur[0];
91  v[1] = cur[1];
92  dp[0] = static_cast<float>(d[0]) / dist;
93  dp[1] = static_cast<float>(d[1]) / dist;
94  Vec pos;
95  for (int i = 0; i < dist; i++)
96  {
97  pos[0] = std::lround(v[0]);
98  pos[1] = std::lround(v[1]);
99  pos.cycleUnsigned(resolution_, resolution_);
100  const auto c = cm_[pos];
101  if (c > 99)
102  return -1;
103  sum += c;
104  v[0] += dp[0];
105  v[1] += dp[1];
106  }
107  cost += sum * cc_.weight_cost_ / 100.0;
108  return cost;
109 }
110 
112  const Vec& cur, const Vec& goal) const
113 {
114  const Vec d = goal - cur;
115  return euclidCost(d);
116 }
117 const std::vector<GridAstarModel2DoFSerialJoint::Vec>& GridAstarModel2DoFSerialJoint::searchGrids(
118  const Vec& p,
119  const std::vector<VecWithCost>& ss,
120  const Vec& es) const
121 {
122  return search_list_;
123 }
124 } // namespace planner_2dof_serial_joints
125 } // namespace planner_cspace
d
void cycle(const int res, const ArgList &...rest)
Definition: cyclic_vec.h:282
GridAstarModel2DoFSerialJoint(const Vecf &euclid_cost_coef, const int resolution, BlockMemGridmapBase< char, 2, 0 > &cm, const CostCoeff &cc, const int range)
void cycleUnsigned(const int res, const ArgList &...rest)
Definition: cyclic_vec.h:289
float cost(const Vec &cur, const Vec &next, const std::vector< VecWithCost > &start, const Vec &goal) const override
const std::vector< Vec > & searchGrids(const Vec &p, const std::vector< VecWithCost > &ss, const Vec &es) const override


planner_cspace
Author(s): Atsushi Watanabe
autogenerated on Wed May 12 2021 02:20:42