cheshirekow  v0.1.0
SolutionRSL.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_RSL_HPP_
27 #define MPBLOCKS_DUBINS_CURVES_EIGEN_SOLUTION_RSL_HPP_
28 
32 
33 namespace mpblocks {
34 namespace dubins {
35 namespace curves_eigen {
36 
38 template <typename Scalar>
39 struct Solver<RSL, Scalar> {
40  typedef Eigen::Matrix<Scalar, 3, 1> Vector3d;
41  typedef Eigen::Matrix<Scalar, 2, 1> Vector2d;
42 
43  static Path<Scalar> solve(const Vector3d& q0, const Vector3d& q1,
44  const Scalar r) {
45  Path<Scalar> out(RSL);
46  Vector2d c[2];
47  Vector3d s;
48 
49  // calculate the center of the circle to which q1 is tangent
50  c[0] = rightCenter(q0, r);
51 
52  // calculate the center of the circle to which q2 is tangent
53  c[1] = leftCenter(q1, r);
54 
55  // find the vector between the two
56  Vector2d v = c[1] - c[0];
57 
58  // calculate the distance between the two
59  Scalar d = v.norm();
60 
61  // if they overlap then this primitive has no solution and is not the
62  // optimal primitive
63  if (d < 2 * r) {
64  return out;
65  }
66 
67  // find the angle between the line through centers and the radius that
68  // points to the tangent on the circle
69  Scalar a = std::acos(2 * r / d);
70 
71  // the distance of the straight segment
72  s[1] = d * std::sin(a);
73 
74  // this is the angle of dc
75  Scalar b = std::atan2(v[1], v[0]);
76 
77  // the arc location of the tanget point gives us the first arc length
78  Scalar t0 = rightAngleOf(q0);
79  Scalar t1 = clampRadian(b + a);
80  s[0] = cwArc(t0, t1);
81 
82  // the second arc length
83  t0 = clampRadian(t1 + M_PI);
84  t1 = leftAngleOf(q1);
85  s[2] = ccwArc(t0, t1);
86 
87  out = s;
88  return out;
89  }
90 };
91 
92 } // curves_eigen
93 } // dubins
94 } // mpblocks
95 
96 #endif // MPBLOCKS_DUBINS_CURVES_EIGEN_SOLUTION_RSL_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
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
empty struct used to template "variant" of three arc primitives
Definition: types.h:46
__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
empty struct used to template "variant" of three arc primitives
Definition: types.h:43
static Path< Scalar > solve(const Vector3d &q0, const Vector3d &q1, const Scalar r)
Definition: SolutionRSL.hpp:43
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
__host__ __device__ Format_t clampRadian(Format_t a)
wraps the input onto [-pi,pi]
Definition: funcs.hpp:37
interface for different solutions, this is specialized for each Id in the SolutionId enum ...
Definition: solver.h:39
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