cheshirekow  v0.1.0
LSR.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_TWO_THETA_Y_LSR_H_
27 #define MPBLOCKS_DUBINS_CURVES_EIGEN_HYPER_TWO_THETA_Y_LSR_H_
28 
29 namespace mpblocks {
30 namespace dubins {
31 namespace curves_eigen {
32 namespace hyper {
33 namespace two_theta_y {
34 
36 template <int ySpec, int tSpec, typename Format_t>
37 struct Solver<ySpec, tSpec, LSR, Format_t> {
38  typedef Eigen::Matrix<Format_t, 3, 1> Vector3d_t;
39  typedef Eigen::Matrix<Format_t, 2, 1> Vector2d_t;
42 
43  static const unsigned int SPEC = SpecPack<OFF, ySpec, tSpec>::Result;
44 
45  static Result_t solve(const Vector3d_t& q0, const Hyper_t& h,
46  const Format_t r) {
47  Result_t out[3];
48  for (int i = 0; i < 3; i++) {
49  out[i].id = LSR;
50  }
51 
52  // calculate the center of the turn
53  const Vector2d_t c0 = leftCenter(q0, r);
54 
55  // the goal point (we'll vary the x coordinate)
56  Vector3d_t q1;
57  q1 << q0[0], get_constraint<ySpec, 1>(h), get_constraint<tSpec, 2>(h);
58 
59  // the center of the goal point (we'll vary the x coordinate)
60  Vector2d_t c1 = rightCenter(q1, r);
61 
62  const Format_t alpha0 = leftAngleOf(q0);
63  const Format_t alpha1 = rightAngleOf(q1);
64 
65  // vertical distance between centers
66  const Format_t dy = c1[1] - c0[1];
67 
69  Format_t dist, dist_i, d1, arc0, arc1;
70 
72  Format_t target;
73  if (dy > 0)
74  target = M_PI / 2;
75  else
76  target = -M_PI / 2;
77 
78  d1 = std::abs(dy);
79  arc0 = ccwArc(q0[2], target);
80  arc1 = cwArc(target, q1[2]);
81  dist = r * (arc0 + arc1) + d1;
82 
83  out[0] = Vector3d_t(arc0, d1, arc1);
84  int iBest = 0;
85 
90  Format_t sinTheta = std::sin(q0[2]);
91  if ((dy > 0 && sinTheta > 0) || (dy < 0 && sinTheta < 0)) {
92  d1 = (dy - 2 * r * std::sin(alpha0)) / sinTheta;
93  if (d1 > 0) {
94  arc0 = 0;
95  arc1 = cwArc(q0[2], q1[2]);
96  dist_i = r * (arc0 + arc1) + d1;
97  out[1] = Vector3d_t(arc0, d1, arc1);
98  if (dist_i < dist) {
99  iBest = 1;
100  dist = dist_i;
101  }
102  }
103  }
104 
105  sinTheta = std::sin(q1[2]);
106  if ((dy > 0 && sinTheta > 0) || (dy < 0 && sinTheta < 0)) {
107  d1 = (dy + 2 * r * std::sin(alpha1)) / sinTheta;
108  if (d1 > 0) {
109  arc0 = ccwArc(q0[2], q1[2]);
110  arc1 = 0;
111  dist_i = r * (arc0 + arc1) + d1;
112  out[2] = Vector3d_t(arc0, d1, arc1);
113  if (dist_i < dist) {
114  iBest = 2;
115  dist = dist_i;
116  }
117  }
118  }
119 
120  return out[iBest];
121  };
122 };
123 
124 } // namespace two_theta_y
125 } // namespace hyper
126 } // namespace curves_eigen
127 } // namespace dubins
128 } // namespace mpblocks
129 
130 #endif // MPBLOCKS_DUBINS_CURVES_EIGEN_HYPER_TWO_THETA_Y_LSR_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
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
static Result_t solve(const Vector3d_t &q0, const Hyper_t &h, const Format_t r)
Definition: LSR.hpp:45
__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
interface for variants of solvers, default template is never instantiated
Definition: Solver.hpp:41
int id
identifies the type of path
Definition: path.h:45
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
Eigen::Matrix< Scalar, 2, 1 > rightCenter(const Eigen::Matrix< Scalar, 3, 1 > &q, Scalar r)
return the center of a clockwise (right) circle coincident to q with radius r
Definition: funcs.hpp:76
Encodes a dubins path primitive, which is three connected arc segments.
Definition: path.h:42
Eigen::Matrix< Scalar, 2, 1 > leftCenter(const Eigen::Matrix< Scalar, 3, 1 > &q, Scalar r)
return the center of a counter clockwise (left) circle coincident to q with radius r ...
Definition: funcs.hpp:54