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  */
36 
38 //
39 // Class for constant-speed Dubins car state.
40 //
42 
43 #ifndef FASTRACK_STATE_PLANAR_DUBINS_3D_H
44 #define FASTRACK_STATE_PLANAR_DUBINS_3D_H
45 
46 #include <fastrack/state/state.h>
47 
48 namespace fastrack {
49 namespace state {
50 
51 class PlanarDubins3D : public State {
52 public:
54  explicit PlanarDubins3D()
55  : State(), x_(0.0), y_(0.0), theta_(0.0), v_(constants::kDefaultSpeed) {}
56  explicit PlanarDubins3D(double x, double y, double theta)
57  : State(), x_(x), y_(y), theta_(theta), v_(constants::kDefaultSpeed) {}
58  explicit PlanarDubins3D(double x, double y, double theta, double v)
59  : State(), x_(x), y_(y), theta_(theta), v_(v) {}
60  explicit PlanarDubins3D(const fastrack_msgs::State &msg);
61  explicit PlanarDubins3D(const VectorXd &config);
62 
63  // Accessors.
64  // NOTE! Since this is planar, we assume that Z is a fixed
65  // static variable.
66  inline double X() const { return x_; }
67  inline double Y() const { return y_; }
68  inline double Z() const { return z_; }
69  inline double Theta() const { return theta_; }
70  inline double V() const { return v_; }
71  inline double Vx() const { return v_ * std::cos(theta_); }
72  inline double Vy() const { return v_ * std::sin(theta_); }
73  inline double Vz() const { return 0.0; }
74 
75  inline Vector3d Position() const { return Vector3d(x_, y_, z_); }
76  inline Vector3d Velocity() const { return Vector3d(Vx(), Vy(), Vz()); }
77  inline VectorXd Configuration() const {
78  VectorXd config(2);
79  config(0) = x_;
80  config(1) = y_;
81 
82  return config;
83  }
84 
85  // Setters.
86  inline double &X() { return x_; }
87  inline double &Y() { return y_; }
88  inline double &Z() { return z_; }
89  inline double &Theta() { return theta_; }
90  inline double &V() { return v_; }
91 
92  // Set non-configuration dimensions to match the given config derivative.
93  void SetConfigurationDot(const VectorXd &configuration_dot);
94 
95  // What are the positions that the system occupies at the current state.
96  // NOTE! For simplicity, this is a finite set. In future, this could
97  // be generalized to a collection of generic obstacles.
98  std::vector<Vector3d> OccupiedPositions() const;
99 
100  // Convert from/to VectorXd. Assume State is [x, y, theta] or
101  // [x, y, theta, v].
102  void FromVector(const VectorXd &x);
103  VectorXd ToVector() const;
104 
105  // Convert from/to ROS message. Assume State is [x, y, theta, v].
106  // or configuration only.
107  void FromRos(const fastrack_msgs::State& msg);
108  fastrack_msgs::State ToRos() const;
109 
110  // Dimension of the state and configuration spaces.
111  static constexpr size_t StateDimension() { return 3; }
112  static constexpr size_t ConfigurationDimension() { return 3; }
113 
114  // Set/get bounds of the state/configuration space.
115  static void SetBounds(const PlanarDubins3D &lower,
116  const PlanarDubins3D &upper);
117  static void SetBounds(const std::vector<double> &lower,
118  const std::vector<double> &upper);
119  static const PlanarDubins3D& GetLower();
120  static const PlanarDubins3D& GetUpper();
121  static VectorXd GetConfigurationLower();
122  static VectorXd GetConfigurationUpper();
123 
124  // Sample from the configuration space associated with this state space.
125  static VectorXd SampleConfiguration();
126 
127  // Sample from the state space itself.
128  // NOTE! Sets v_ to default value.
129  static PlanarDubins3D Sample();
130 
131  // Compound assignment operators.
134  PlanarDubins3D& operator*=(double s);
135  PlanarDubins3D& operator/=(double s);
136 
137  // Binary operators.
139  const PlanarDubins3D& rhs);
141  const PlanarDubins3D& rhs);
142  friend PlanarDubins3D operator*(PlanarDubins3D lhs, double s);
143  friend PlanarDubins3D operator*(double s, PlanarDubins3D rhs);
144  friend PlanarDubins3D operator/(PlanarDubins3D lhs, double s);
145  friend PlanarDubins3D operator/(double s, PlanarDubins3D rhs);
146 
147 private:
148  // (x, y) position, and heading angle theta.
149  double x_;
150  double y_;
151  double theta_;
152 
153  // Parameter for speed.
154  // NOTE! This is NOT a state.
155  double v_;
156 
157  // Static height z.
158  static double z_;
159 
160  // Static state space bounds for this state space.
163 }; //\class PlanarDubins3D
164 
165 } // namespace state
166 } // namespace fastrack
167 
168 #endif
void SetConfigurationDot(const VectorXd &configuration_dot)
PlanarDubins3D & operator*=(double s)
fastrack_msgs::State ToRos() const
friend PlanarDubins3D operator+(PlanarDubins3D lhs, const PlanarDubins3D &rhs)
PlanarDubins3D & operator/=(double s)
static constexpr double kDefaultSpeed
Definition: types.h:76
friend PlanarDubins3D operator/(PlanarDubins3D lhs, double s)
PlanarDubins3D(double x, double y, double theta, double v)
PlanarDubins3D(double x, double y, double theta)
friend PlanarDubins3D operator-(PlanarDubins3D lhs, const PlanarDubins3D &rhs)
void FromVector(const VectorXd &x)
PlanarDubins3D & operator-=(const PlanarDubins3D &rhs)
static const PlanarDubins3D & GetLower()
Definition: box.h:53
static constexpr size_t StateDimension()
friend PlanarDubins3D operator*(PlanarDubins3D lhs, double s)
PlanarDubins3D & operator+=(const PlanarDubins3D &rhs)
static constexpr size_t ConfigurationDimension()
static const PlanarDubins3D & GetUpper()
static PlanarDubins3D Sample()
void FromRos(const fastrack_msgs::State &msg)
static void SetBounds(const PlanarDubins3D &lower, const PlanarDubins3D &upper)
std::vector< Vector3d > OccupiedPositions() const


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