cheshirekow  v0.1.0
one_y.hpp
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_EIGEN_HYPER_ONE_Y_H_
27 #define MPBLOCKS_DUBINS_CURVES_EIGEN_HYPER_ONE_Y_H_
28 
29 namespace mpblocks {
30 namespace dubins {
31 namespace curves_eigen {
32 namespace hyper {
33 
35 template <int ySpec, typename Format_t>
36 struct Solver<OFF, ySpec, OFF, Format_t> {
37  typedef Eigen::Matrix<Format_t, 3, 1> Vector3d_t;
38  typedef Eigen::Matrix<Format_t, 2, 1> Vector2d_t;
41 
42  static const unsigned int SPEC = SpecPack<OFF, ySpec, OFF>::Result;
43 
45  static Result_t solveLS(const Vector3d_t& q0, const Hyper_t& h,
46  const Format_t r) {
47  Result_t out(LSL);
48  const Format_t _PI = static_cast<Format_t>(M_PI);
49 
50  // calculate the center of the circle to which q0 is tangent
51  Vector2d_t x, v, c;
52  x << q0[0], q0[1];
53  v << -std::sin(q0[2]), std::cos(q0[2]);
54  c = x + r * v;
55 
56  // grab the X value
57  Format_t Y = get_constraint<ySpec, 1>(h);
58 
59  // if the solution is less than r from this center, then there is no
60  // straight section and we simply turn left until we hit x = x
61  if (std::abs(c[1] - Y) < r) {
62  Format_t theta1 = std::asin((Y - c[1]) / r);
63  Format_t theta0 = leftAngleOf(q0);
64  Format_t dist0 = ccwArc(theta0, theta1);
65  Format_t dist1;
66  if (theta1 > 0)
67  dist1 = ccwArc(theta0, _PI - theta1);
68  else
69  dist1 = ccwArc(theta0, -_PI - theta1);
70  Format_t arc0 = std::min(dist0, dist1);
71 
72  out = Vector3d_t(arc0, 0, 0);
73  return out;
74  }
75 
76  // otherwise we turn left until we are perpendicular to the constraint
77  // and pointed in the right direction, then we go straight the rest of
78  // the way
79 
80  // if the constraint is right of the center then our target is -_PI/2.
81  // otherwise it's _PI/2;
82  Format_t target = _PI;
83  if (Y > c[1]) target = 0;
84 
85  // we turn until we hit this point
86  Format_t theta0 = leftAngleOf(q0);
87  Format_t arc0 = ccwArc(theta0, target);
88 
89  // then we drive straight until we hit the constraint
90  Format_t d1 = std::abs(Y - c[1]);
91 
92  out = Vector3d_t(arc0, d1, 0);
93  return out;
94  };
95 
96  static Result_t solveRS(const Vector3d_t& q0, const Hyper_t& h,
97  const Format_t r) {
98  Result_t out(RSR);
99  const Format_t _PI = static_cast<Format_t>(M_PI);
100 
101  // calculate the center of the circle to which q0 is tangent
102  Vector2d_t x, v, c;
103  x << q0[0], q0[1];
104  v << std::sin(q0[2]), -std::cos(q0[2]);
105  c = x + r * v;
106 
107  // grab the X value
108  Format_t Y = get_constraint<ySpec, 1>(h);
109 
110  // if the solution is less than r from this center, then there is no
111  // straight section and we simply turn left until we hit x = x
112  if (std::abs(c[1] - Y) < r) {
113  Format_t theta1 = std::asin((Y - c[1]) / r);
114  Format_t theta0 = rightAngleOf(q0);
115  Format_t dist0 = cwArc(theta0, theta1);
116  Format_t dist1;
117  if (theta1 > 0)
118  dist1 = cwArc(theta0, _PI - theta1);
119  else
120  dist1 = cwArc(theta0, -_PI - theta1);
121  Format_t arc0 = dist0;
122  std::min(dist0, dist1);
123 
124  out = Vector3d_t(arc0, 0, 0);
125  return out;
126  }
127 
128  // otherwise we turn left until we are perpendicular to the constraint
129  // and pointed in the right direction, then we go straight the rest of
130  // the way
131 
132  // if the constraint is right of the center then our target is -_PI/2.
133  // otherwise it's _PI/2;
134  Format_t target = 0;
135  if (Y > c[1]) target = _PI;
136 
137  // we turn until we hit this point
138  Format_t theta0 = rightAngleOf(q0);
139  Format_t arc0 = cwArc(theta0, target);
140 
141  // then we drive straight until we hit the constraint
142  Format_t d1 = std::abs(Y - c[1]);
143 
144  out = Vector3d_t(arc0, d1, 0);
145  return out;
146  };
147 
148  static Result_t solve(const Vector3d_t& q0, const Hyper_t& h,
149  const Format_t r) {
150  return bestOf(solveLS(q0, h, r), solveRS(q0, h, r), r);
151  };
152 };
153 
154 } // namespace hyper
155 } // namespace curves_eigen
156 } // namespace dubins
157 } // namespace mpblocks
158 
159 #endif // MPBLOCKS_DUBINS_CURVES_EIGEN_HYPER_ONE_Y_H_
__host__ __device__ Format_t cwArc(Format_t a, Format_t b)
returns the clockwise (right) distance from a to b
Definition: funcs.hpp:72
static Result_t solveLS(const Vector3d_t &q0, const Hyper_t &h, const Format_t r)
get the distance for a left turn
Definition: one_y.hpp:45
the default solver is instantated when not all three constraints are active and it simply dispatches ...
Definition: Solver.hpp:95
Scalar leftAngleOf(const Scalar q_theta)
return the angle of the vector from the center of the counter clockwise (left) circle coincident to q...
Definition: funcs.hpp:87
__host__ __device__ Format_t ccwArc(Format_t a, Format_t b)
returns the counter clockwise (left) distance from a to b
Definition: funcs.hpp:51
Eigen::Matrix< Format_t, 3, 1 > Vector3d_t
Definition: Solver.hpp:96
static Result_t solve(const Vector3d_t &q0, const Hyper_t &h, const Format_t r)
Definition: one_y.hpp:148
A hyper-rectangle in dubins space: A rectangular prism in R^3.
Definition: hyper_rect.h:44
Scalar rightAngleOf(const Scalar q_theta)
return the angle of the vector from the center of the clockwise (right) circle coincident to q...
Definition: funcs.hpp:107
Encodes a dubins path primitive, which is three connected arc segments.
Definition: path.h:42
static Result_t solveRS(const Vector3d_t &q0, const Hyper_t &h, const Format_t r)
Definition: one_y.hpp:96
Path< Format_t > bestOf(const Path< Format_t > &r0, const Path< Format_t > &r1, const Format_t r)
Definition: path.h:96