FDCL Controllers
control.hpp
Go to the documentation of this file.
1 
5 /*
6  * Copyright (c) 2020 Flight Dynamics and Control Lab
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  */
26 
27 #ifndef FDCL_CONTROL_HPP
28 #define FDCL_CONTROL_HPP
29 
30 
31 // user headers
32 #include "common_types.hpp"
33 #include "fdcl/param.hpp"
34 #include "fdcl/integral_utils.hpp"
35 #include "fdcl/matrix_utils.hpp"
36 
37 
38 // external headers
39 #include "Eigen/Dense"
40 
41 
42 namespace fdcl
43 {
51 class control
52 {
53 public:
54  double t = 0.0;
55  double t_pre = 0.0;
56  double dt = 1e-9;
57  int freq = 100;
59  bool use_integral = false;
61  // for integral controller
68  Vector3 eR = Vector3::Zero();
69  Vector3 eW = Vector3::Zero();
70  Vector3 ei = Vector3::Zero();
71  Vector3 M = Vector3::Zero();
73  Vector3 eX = Vector3::Zero();
74  Vector3 eV = Vector3::Zero();
76  Vector3 b1 = Vector3::Zero();
77  Vector3 b2 = Vector3::Zero();
78  Vector3 b3 = Vector3::Zero();
79  Vector3 b3_dot = Vector3::Zero();
81  Eigen::Matrix<double, 4, 4> fM_to_forces_inv;
84  Vector4 f_motor;
86  Vector4 fM = Vector4::Zero();
88  double f_total = 0.0;
90  control(
91  fdcl::state_t *&state_,
92  fdcl::command_t *&command_,
93  fdcl::param *config_file_
96  );
97  control(void); // Default constructor (this is should not be used)
98  ~control(void);
99 
103  void init(void);
104 
108  void load_config(void);
109 
113  void set_error_to_zero(void);
114 
120  void attitude_control(void);
121 
128 
129 
134  void position_control(void);
135 
136 
141  double get_time(void);
142 
143 
149  void output_uav_properties(double &m, Matrix3 &J);
150 
151 
157  void output_fM(double &f, Vector3 &M);
158 
159 
160 private:
161  fdcl::state_t *state = nullptr;
162  fdcl::command_t *command = nullptr;
163  fdcl::param *config_file = nullptr;
167  bool use_decoupled_yaw = true;
171  Vector3 e1;
172  Vector3 e2;
173  Vector3 e3;
175  double m = 0.0;
176  double g = 9.81;
177  Matrix3 J = Matrix3::Zero();
178  double c_tf = 0.0;
179  double l = 0.0;
181  struct timespec tspec_init;
182  struct timespec tspec_curr;
184  // Attitude gains
185  Matrix3 kR = Matrix3::Zero();
186  Matrix3 kW = Matrix3::Zero();
187  double kyw = 0.0;
189  // Position gains
190  Matrix3 kX = Matrix3::Zero();
191  Matrix3 kV = Matrix3::Zero();
193  // Integral gains
194  double kIR = 0.0;
195  double ki = 0.0;
196  double kI = 0.0;
197  double kyI = 0.0;
198  double kIX = 0.0;
199  double c1 = 0.0;
200  double c2 = 0.0;
201  double c3 = 0.0;
203 }; // end of control class
204 
205 } // end of namespace fdcl
206 
207 #endif
Vector4 fM
Definition: control.hpp:86
Vector3 eR
Definition: control.hpp:68
void attitude_control(void)
void load_config(void)
Integral for error for Vector3.
Definition: integral_utils.hpp:44
Vector3 b3
Definition: control.hpp:78
Controller functions for the rover.
Definition: control.hpp:51
double f_total
Definition: control.hpp:88
int freq
Definition: control.hpp:57
Vector3 b2
Definition: control.hpp:77
fdcl::integral_error eIy
Definition: control.hpp:65
Vector3 eW
Definition: control.hpp:69
void init(void)
double t_pre
Definition: control.hpp:55
Miscellaneous math functions.
void position_control(void)
Saving and loading parameters.
Definition: param.hpp:34
Vector3 b3_dot
Definition: control.hpp:79
fdcl::integral_error_vec3 eIX
Definition: control.hpp:66
double t
Definition: control.hpp:54
Data types used throughout the code.
Vector3 M
Definition: control.hpp:71
fdcl::integral_error_vec3 eIR
Definition: control.hpp:62
Vector3 eV
Definition: control.hpp:74
Definition: common_types.hpp:44
Structures to handle integral errors.
Vector3 eX
Definition: control.hpp:73
double get_time(void)
void output_fM(double &f, Vector3 &M)
Data structure to store current states.
Definition: common_types.hpp:49
double dt
Definition: control.hpp:56
void set_error_to_zero(void)
Vector4 f_motor
Definition: control.hpp:84
void attitude_control_decoupled_yaw(void)
fdcl::integral_error eI1
Definition: control.hpp:63
Vector3 ei
Definition: control.hpp:70
Data structure to store command (or desired) values.
Definition: common_types.hpp:61
bool use_integral
Definition: control.hpp:59
fdcl::integral_error eI2
Definition: control.hpp:64
Integral for error for a double.
Definition: integral_utils.hpp:82
Vector3 b1
Definition: control.hpp:76
Eigen::Matrix< double, 4, 4 > fM_to_forces_inv
Definition: control.hpp:81
void output_uav_properties(double &m, Matrix3 &J)