planar_dubins_dynamics_3d.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, 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 // Defines the PlanarDubinsDynamics3D class, which uses the PlanarDubins3D
40 // state type.
41 //
43 
44 #ifndef FASTRACK_DYNAMICS_PLANAR_DUBINS_DYNAMICS_3D_H
45 #define FASTRACK_DYNAMICS_PLANAR_DUBINS_DYNAMICS_3D_H
46 
50 #include <fastrack_srvs/PlanarDubinsPlannerDynamics.h>
51 #include <fastrack_srvs/PlanarDubinsPlannerDynamicsResponse.h>
52 
53 #include <math.h>
54 
55 namespace fastrack {
56 namespace dynamics {
57 
58 using state::PlanarDubins3D;
59 using control::ScalarBoundInterval;
60 
62  : public Dynamics<PlanarDubins3D, double, ScalarBoundInterval,
63  fastrack_srvs::PlanarDubinsPlannerDynamics::Response> {
64  public:
67  : Dynamics<PlanarDubins3D, double, ScalarBoundInterval,
68  fastrack_srvs::PlanarDubinsPlannerDynamics::Response>() {}
69  explicit PlanarDubinsDynamics3D(double v, const ScalarBoundInterval& bound)
70  : Dynamics<PlanarDubins3D, double, ScalarBoundInterval,
71  fastrack_srvs::PlanarDubinsPlannerDynamics::Response>(bound),
72  v_(v) {}
73 
74  // Assume parameters are laid out as: [v, min yaw rate, max yaw rate].
75  explicit PlanarDubinsDynamics3D(const std::vector<double>& params)
76  : Dynamics<PlanarDubins3D, double, ScalarBoundInterval,
77  fastrack_srvs::PlanarDubinsPlannerDynamics::Response>() {
78  Initialize(params);
79  }
80 
81  explicit PlanarDubinsDynamics3D(double v, const double& u_lower,
82  const double& u_upper)
83  : Dynamics<PlanarDubins3D, double, ScalarBoundInterval,
84  fastrack_srvs::PlanarDubinsPlannerDynamics::Response>(
85  ScalarBoundInterval(u_lower, u_upper)),
86  v_(v) {
87  // Make sure interval is symmetric.
88  constexpr double kSmallNumber = 1e-8;
89  if (std::abs(control_bound_->Max() + control_bound_->Min()) > kSmallNumber)
90  throw std::runtime_error("Non-symmetric control bound.");
91  }
92 
93  // Accessors.
94  double V() const { return v_; }
95  double MaxOmega() const { return control_bound_->Max(); }
96 
97  // Compute turning radius.
98  double TurningRadius() const { return V() / MaxOmega(); }
99 
100  // Override base class initializer because parameter vector now contains
101  // more than just control bound params.
102  // Assume parameters are laid out as: [v, min yaw rate, max yaw rate].
103  void Initialize(const std::vector<double> &params) {
104  if (params.size() != 3) {
105  throw std::runtime_error("Incorrect number of parameters: " +
106  std::to_string(params.size()));
107  }
108 
109  v_ = params[0];
110  control_bound_.reset(new ScalarBoundInterval(params[1], params[2]));
111  }
112 
113  // Derived classes must be able to give the time derivative of state
114  // as a function of current state and control.
115  inline PlanarDubins3D Evaluate(const PlanarDubins3D& x,
116  const double& u) const {
117  const PlanarDubins3D x_dot(v_ * std::cos(x.Theta()),
118  v_ * std::sin(x.Theta()), u);
119  return x_dot;
120  }
121 
122  // Derived classes must be able to compute an optimal control given
123  // the gradient of the value function at the specified state.
124  // In this case (linear dynamics), the state is irrelevant given the
125  // gradient of the value function at that state.
126  inline double OptimalControl(const PlanarDubins3D& x,
127  const PlanarDubins3D& value_gradient) const {
128  throw std::runtime_error(
129  "PlanarDubinsDynamics3D: OptimalControl is unimplemented.");
130  return std::numeric_limits<double>::quiet_NaN();
131  }
132 
133  // Convert to the appropriate service response type.
134  inline fastrack_srvs::PlanarDubinsPlannerDynamics::Response ToRos() const {
135  if (!control_bound_)
136  throw std::runtime_error("PlanarDubinsDynamics3D was not initialized.");
137 
138  fastrack_srvs::PlanarDubinsPlannerDynamics::Response res;
139  res.speed = v_;
140  res.max_yaw_rate = control_bound_->Max();
141 
142  return res;
143  }
144 
145  // Convert from the appropriate service response type.
146  inline void FromRos(
147  const fastrack_srvs::PlanarDubinsPlannerDynamics::Response& res) {
148  v_ = res.speed;
149  control_bound_.reset(
150  new ScalarBoundInterval(-res.max_yaw_rate, res.max_yaw_rate));
151  }
152 
153  private:
154  double v_;
155 }; //\class QuadrotorDecoupled6D
156 
157 } // namespace dynamics
158 } // namespace fastrack
159 
160 #endif
void FromRos(const fastrack_srvs::PlanarDubinsPlannerDynamics::Response &res)
double OptimalControl(const PlanarDubins3D &x, const PlanarDubins3D &value_gradient) const
PlanarDubinsDynamics3D(const std::vector< double > &params)
void Initialize(const std::vector< double > &params)
Definition: box.h:53
PlanarDubinsDynamics3D(double v, const double &u_lower, const double &u_upper)
fastrack_srvs::PlanarDubinsPlannerDynamics::Response ToRos() const
PlanarDubinsDynamics3D(double v, const ScalarBoundInterval &bound)
PlanarDubins3D Evaluate(const PlanarDubins3D &x, const double &u) const


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