quadrotor_decoupled_6d_rel_kinematics.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 relative dynamics between a 6D decoupled quadrotor model and a
40 // 3D kinematic point model. Templated on type of control bound for quadrotor.
41 //
43 
44 #ifndef FASTRACK_DYNAMICS_QUADROTOR_DECOUPLED_6D_REL_KINEMATICS_H
45 #define FASTRACK_DYNAMICS_QUADROTOR_DECOUPLED_6D_REL_KINEMATICS_H
46 
54 
55 #include <math.h>
56 
57 namespace fastrack {
58 namespace dynamics {
59 
60 using control::QuadrotorControl;
61 using dynamics::Kinematics;
62 using dynamics::QuadrotorDecoupled6D;
63 using state::PositionVelocity;
64 using state::PositionVelocityRelPositionVelocity;
65 using state::RelativeState;
66 
67 template <typename CB>
69  : public RelativeDynamics<PositionVelocity, QuadrotorControl,
70  PositionVelocity, VectorXd> {
71  public:
74  : RelativeDynamics<PositionVelocity, QuadrotorControl, PositionVelocity,
75  VectorXd>() {}
76 
77  // Derived classes must be able to give the time derivative of relative state
78  // as a function of current state and control of each system.
79  inline std::unique_ptr<RelativeState<PositionVelocity, PositionVelocity>>
80  Evaluate(const PositionVelocity& tracker_x, const QuadrotorControl& tracker_u,
81  const PositionVelocity& planner_x, const VectorXd& planner_u) const {
82  if (planner_u.size() != PositionVelocity::ConfigurationDimension())
83  throw std::runtime_error("Bad planner control size.");
84 
85  // TODO(@jaime): confirm that this works. I set things up so things like
86  // this should work.
87  const QuadrotorDecoupled6D<CB> quad_dynamics;
88  const Kinematics<PositionVelocity> quad_kinematics;
89  return std::unique_ptr<PositionVelocityRelPositionVelocity>(
90  new PositionVelocityRelPositionVelocity(
91  quad_dynamics.Evaluate(tracker_x, tracker_u),
92  quad_kinematics.Evaluate(planner_x, planner_u)));
93  }
94 
95  // Derived classes must be able to compute an optimal control given
96  // the gradient of the value function at the relative state specified
97  // by the given system states, provided abstract control bounds.
98  inline QuadrotorControl OptimalControl(
99  const PositionVelocity& tracker_x, const PositionVelocity& planner_x,
100  const RelativeState<PositionVelocity, PositionVelocity>& value_gradient,
101  const ControlBound<QuadrotorControl>& tracker_u_bound,
102  const ControlBound<VectorXd>& planner_u_bound) const {
103  // Get internal state of value gradient and map tracker control (negative)
104  // coefficients to QuadrotorControl, so we get a negative gradient.
105  const auto& cast = static_cast<const PositionVelocityRelPositionVelocity& >(
106  value_gradient);
107 
108  const auto& grad = cast.State();
109  QuadrotorControl negative_grad;
110  negative_grad.yaw_rate = 0.0;
111  negative_grad.pitch = -grad.Vx();
112  negative_grad.roll = grad.Vy();
113  negative_grad.thrust = -grad.Vz();
114 
115  // Project onto tracker control bound and make sure to zero out yaw_rate.
116  QuadrotorControl c = tracker_u_bound.ProjectToSurface(negative_grad);
117  c.yaw_rate = 0.0;
118 
119  return c;
120  }
121 }; //\class QuadrotorDecoupled6DRelKinematics
122 
123 } // namespace dynamics
124 } // namespace fastrack
125 
126 #endif
S Evaluate(const S &x, const VectorXd &u) const
Definition: kinematics.h:109
Definition: box.h:53
PositionVelocity Evaluate(const PositionVelocity &x, const QuadrotorControl &u) const
std::unique_ptr< RelativeState< PositionVelocity, PositionVelocity > > Evaluate(const PositionVelocity &tracker_x, const QuadrotorControl &tracker_u, const PositionVelocity &planner_x, const VectorXd &planner_u) const
QuadrotorControl OptimalControl(const PositionVelocity &tracker_x, const PositionVelocity &planner_x, const RelativeState< PositionVelocity, PositionVelocity > &value_gradient, const ControlBound< QuadrotorControl > &tracker_u_bound, const ControlBound< VectorXd > &planner_u_bound) const


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