position_velocity_rel_planar_dubins_3d.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, The Regents of the University of California (Regents).
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following
14  * disclaimer in the documentation and/or other materials provided
15  * with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * Please contact the author(s) of this library if you have any questions.
34  * Authors: David Fridovich-Keil ( dfk@eecs.berkeley.edu )
35  * Jaime F. Fisac ( jfisac@eecs.berkeley.edu )
36  */
37 
39 //
40 // Class for relative state computed between PositionVelocity and
41 // PlanarDubins3D.
42 //
43 // NOTE! Because this is a relative state, we do NOT support
44 // sampling or configuration space conversions.
45 //
47 
48 #ifndef FASTRACK_STATE_POSITION_VELOCITY_REL_PLANAR_DUBINS_3D_H
49 #define FASTRACK_STATE_POSITION_VELOCITY_REL_PLANAR_DUBINS_3D_H
50 
54 
55 namespace fastrack {
56 namespace state {
57 
59  : public RelativeState<PositionVelocity, PlanarDubins3D> {
60 public:
62 
63  // NOTE! We do NOT provide a default constructor. Objects from this
64  // class SHOULD be initialized from the two corresponding states.
66  const PlanarDubins3D& planner_x)
67  : distance_(std::hypot(tracker_x.X() - planner_x.X(),
68  tracker_x.Y() - planner_x.Y())),
69  bearing_(std::atan2(tracker_x.Y() - planner_x.Y(),
70  tracker_x.X() - planner_x.X())),
71  tangent_velocity_(std::cos(planner_x.Theta()) * tracker_x.Vx() +
72  std::sin(planner_x.Theta()) * tracker_x.Vy()),
73  normal_velocity_(-std::sin(planner_x.Theta()) * tracker_x.Vx() +
74  std::cos(planner_x.Theta()) * tracker_x.Vy()) {}
75 
76  // Construct from VectorXd.
77  explicit PositionVelocityRelPlanarDubins3D(const VectorXd& x)
79  FromVector(x);
80  }
81 
82  // Construct directly.
83  explicit PositionVelocityRelPlanarDubins3D(double distance, double bearing,
84  double tangent_v, double normal_v)
85  : distance_(distance), bearing_(bearing), tangent_velocity_(tangent_v),
86  normal_velocity_(normal_v) {}
87 
88  // Convert from/to VectorXd.
89  // Assume vector is laid out as follows:
90  // [distance, bearing, tangent velocity, normal velocity]
91  void FromVector(const VectorXd& x) {
92  if (x.size() != StateDimension())
93  throw std::runtime_error("Vector was of incorrect dimension.");
94 
95  distance_ = x(0);
96  bearing_ = x(1);
97  tangent_velocity_ = x(2);
98  normal_velocity_ = x(3);
99  }
100 
101  VectorXd ToVector() const {
102  VectorXd vec(4);
103  vec(0) = distance_;
104  vec(1) = bearing_;
105  vec(2) = tangent_velocity_;
106  vec(3) = normal_velocity_;
107 
108  return vec;
109  }
110 
111  // Dimension of the state space.
112  static constexpr size_t StateDimension() { return 4; }
113 
114  // Accessors.
115  inline double Distance() const { return distance_; }
116  inline double Bearing() const { return bearing_; }
117  inline double TangentVelocity() const { return tangent_velocity_; }
118  inline double NormalVelocity() const { return normal_velocity_; }
119 
120 private:
121  // Relative (x, y) distance.
122  double distance_;
123 
124  // Relative bearing in the (x, y) plane.
125  double bearing_;
126 
127  // PositionVelocity's absolute velocity along PlanarDubins3D's heading.
128  // (in Frenet frame).
130 
131  // PositionVelocity's absolute velocity normal to PlanarDubins3D's heading.
132  // (in Frenet frame).
134 }; //\class PositionVelocityRelPlanarDubins3D
135 
136 } // namespace state
137 } // namespace fastrack
138 
139 #endif
PositionVelocityRelPlanarDubins3D(double distance, double bearing, double tangent_v, double normal_v)
Definition: box.h:53
PositionVelocityRelPlanarDubins3D(const PositionVelocity &tracker_x, const PlanarDubins3D &planner_x)


fastrack
Author(s): David Fridovich-Keil
autogenerated on Mon Aug 3 2020 21:28:37