cheshirekow  v0.1.0
SolutionRSR.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_RSR_HPP_
27 #define MPBLOCKS_DUBINS_CURVES_EIGEN_SOLUTION_RSR_HPP_
28 
32 
33 namespace mpblocks {
34 namespace dubins {
35 namespace curves_eigen {
36 
38 template <typename Scalar>
39 struct Solver<RSR, 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(RSR);
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 
53  c[1] = rightCenter(q1, r);
54 
55  // find the vector between the two
56  Vector2d v = c[1] - c[0];
57 
58  // the length of the straight segment is the length of this vector
59  s[1] = v.norm();
60 
61  // the angle of this vector is the target angle for the vehicle when
62  // it leaves the circle
63  Scalar t0 = q0[2];
64  Scalar t1 = std::atan2(v[1], v[0]);
65  s[0] = cwArc(t0, t1);
66 
67  t0 = t1;
68  t1 = q1[2];
69  s[2] = cwArc(t0, t1);
70 
71  out = s;
72  return out;
73  }
74 };
75 
76 } // curves_eigen
77 } // dubins
78 } // mpblocks
79 
80 #endif // MPBLOCKS_DUBINS_CURVES_EIGEN_SOLUTION_RSR_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
static Path< Scalar > solve(const Vector3d &q0, const Vector3d &q1, const Scalar r)
Definition: SolutionRSR.hpp:43
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