quadrotor_decoupled_6d.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 QuadrotorDecoupled6D class, which uses PositionVelocity as the
40 // state and QuadrotorControl as the control, and models the dynamics as a
41 // three decoupled 2D systems.
42 //
44 
45 #ifndef FASTRACK_DYNAMICS_QUADROTOR_DECOUPLED_6D_H
46 #define FASTRACK_DYNAMICS_QUADROTOR_DECOUPLED_6D_H
47 
52 
53 #include <math.h>
54 
55 namespace fastrack {
56 namespace dynamics {
57 
58 using control::QuadrotorControl;
59 using control::QuadrotorControlBoundBox;
60 using state::PositionVelocity;
61 
62 template <typename CB>
64  : public Dynamics<PositionVelocity, QuadrotorControl, CB, Empty> {
65  public:
68  : Dynamics<PositionVelocity, QuadrotorControl, CB, Empty>() {}
69  explicit QuadrotorDecoupled6D(const CB& bound)
70  : Dynamics<PositionVelocity, QuadrotorControl, CB, Empty>(bound) {}
71  explicit QuadrotorDecoupled6D(const std::vector<double>& params)
72  : Dynamics<PositionVelocity, QuadrotorControl, CB, Empty>(params) {}
73 
74  // Derived classes must be able to give the time derivative of state
75  // as a function of current state and control.
76  inline PositionVelocity Evaluate(const PositionVelocity &x,
77  const QuadrotorControl &u) const {
78  // Position derivatives are just velocity.
79  const Vector3d position_dot(x.Velocity());
80 
81  // Velocity derivatives are given by simple trigonometric functions
82  // of the pitch/roll, scaled by G since we assume that thrust is
83  // approximately equal to G.
84  const Vector3d velocity_dot(constants::G * std::tan(u.pitch),
85  -constants::G * std::tan(u.roll),
86  u.thrust - constants::G);
87 
88  return PositionVelocity(position_dot, velocity_dot);
89  }
90 
91  // Derived classes must be able to compute an optimal control given
92  // the gradient of the value function at the specified state.
93  // In this case (linear dynamics), the state is irrelevant given the
94  // gradient of the value function at that state.
95  inline QuadrotorControl OptimalControl(
96  const PositionVelocity &x, const PositionVelocity &value_gradient) const {
97  // Check initialization.
98  if (!this->control_bound_)
99  throw std::runtime_error(
100  "QuadrotorDecoupled6D: uninitialized call to OptimalControl.");
101 
102  // Map the negative value gradient's control coefficients to
103  // QuadrotorControl, so we get a negative gradient.
104  QuadrotorControl negative_grad;
105  negative_grad.yaw_rate = 0.0;
106  negative_grad.pitch = -value_gradient.Vx();
107  negative_grad.roll = value_gradient.Vy();
108  negative_grad.thrust = -value_gradient.Vz();
109 
110  // Project onto control bound and make sure to zero out yaw_rate.
111  QuadrotorControl c = this->control_bound_->ProjectToSurface(negative_grad);
112  c.yaw_rate = 0.0;
113 
114  return c;
115  }
116 
117  // Convert to the appropriate service response type.
118  inline Empty ToRos() const {
119  throw std::runtime_error("QuadrotorDecoupled6D: ToRos is unimplemented.");
120  return Empty();
121  }
122 
123  // Convert from the appropriate service response type.
124  inline void FromRos(const Empty &res) {
125  throw std::runtime_error("QuadrotorDecoupled6D: FromRos is unimplemented.");
126  }
127 
128 }; //\class QuadrotorDecoupled6D
129 
130 } // namespace dynamics
131 } // namespace fastrack
132 
133 #endif
QuadrotorControl OptimalControl(const PositionVelocity &x, const PositionVelocity &value_gradient) const
Definition: box.h:53
PositionVelocity Evaluate(const PositionVelocity &x, const QuadrotorControl &u) const
QuadrotorDecoupled6D(const std::vector< double > &params)
static constexpr double G
Definition: types.h:67


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