cheshirekow  v0.1.0
path.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
26 #ifndef MPBLOCKS_DUBINS_CURVES_PATH_H_
27 #define MPBLOCKS_DUBINS_CURVES_PATH_H_
28 
29 #include <Eigen/Dense>
31 
32 namespace mpblocks {
33 namespace dubins {
34 
36 
41 template <typename Format_t>
42 struct Path {
43  typedef Eigen::Matrix<Format_t, 3, 1> Vector3d;
44 
45  int id;
46  bool f;
48 
51  id = other.id;
52  f = other.f;
53  s = other.s;
54  }
55 
56  Path() : id(INVALID), f(false) { s.fill(0); }
57 
60 
61  Path(int id) : id(id), f(false) { s.fill(0); }
62 
64 
65  Path(int id, const Vector3d& s) : id(id), f(true), s(s) { s.fill(0); }
66 
69 
71  f = true;
72  s = s_in;
73  return *this;
74  }
75 
77  f = other.f;
78  s = other.s;
79  id = other.id;
80  return *this;
81  }
82 
84  Format_t dist(const Format_t r) const {
85  if (id < 4)
86  return r * s.sum();
87  else
88  return r * (s[0] + s[2]) + s[1];
89  }
90 
92  operator bool() const { return f; }
93 };
94 
95 template <typename Format_t>
97  const Format_t r) {
98  if (r0.f && r1.f) {
99  if (r0.dist(r) < r1.dist(r))
100  return r0;
101  else
102  return r1;
103  } else if (r0.f)
104  return r0;
105  else if (r1.f)
106  return r1;
107  else
108  return Path<Format_t>();
109 }
110 
111 } // dubins
112 } // mpblocks
113 
114 #endif // MPBLOCKS_DUBINS_CURVES_PATH_H_
bool f
is feasible
Definition: path.h:46
Path(int id, const Vector3d &s)
we only use this constructor when it's feasible
Definition: path.h:65
Path< Format_t > & operator=(const Vector3d &s_in)
fill and set to feasible, returns itself so that we can do the return in one line ...
Definition: path.h:70
Path(const Path< Format_t > &other)
Definition: path.h:50
Format_t dist(const Format_t r) const
compute distance based on id
Definition: path.h:84
Vector3d s
lengths of each segment, how it's interpreted depends on id
Definition: path.h:47
int id
identifies the type of path
Definition: path.h:45
Path(int id)
the default constructor marks it as infeasible, so we can return it immediately
Definition: path.h:61
BinaryKey other(const BinaryKey &key)
Definition: BinaryKey.h:44
Encodes a dubins path primitive, which is three connected arc segments.
Definition: path.h:42
Path< Format_t > bestOf(const Path< Format_t > &r0, const Path< Format_t > &r1, const Format_t r)
Definition: path.h:96
Path< Format_t > & operator=(const Path< Format_t > &other)
Definition: path.h:76
Eigen::Matrix< Format_t, 3, 1 > Vector3d
Definition: path.h:43