cheshirekow  v0.1.0
SolutionRLRb.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_SOLUTION_RLR_B_HPP_
27 #define MPBLOCKS_DUBINS_CURVES_EIGEN_SOLUTION_RLR_B_HPP_
28 
32 
33 namespace mpblocks {
34 namespace dubins {
35 namespace curves_eigen {
36 
38 
50 template <typename Scalar>
51 struct Solver<RLRb, Scalar> {
52  typedef Eigen::Matrix<Scalar, 3, 1> Vector3d;
53  typedef Eigen::Matrix<Scalar, 2, 1> Vector2d;
54 
55  static Path<Scalar> solve(const Vector3d& q0, const Vector3d& q1,
56  const Scalar r) {
57  Path<Scalar> out(RLRb);
58  Vector2d c[3];
59  Vector3d s;
60 
61  // calculate the center of the circle to which q1 is tangent
62  c[0] = rightCenter(q0, r);
63 
64  // calculate the center of the circle to which q2 is tangent
65  c[2] = rightCenter(q1, r);
66 
67  // the distance between the centers of these two circles
68  Scalar d = (c[0] - c[2]).norm();
69 
70  // if the distance is too large, then this primitive is not the solution,
71  // and we can bail here
72  if (d > 4 * r) {
73  return out;
74  }
75 
76  // if the distance is zero then the geometry degenerates
77  if (d == 0) {
78  out = Vector3d(0, 0, 0);
79  return out;
80  }
81 
82  // the base angle of the isosceles triangle whose vertices are the centers
83  // of the the three circles, note acos returns [0,pi]
84  Scalar a = acos(d / (4 * r));
85 
86  // create a clockwise rotation of magnitude alpha
87  Eigen::Rotation2D<Scalar> R(-a);
88 
89  // we find the third vertex of this triangle by taking the vector between
90  // the two circle centers, normalizing it, and rotating it by alpha, and
91  // scaling it to magnitude 2r, then it points from the center of
92  // one the circle tangent to q1 to the third vertex
93  c[1] = c[2] + R * (c[0] - c[2]).normalized() * 2 * r;
94 
95  // calculate the arc distance we travel on the first circle
96  Vector2d dc = c[1] - c[0]; //< vector between centers of circles
97  Scalar a0 = rightAngleOf(q0); //< angle of vector from center to q1
98  Scalar a1 = std::atan2(dc[1], dc[0]); //< angle of that vector
99  s[0] = cwArc(a0, a1); //< ccwise distance
100 
101  // calculate the arc distance we travel on the third circle
102  s[1] = M_PI - 2 * a;
103 
104  // calculate the arc distance we travel on the second circle
105  dc = c[1] - c[2]; //< vector between centers of circles
106  a0 = std::atan2(dc[1], dc[0]); //< angle of that vector
107  a1 = rightAngleOf(q1); //< angle of vector from center to q1
108  s[2] = cwArc(a0, a1); //< ccwise distance
109 
110  out = s;
111  return out;
112  }
113 };
114 
115 } // curves_eigen
116 } // dubins
117 } // mpblocks
118 
119 #endif // MPBLOCKS_DUBINS_CURVES_EIGEN_SOLUTION_RLR_B_HPP_
__host__ __device__ Format_t cwArc(Format_t a, Format_t b)
returns the clockwise (right) distance from a to b
Definition: funcs.hpp:72
Matrix< double, 3, 1 > Vector3d
Definition: matrix.h:145
empty struct used to template "variant" of three arc primitives
Definition: types.h:43
empty struct used to template "right turn" primitive
Definition: types.h:37
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
interface for different solutions, this is specialized for each Id in the SolutionId enum ...
Definition: solver.h:39
__device__ __host__ Scalar norm(const RValue< Scalar, ROWS, COLS, Exp > &M)
compute the norm
Definition: Norm.h:140
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
__host__ __device__ Normalized< Scalar, Exp, Spec > normalized(const RValue< Scalar, Exp, Spec > &exp)
Definition: Normalized.h:72
Encodes a dubins path primitive, which is three connected arc segments.
Definition: path.h:42
static Path< Scalar > solve(const Vector3d &q0, const Vector3d &q1, const Scalar r)