cheshirekow  v0.1.0
SolutionLSR.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_LSR_HPP_
27 #define MPBLOCKS_DUBINS_CURVES_EIGEN_SOLUTION_LSR_HPP_
28 
32 
33 namespace mpblocks {
34 namespace dubins {
35 namespace curves_eigen {
36 
38 template <typename Scalar>
39 struct Solver<LSR, 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(LSR);
46  Vector2d c[2];
47  Vector3d s;
48 
49  // calculate the center of the circle to which q1 is tangent
50  c[0] = leftCenter(q0, r);
51 
52  // calculate the center of the circle to which q2 is tangent
53  c[1] = rightCenter(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 the distance is too large, then this primitive is not the solution,
64  // and we can bail here
65  if (d < 2 * r) {
66  return out;
67  }
68 
69  // let dc be the vector from the first center to the second. Let
70  // dt be the vector from the first center to the point on the circle
71  // where the car leaves the circle. This is the angle between the two
72  Scalar a = std::acos(2 * r / d);
73 
74  // the distance of the straight segment is
75  s[1] = d * std::sin(a);
76 
77  // this is the angle of dc
78  Scalar b = std::atan2(v[1], v[0]);
79 
80  // the arc location of the tangent point gives us the first arc length
81  Scalar t0 = leftAngleOf(q0);
82  Scalar t1 = clampRadian(b - a);
83  s[0] = ccwArc(t0, t1);
84 
85  // and the second arc length
86  t0 = clampRadian(t1 + M_PI);
87  t1 = rightAngleOf(q1);
88  s[2] = cwArc(t0, t1);
89 
90  out = s;
91  return out;
92  }
93 };
94 
95 } // curves_eigen
96 } // dubins
97 } // mpblocks
98 
99 #endif // MPBLOCKS_DUBINS_CURVES_EIGEN_SOLUTION_LSR_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
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
static Path< Scalar > solve(const Vector3d &q0, const Vector3d &q1, const Scalar r)
Definition: SolutionLSR.hpp:43
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