AerialVehicleControl.jl
cont_attitude_utils.c
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) Marcus Greiff 2020
3 *
4 * @file cont_attitude_utils.c
5 * @author Marcus Greiff
6 * @date June 2020
7 *******************************************************************************/
8 #include "cont_attitude_utils.h"
9 
11  con_state_qw_fsf_t * controller
12 ){
13  double maxJ, minJ, minVal, temp;
14  double kR = controller->gain_kR;
15  double kc = controller->gain_kc;
16  double kw = controller->gain_kw;
17 
18  /* Check that the parameters have the correct sign, and evaluate eig(J) */
19  if (0 == assert_attitude_FSF_parameters(controller, &minJ, &maxJ)) return 0;
20 
21  /* Check that kc is set sufficiently small w.r.t. kX and kw */
22  minVal = kw;
23  temp = sqrt(kR * minJ);
24  if (temp < minVal) minVal = temp;
25  temp = 4.0 * kw * kR * minJ * minJ;
26  temp /= (maxJ * kw * kw + 4.0 * minJ * minJ * kR);
27  if (temp < minVal) minVal = temp;
28  if (kc > minVal){
29  TRACE(5, ("The controller parameters do not result in a feasible controller\n"));
30  return 0;
31  }
32  return 1;
33 }
34 
36  con_state_qw_fsf_t * controller
37 ){
38  double maxJ, minJ, minVal, temp;
39  double kR = controller->gain_kR;
40  double kc = controller->gain_kc;
41  double kw = controller->gain_kw;
42 
43  /* Check that the parameters have the correct sign, and evaluate eig(J) */
44  if (0 == assert_attitude_FSF_parameters(controller, &minJ, &maxJ)) return 0;
45 
46  /* Check that kc is set sufficiently small w.r.t. kX and kw */
47  minVal = 4.0 * kw;
48  temp = 2.0 * sqrt(kw * minJ);
49  if (temp < minVal) minVal = temp;
50  temp = 4.0 * kw * kR * minJ * minJ;
51  temp /= (maxJ * kw * kw + minJ * minJ * kR);
52  if (temp < minVal) minVal = temp;
53  if (kc > minVal){
54  TRACE(5, ("The controller parameters do not result in a feasible controller\n"));
55  return 0;
56  }
57  return 1;
58 }
59 
61  con_state_qw_fsf_t * controller,
62  double *minJ,
63  double *maxJ
64 ){
65  double tol = 0.000001;
66  double kR = controller->gain_kR;
67  double kc = controller->gain_kc;
68  double kw = controller->gain_kw;
69  matrix_double_t Jm, Em;
70 
71  matrix_define(&Jm, 3, 3, controller->inertia);
72  matrix_allocate(&Em, 3, 1);
73 
74  /* Check for symmetry */
75  if ((tol < abs(matrix_get(&Jm, 0, 1) - matrix_get(&Jm, 1, 0))) ||
76  (tol < abs(matrix_get(&Jm, 0, 2) - matrix_get(&Jm, 2, 0))) ||
77  (tol < abs(matrix_get(&Jm, 1, 2) - matrix_get(&Jm, 2, 1)))) {
78  TRACE(5, ("The inertia matrix must be symmetric\n"));
79  free(Em.pData);
80  return 0;
81  }
82  /* Compute the maximum and minimum eigenvalues of the inertia matrix */
83  mat_eigvals(&Jm, &Em);
84  *minJ = Em.pData[0];
85  *maxJ = Em.pData[2];
86 
87  if (*minJ < -tol){
88  TRACE(5, ("The inertia matrix must be positive definite\n"));
89  free(Em.pData);
90  return 0;
91  }
92  if ((kR <= 0) ||
93  (kc <= 0) ||
94  (kw <= 0) ||
95  (controller->param_a <= 0) ||
96  (controller->param_b <= 0) ||
97  (controller->param_c <= 0) ||
98  (controller->param_d <= 0)){
99  TRACE(5, ("The controller parameters must be positive\n"));
100  free(Em.pData);
101  return 0;
102  }
103  free(Em.pData);
104  return 1;
105 }
matrix_double_s::pData
double * pData
Definition: cont_types.h:59
con_state_qw_fsf_s::gain_kc
double gain_kc
Definition: cont_types.h:73
matrix_allocate
void matrix_allocate(matrix_double_t *matrix, int numRows, int numCols)
Allocate memory for a matrix struct of given dimensions.
Definition: cont_types.c:65
assert_attitude_FSF_parameters
int assert_attitude_FSF_parameters(con_state_qw_fsf_t *controller, double *minJ, double *maxJ)
Assert that the FSF allitude controller parameters are feaible.
Definition: cont_attitude_utils.c:60
cont_attitude_utils.h
assert_attitude_FSF_SU2
int assert_attitude_FSF_SU2(con_state_qw_fsf_t *controller)
Assert that the SU(2) controller is feasible.
Definition: cont_attitude_utils.c:35
mat_eigvals
void mat_eigvals(matrix_double_t *Amat, matrix_double_t *Bmat)
Computethe eigenvalues of a real symmetric A to B, asserts that this is done correctly.
Definition: cont_matrix_math.c:267
matrix_double_s
Matrix object used for all matrix manipulation.
Definition: cont_types.h:50
con_state_qw_fsf_s::gain_kw
double gain_kw
Definition: cont_types.h:74
con_state_qw_fsf_s::param_c
double param_c
Definition: cont_types.h:79
assert_attitude_FSF_SO3
int assert_attitude_FSF_SO3(con_state_qw_fsf_t *controller)
Assert that the SO(3) controller is feasible.
Definition: cont_attitude_utils.c:10
con_state_qw_fsf_s::param_b
double param_b
Definition: cont_types.h:78
con_state_qw_fsf_s
Complete state of the attitude FSF on SO(3) or SU(2)
Definition: cont_types.h:67
matrix_define
void matrix_define(matrix_double_t *matrix, int numRows, int numCols, double *data)
Define a matrix to use already allocated memory.
Definition: cont_types.c:75
con_state_qw_fsf_s::param_d
double param_d
Definition: cont_types.h:80
con_state_qw_fsf_s::param_a
double param_a
Definition: cont_types.h:77
con_state_qw_fsf_s::gain_kR
double gain_kR
Definition: cont_types.h:72
con_state_qw_fsf_s::inertia
double inertia[9]
Definition: cont_types.h:71
matrix_get
double matrix_get(matrix_double_t *mat, int row, int column)
Get an entry of a matrix (irrespective of the used memory layout)
Definition: cont_types.c:32