Paparazzi UAS  v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
swashplate_mixing.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 C. De Wagter
3  * 2015 Freek van Tienen <freek.v.tienen@gmail.com>
4  *
5  * This file is part of paparazzi
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, see
19  * <http://www.gnu.org/licenses/>.
20  */
27 #include "swashplate_mixing.h"
28 #include "throttle_curve.h"
29 
30 PRINT_CONFIG_VAR(SW_MIXING_TYPE)
32 
33 /* Coeficients per motor */
34 static const float roll_coef[SW_NB] = SW_MIXING_ROLL_COEF;
35 static const float pitch_coef[SW_NB] = SW_MIXING_PITCH_COEF;
36 static const float coll_coef[SW_NB] = SW_MIXING_COLL_COEF;
37 
38 /* Default roll trim */
39 #ifndef SW_MIXING_TRIM_ROLL
40 #define SW_MIXING_TRIM_ROLL 0
41 #endif
42 PRINT_CONFIG_VAR(SW_MIXING_TRIM_ROLL)
43 
44 /* Default pitch trim */
45 #ifndef SW_MIXING_TRIM_PITCH
46 #define SW_MIXING_TRIM_PITCH 0
47 #endif
48 PRINT_CONFIG_VAR(SW_MIXING_TRIM_PITCH)
49 
50 /* Default collective trim */
51 #ifndef SW_MIXING_TRIM_COLL
52 #define SW_MIXING_TRIM_COLL 0
53 #endif
54 PRINT_CONFIG_VAR(SW_MIXING_TRIM_COLL)
55 
56 
57 
61 {
62  uint8_t i;
63 
64  // Go trough all the motors and calculate the trim value and set the initial command
65  for (i = 0; i < SW_NB; i++) {
66  swashplate_mixing.commands[i] = 0;
67  swashplate_mixing.trim[i] =
71  }
72 }
73 
74 /*
75  * Run the swashplate mixing
76  * This depends on the ROLL and PITCH command
77  * It also depends on the throttle_curve.collective
78  */
80 {
81  uint8_t i;
82 
83  // Go trough all the motors and calculate the command
84  for (i = 0; i < SW_NB; i++) {
85  swashplate_mixing.commands[i] = swashplate_mixing.trim[i] +
86  roll_coef[i] * in_cmd[COMMAND_ROLL] +
87  pitch_coef[i] * in_cmd[COMMAND_PITCH] +
88  coll_coef[i] * in_cmd[COMMAND_COLLECTIVE];
89  BoundAbs(swashplate_mixing.commands[i], MAX_PPRZ);
90  }
91 }
#define SW_NB
MECH (front/right/coll), H120 (front/rightback/leftback), HR120 (back/leftfront/rightfront) ...
#define SW_MIXING_TRIM_PITCH
int16_t pprz_t
Definition: paparazzi.h:6
struct swashplate_mixing_t swashplate_mixing
void swashplate_mixing_run(pprz_t in_cmd[])
static const float coll_coef[SW_NB]
#define SW_MIXING_PITCH_COEF
int32_t commands[SW_NB]
The output commands.
#define SW_MIXING_TRIM_COLL
void swashplate_mixing_init()
Initialize the motor mixing and calculate the trim values.
unsigned char uint8_t
Definition: types.h:14
static const float roll_coef[SW_NB]
#define SW_MIXING_ROLL_COEF
#define SW_MIXING_COLL_COEF
#define MAX_PPRZ
Definition: paparazzi.h:8
#define SW_MIXING_TRIM_ROLL
int32_t trim[SW_NB]
Trim values for the different actuators.
static const float pitch_coef[SW_NB]