Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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++) {
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++) {
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 }
MAX_PPRZ
#define MAX_PPRZ
Definition: paparazzi.h:8
swashplate_mixing_t::commands
int32_t commands[SW_NB]
The output commands.
Definition: swashplate_mixing.h:72
coll_coef
static const float coll_coef[SW_NB]
Definition: swashplate_mixing.c:36
swashplate_mixing_init
void swashplate_mixing_init()
Initialize the motor mixing and calculate the trim values.
Definition: swashplate_mixing.c:60
SW_MIXING_TRIM_COLL
#define SW_MIXING_TRIM_COLL
Definition: swashplate_mixing.c:52
SW_MIXING_PITCH_COEF
#define SW_MIXING_PITCH_COEF
Definition: swashplate_mixing.h:48
SW_MIXING_ROLL_COEF
#define SW_MIXING_ROLL_COEF
Definition: swashplate_mixing.h:47
pprz_t
int16_t pprz_t
Definition: paparazzi.h:6
swashplate_mixing_t::trim
int32_t trim[SW_NB]
Trim values for the different actuators.
Definition: swashplate_mixing.h:73
roll_coef
static const float roll_coef[SW_NB]
Definition: swashplate_mixing.c:34
swashplate_mixing_t
Definition: swashplate_mixing.h:71
pitch_coef
static const float pitch_coef[SW_NB]
Definition: swashplate_mixing.c:35
SW_MIXING_TRIM_ROLL
#define SW_MIXING_TRIM_ROLL
Definition: swashplate_mixing.c:40
SW_MIXING_COLL_COEF
#define SW_MIXING_COLL_COEF
Definition: swashplate_mixing.h:49
uint8_t
unsigned char uint8_t
Definition: types.h:14
SW_NB
#define SW_NB
MECH (front/right/coll), H120 (front/rightback/leftback), HR120 (back/leftfront/rightfront)
Definition: swashplate_mixing.h:43
SW_MIXING_TRIM_PITCH
#define SW_MIXING_TRIM_PITCH
Definition: swashplate_mixing.c:46
swashplate_mixing
struct swashplate_mixing_t swashplate_mixing
Definition: swashplate_mixing.c:31
swashplate_mixing.h
throttle_curve.h
swashplate_mixing_run
void swashplate_mixing_run(pprz_t in_cmd[])
Definition: swashplate_mixing.c:79