MAV'RIC
attitude_controller.h
1 /*******************************************************************************
2  * Copyright (c) 2009-2014, MAV'RIC Development Team
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 met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  ******************************************************************************/
31 
32 /*******************************************************************************
33  * \file attitude_controller.h
34  *
35  * \author MAV'RIC Team
36  * \author Julien Lecoeur
37  *
38  * \brief A cascaded controller for attitude & rate control.
39  *
40  * \details It takes a command in attitude (roll/pitch/yaw or quaternion) as
41  * input, and computes a torque command on roll pitch and yaw.
42  * The inner PID loop controls the angular speed around the 3 axis. This inner
43  * loop is fed by the outer PID loop which controls the attitude.
44  * The error of the outer loop is computed using quaternion arithmetic, and thus
45  * avoids gimbal locks as long as the attitude error is smaller than 90 degrees
46  * on the pitch axis.
47  *
48  ******************************************************************************/
49 
50 
51 #ifndef ATTITUDE_CONTROLLER_H_
52 #define ATTITUDE_CONTROLLER_H_
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 #include "attitude_error_estimator.h"
59 #include "control_command.h"
60 #include "ahrs.h"
61 #include "pid_controller.h"
62 
66 typedef enum
67 {
68  ATTITUDE_CONTROLLER_MODE_DEFAULT = 0,
69  ATTITUDE_CONTROLLER_MODE_RATE_ONLY = 1,
70 } attitude_controller_mode_t;
71 
72 
76 typedef struct
77 {
79  pid_controller_t rate_pid[3];
80  pid_controller_t angle_pid[3];
81  attitude_controller_mode_t mode;
82  const ahrs_t* ahrs;
87 
88 
92 typedef struct
93 {
94  pid_controller_conf_t rate_pid_config[3];
95  pid_controller_conf_t angle_pid_config[3];
97 
98 
109 void attitude_controller_init(attitude_controller_t* controller, const attitude_controller_conf_t* config, const ahrs_t* ahrs, attitude_command_t* attitude_command, rate_command_t* rate_command, torque_command_t* torque_command);
110 
111 
117 void attitude_controller_update(attitude_controller_t* controller);
118 
119 
120 #ifdef __cplusplus
121 }
122 #endif
123 
124 #endif /* ATTITUDE_CONTROLLER_H_ */
Structure containing the Attitude and Heading Reference System.
Definition: ahrs.h:58
Attitude controller configuration.
Definition: attitude_controller.h:92
Torque command structure.
Definition: control_command.h:142
const attitude_command_t * attitude_command
Pointer to attitude command (input)
Definition: attitude_controller.h:83
Configuration for PID controller.
Definition: pid_controller.h:81
const ahrs_t * ahrs
Pointer to attitude estimation (input)
Definition: attitude_controller.h:82
torque_command_t * torque_command
Pointer to torque command (output)
Definition: attitude_controller.h:85
PID controller.
Definition: pid_controller.h:95
Attitude command structure.
Definition: control_command.h:122
rate_command_t * rate_command
Pointer to rate command (input/output)
Definition: attitude_controller.h:84
Rate command structure.
Definition: control_command.h:133
Attitude controller structure.
Definition: attitude_controller.h:76
attitude_controller_mode_t mode
Control mode: Angle (default), or rate.
Definition: attitude_controller.h:81
Quaternion attitude error estimator data structure.
Definition: attitude_error_estimator.h:68
attitude_error_estimator_t attitude_error_estimator
Attitude error estimator.
Definition: attitude_controller.h:78