PX4 Firmware
PX4 Autopilot Software http://px4.io
AttitudeControl.hpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2019 PX4 Development Team. 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
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * @file AttitudeControl.hpp
36  *
37  * A quaternion based attitude controller.
38  *
39  * @author Matthias Grob <maetugr@gmail.com>
40  *
41  * Publication documenting the implemented Quaternion Attitude Control:
42  * Nonlinear Quadrocopter Attitude Control (2013)
43  * by Dario Brescianini, Markus Hehn and Raffaello D'Andrea
44  * Institute for Dynamic Systems and Control (IDSC), ETH Zurich
45  *
46  * https://www.research-collection.ethz.ch/bitstream/handle/20.500.11850/154099/eth-7387-01.pdf
47  */
48 
49 #pragma once
50 
51 #include <matrix/matrix/math.hpp>
52 
54 {
55 public:
56  AttitudeControl() = default;
57  ~AttitudeControl() = default;
58 
59  /**
60  * Set proportional attitude control gain
61  * @param proportional_gain 3D vector containing gains for roll, pitch, yaw
62  */
63  void setProportionalGain(const matrix::Vector3f &proportional_gain);
64 
65  /**
66  * Set hard limit for output rate setpoints
67  * @param rate_limit [rad/s] 3D vector containing limits for roll, pitch, yaw
68  */
69  void setRateLimit(const matrix::Vector3f &rate_limit) { _rate_limit = rate_limit; }
70 
71  /**
72  * Run one control loop cycle calculation
73  * @param q estimation of the current vehicle attitude unit quaternion
74  * @param qd desired vehicle attitude setpoint
75  * @param yawspeed_feedforward [rad/s] yaw feed forward angular rate in world frame
76  * @return [rad/s] body frame 3D angular rate setpoint vector to be executed by the rate controller
77  */
78  matrix::Vector3f update(matrix::Quatf q, matrix::Quatf qd, float yawspeed_feedforward);
79 
80 private:
83  float _yaw_w = 0.0f; /**< yaw weight [0,1] to prioritize roll and pitch */
84 };
~AttitudeControl()=default
matrix::Vector3f _rate_limit
matrix::Vector3f update(matrix::Quatf q, matrix::Quatf qd, float yawspeed_feedforward)
Run one control loop cycle calculation.
matrix::Vector3f _proportional_gain
Quaternion class.
Definition: Dcm.hpp:24
AttitudeControl()=default
void setProportionalGain(const matrix::Vector3f &proportional_gain)
Set proportional attitude control gain.
void setRateLimit(const matrix::Vector3f &rate_limit)
Set hard limit for output rate setpoints.
float _yaw_w
yaw weight [0,1] to prioritize roll and pitch