NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mixer.h
Go to the documentation of this file.
1 /*
2  * This file is part of Ninjaflight.
3  *
4  * Copyright: collective.
5  * Cleanup: Martin Schröder <mkschreder.uk@gmail.com>
6  * Original source from Cleanflight.
7  *
8  * Ninjaflight is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * Ninjaflight is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Ninjaflight. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #pragma once
23 
24 #define MAX_SUPPORTED_MOTORS 12
25 #define MAX_SUPPORTED_SERVOS 8
26 
27 #define MAX_SERVO_RULES (2 * MAX_SUPPORTED_SERVOS)
28 #define MAX_SERVO_SPEED UINT8_MAX
29 #define MAX_SERVO_BOXES 3
30 
31 #define DEFAULT_SERVO_MIN 1000
32 #define DEFAULT_SERVO_MIDDLE 1500
33 #define DEFAULT_SERVO_MAX 2000
34 #define DEFAULT_SERVO_MIN_ANGLE 45
35 #define DEFAULT_SERVO_MAX_ANGLE 45
36 
37 /*
39 struct servo_mixer {
40  uint8_t targetChannel; //!< servo that receives the output of the rule
41  uint8_t inputSource; //!< input channel for this rule
42  int8_t rate; //!< range [-125;+125] ; can be used to adjust a rate 0-125% and a direction
43  uint8_t speed; //!< reduces the speed of the rule, 0=unlimited speed
44  int8_t min; //!< lower bound of rule range [0;100]% of servo max-min
45  int8_t max; //!< lower bound of rule range [0;100]% of servo max-min
46  uint8_t box; //!< active rule if box is enabled, range [0;3], 0=no box, 1=BOXSERVO1, 2=BOXSERVO2, 3=BOXSERVO3
47 } __attribute__((packed));
48 
50 struct motor_mixer {
51  float throttle;
52  float roll;
53  float pitch;
54  float yaw;
55 } __attribute__((packed));
56 */
59  uint16_t deadband3d_low; // min 3d value
60  uint16_t deadband3d_high; // max 3d value
61  uint16_t neutral3d; // center 3d value
62 } __attribute__((packed)) ;
63 
65  // PWM values, in milliseconds, common range is 1000-2000 (1 to 2ms)
66  uint16_t minthrottle; // Set the minimum throttle command sent to the ESC (Electronic Speed Controller). This is the minimum value that allow motors to run at a idle speed.
67  uint16_t maxthrottle; // This is the maximum value for the ESCs at full power this value can be increased up to 2000
68  uint16_t mincommand; // This is the value for the ESCs when they are not armed. In some cases, this value must be lowered down to 900 for some specific ESCs
69  uint16_t servoCenterPulse; // This is the value for servos when they should be in the middle. e.g. 1500.
70  uint16_t motor_pwm_rate; // The update rate of motor outputs (50-498Hz)
71  uint16_t servo_pwm_rate; // The update rate of servo outputs (50-498Hz)
72 } __attribute__((packed)) ;
73 
74 // the following few structures are cleanflight config for motor and servo mixers which is also currently used for custom mixers
75 #define CHANNEL_FORWARDING_DISABLED (uint8_t)0xff
76 
78 struct servo_config {
79  int16_t min;
80  int16_t max;
81  int16_t middle;
82  int8_t rate;
83  uint8_t angleAtMin;
84  uint8_t angleAtMax;
86  uint32_t reversedSources;
87 } __attribute__ ((__packed__));
88 
89 struct servo_profile {
91 } __attribute__((packed)) ;
92 
97 typedef enum {
135 } mixer_input_t;
136 
138 typedef enum {
161 
162 // TODO: all mixers should actually be stored in the client and we should only be supporting custom mixers (and possibly a default)
163 
166  uint8_t output;
167  uint8_t input;
168  int16_t scale;
169 } __attribute__((packed));
170 
171 #define MIXER_MAX_RULES 48
172 
174 typedef enum {
180  MIXER_Y6 = 6,
183  MIXER_Y4 = 9,
188  MIXER_AIRPLANE = 14, // airplane / singlecopter / dualcopter (not yet properly supported)
193  MIXER_PPM_TO_SERVO = 19, // PPM -> servo relay
203 } mixer_mode_t;
204 
205 
207 struct mixer_config {
208  uint8_t mixerMode;
216 } __attribute__((packed)) ;
217 
218 // TODO: custom servo and motor mixers should use mixer_rule_def instead. Remove the above defs once we are using new structures!
219 
3d mode mixer settings (used when mixer_enable_3d_mode is called with true)
Definition: mixer.h:58
Definition: mixer.h:157
#define MAX_SUPPORTED_SERVOS
Definition: mixer.h:25
uint16_t mincommand
Definition: mixer.h:68
Definition: mixer.h:176
Definition: mixer.h:179
uint16_t neutral3d
Definition: mixer.h:61
Definition: mixer.h:141
Definition: mixer.h:180
Definition: mixer.h:126
rc roll input
Definition: mixer.h:117
Definition: mixer.h:134
#define MIXER_MAX_RULES
Definition: mixer.h:171
Definition: mixer.h:146
Definition: mixer.h:186
Definition: mixer.h:130
Definition: mixer.h:120
Definition: mixer.h:145
Definition: mixer.h:128
gimbal pitch
Definition: mixer.h:113
int8_t yaw_motor_direction
allows reversing yaw direction (values -1 or 1)
Definition: mixer.h:210
Definition: mixer.h:195
Definition: mixer.h:178
Definition: mixer.h:89
int16_t min
Minimum pwm value that is sent to the servo.
Definition: mixer.h:79
uint16_t servo_pwm_rate
Definition: mixer.h:71
Definition: mixer.h:198
uint8_t tri_unarmed_servo
send tail servo correction pulses even when unarmed
Definition: mixer.h:212
Definition: mixer.h:143
Definition: mixer.h:154
flight control angular rate for z axis
Definition: mixer.h:101
flight control angular rate for x axis
Definition: mixer.h:99
flight control tilt pitch
Definition: mixer.h:103
Definition: mixer.h:124
Definition: mixer.h:181
Definition: mixer.h:139
mixer_output_t
Mixer output channels.
Definition: mixer.h:138
Definition: mixer.h:197
uint8_t mixerMode
one of the mixer_mode_t values
Definition: mixer.h:208
uint16_t servoCenterPulse
Definition: mixer.h:69
uint8_t input
Definition: mixer.h:167
Definition: mixer.h:110
Configuration for each servo which is editable by the user.
Definition: mixer.h:78
Definition: mixer.h:152
flight control airbreaks
Definition: mixer.h:105
Definition: mixer.h:193
uint8_t output
Definition: mixer.h:166
Definition: mixer.h:118
Definition: mixer.h:144
uint16_t minthrottle
Definition: mixer.h:66
Definition: mixer.h:121
Definition: mixer.h:196
Definition: mixer.h:129
Definition: mixer.h:127
Definition: mixer.h:123
Definition: mixer.h:202
Definition: mixer.h:133
Definition: mixer.h:119
Definition: mixer.h:190
uint8_t pid_at_min_throttle
when enabled pids are used at minimum throttle (valid values 0 or 1)
Definition: mixer.h:209
Definition: mixer.h:175
Definition: mixer.h:183
Definition: mixer.h:108
uint16_t motor_pwm_rate
Definition: mixer.h:70
Definition: mixer.h:64
Definition: mixer.h:184
uint16_t deadband3d_high
Definition: mixer.h:60
uint16_t deadband3d_low
Definition: mixer.h:59
Definition: mixer.h:187
uint8_t angleAtMin
range [0;180] the measured angle in degrees from the middle when the servo is at the 'min' value...
Definition: mixer.h:83
flight control angular rate for y axis
Definition: mixer.h:100
uint16_t yaw_jump_prevention_limit
make limit configurable (original fixed value was 100)
Definition: mixer.h:211
int8_t rate
range [-125;+125] ; can be used to adjust a rate 0-125% and a direction
Definition: mixer.h:82
Definition: mixer.h:200
Definition: mixer.h:194
Definition: mixer.h:189
Definition: mixer.h:147
Definition: mixer.h:201
Definition: mixer.h:148
Definition: mixer.h:182
Definition: mixer.h:177
Definition: mixer.h:142
Definition: mixer.h:199
mixer_input_t
Definition: mixer.h:97
Definition: mixer.h:159
typedef __attribute__
gimbal yaw
Definition: mixer.h:114
flight control throttle
Definition: mixer.h:102
flight control landing gear
Definition: mixer.h:106
Definition: mixer.h:158
uint16_t maxthrottle
Definition: mixer.h:67
int16_t middle
PWM value that is sent to center the servo (usually 1500)
Definition: mixer.h:81
Definition: mixer.h:156
Definition: mixer.h:111
int16_t scale
Definition: mixer.h:168
struct mixer_rule_def custom_rules[MIXER_MAX_RULES]
Definition: mixer.h:215
int8_t forwardFromChannel
RX channel index, 0 based. See CHANNEL_FORWARDING_DISABLED.
Definition: mixer.h:85
Definition: mixer.h:107
struct servo_config servoConf[MAX_SUPPORTED_SERVOS]
Definition: mixer.h:90
Definition: mixer.h:149
float servo_lowpass_freq
lowpass servo filter frequency selection; 1/1000ths of loop freq
Definition: mixer.h:213
Definition: mixer.h:132
Definition: mixer.h:151
uint32_t reversedSources
the direction of servo movement for each input source of the servo mixer, bit set=inverted ...
Definition: mixer.h:86
general mixer settings
Definition: mixer.h:207
Definition: mixer.h:131
Definition: mixer.h:109
Definition: mixer.h:116
mixer_mode_t
sets mixer frame configuration
Definition: mixer.h:174
gimbal shutter
Definition: mixer.h:115
Definition: mixer.h:191
gimbal roll
Definition: mixer.h:112
Definition: mixer.h:98
Definition: mixer.h:140
Definition: mixer.h:188
Definition: mixer.h:122
flight control spoilers
Definition: mixer.h:104
int16_t max
Maximum pwm value that is sent to the servo.
Definition: mixer.h:80
Definition: mixer.h:153
Definition: mixer.h:155
Definition: mixer.h:150
int8_t servo_lowpass_enable
enable/disable lowpass filter for servo output
Definition: mixer.h:214
mixer rule definition in new format
Definition: mixer.h:165
Definition: mixer.h:192
Definition: mixer.h:185
uint8_t angleAtMax
range [0;180] the measured angle in degrees from the middle when the servo is at the 'max' value...
Definition: mixer.h:84