mixer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, James Jackson and Daniel Koch, BYU MAGICC Lab
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 
33 #ifndef ROSFLIGHT_FIRMWARE_MIXER_H
34 #define ROSFLIGHT_FIRMWARE_MIXER_H
35 
36 #include <cstdint>
37 #include <cstdbool>
38 
40 
41 namespace rosflight_firmware
42 {
43 
44 class ROSflight;
45 
47 {
48 
49 public:
50 
51  static constexpr uint8_t NUM_TOTAL_OUTPUTS = 14;
52  static constexpr uint8_t NUM_MIXER_OUTPUTS = 8;
53 
54  enum
55  {
59  HEX_PLUS = 3,
60  HEX_X = 4,
61  OCTO_PLUS = 5,
62  OCTO_X = 6,
63  Y6 = 7,
64  X8 = 8,
65  TRICOPTER = 9,
66  FIXEDWING = 10,
70  };
71 
72  typedef enum
73  {
74  NONE, // None
75  S, // Servo
76  M, // Motor
77  G // GPIO
78  } output_type_t;
79 
80  typedef struct
81  {
82  output_type_t output_type[NUM_MIXER_OUTPUTS];
87  uint32_t default_pwm_rate;
88  } mixer_t;
89 
90  typedef struct
91  {
92  output_type_t type;
93  float value;
94  } aux_channel_t;
95 
96  typedef struct
97  {
99  } aux_command_t;
100 
101 private:
103 
108 
109  void write_motor(uint8_t index, float value);
110  void write_servo(uint8_t index, float value);
111 
113  {
114  {M, M, M, M, M, M, NONE, NONE},
115  { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}, // F Mix
116  { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
117  { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
118  { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
119  490
120  };
121 
123  {
124  {M, M, M, M, NONE, NONE, NONE, NONE}, // output_type
125 
126  { 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // F Mix
127  { 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
128  { 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Y Mix
129  { 1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Z Mix
130  490
131  };
132 
134  {
135  {M, M, M, M, NONE, NONE, NONE, NONE}, // output_type
136 
137  { 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // F Mix
138  {-1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
139  { 1.0f, -1.0f,-1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Y Mix
140  { 1.0f, -1.0f, 1.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Z Mix
141  490
142  };
143 
145  {
146  {M, M, M, M, M, M, M, M}, // output_type
147 
148  { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f}, // F Mix
149  { 0.0f, -0.866025f, -0.866025f, 0.0f, 0.866025f, 0.866025f, 0.0f, 0.0f}, // X Mix
150  { 1.0f, 0.5f, -0.5f, -1.0f, -0.5f, 0.5f, 0.0f, 0.0f}, // Y Mix
151  { 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f}, // Z Mix
152  490
153  };
154 
156  {
157  {M, M, M, M, M, M, M, M}, // output_type
158 
159  { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f}, // F Mix
160  { -0.5f, -1.0f, -0.5f, 0.5f, 1.0f, 0.5f, 0.0f, 0.0f}, // X Mix
161  { 0.866025f, 0.0f, -0.866025f, -0.866025f, 0.0f, 0.866025f, 0.0f, 0.0f}, // Y Mix
162  { 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f}, // Z Mix
163  490
164  };
165 
167  {
168  {M, M, M, M, M, M, M, M}, // output_type
169 
170  { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}, // F Mix
171  { 0.0f, -0.707f, -1.0f, -0.707f, 0.0f, 0.707f, 1.0f, 0.707f}, // X Mix
172  { 1.0f, 0.707f, 0.0f, -0.707f, -1.0f, -0.707f, 0.0f, 0.707f}, // Y Mix
173  { 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f}, // Z Mix
174  490
175  };
176 
178  {
179  {M, M, M, M, M, M, M, M}, // output_type
180 
181  { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}, // F Mix
182  {-0.414f, -1.0f, -1.0f, -0.414f, 0.414f, 1.0f, 1.0f, 0.414}, // X Mix
183  { 1.0f, 0.414f, -0.414f, -1.0f, -1.0f, -0.414f, 0.414f, 1.0}, // Y Mix
184  { 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f}, // Z Mix
185  490
186  };
187 
189  {
190  {M, M, M, M, M, M, NONE, NONE}, // output_type
191 
192  { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f}, // F Mix
193  {-1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f}, // X Mix
194  { 0.667f, 0.667f, -1.333f, -1.333f, 0.667f, 0.667f, 0.0f, 0.0f}, // Y Mix
195  { 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f}, // Z Mix
196  490
197  };
198 
200  {
201  {M, M, M, M, M, M, M, M}, // output_type
202 
203  { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}, // F Mix
204  {-1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f}, // X Mix
205  { 1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f}, // Y Mix
206  { 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f}, // Z Mix
207  490
208  };
209 
211  {
212  {M, M, M, S, NONE, NONE, NONE, NONE}, // output_type
213 
214  { 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // F Mix
215  {-1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
216  { 0.667f, 0.0f, 0.667f, -1.333f, 0.0f, 0.0f, 0.0f, 0.0f}, // Y Mix
217  { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Z Mix
218  490
219  };
220 
222  {
223  {S, S, M, S, S, M, NONE, NONE},
224 
225  { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // F Mix
226  { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
227  { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Y Mix
228  { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Z Mix
229  50
230  };
231 
233  {
234  {NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE},
235 
236  { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // F Mix
237  { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
238  { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Y Mix
239  { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Z Mix
240  50
241  };
242 
244 
246  {
251  &hex_x_mixing,
254  &Y6_mixing,
255  &X8_mixing,
258  &passthrough_mixing
259  };
260 
261 public:
262  Mixer(ROSflight& _rf);
263  void init();
264  void init_PWM();
265  void init_mixing();
266  void mix_output();
267  void param_change_callback(uint16_t param_id) override;
268  void set_new_aux_command(aux_command_t new_aux_command);
269  inline const float* get_outputs() const {return raw_outputs_;}
270 };
271 
272 } // namespace rosflight_firmware
273 
274 #endif // ROSFLIGHT_FIRMWARE_MIXER_H
const mixer_t tricopter_mixing
Definition: mixer.h:210
const mixer_t quadcopter_x_mixing
Definition: mixer.h:133
const mixer_t esc_calibration_mixing
Definition: mixer.h:112
Mixer(ROSflight &_rf)
Definition: mixer.cpp:41
float raw_outputs_[NUM_TOTAL_OUTPUTS]
Definition: mixer.h:104
const mixer_t fixedwing_mixing
Definition: mixer.h:221
const float * get_outputs() const
Definition: mixer.h:269
const mixer_t hex_plus_mixing
Definition: mixer.h:144
void set_new_aux_command(aux_command_t new_aux_command)
Definition: mixer.cpp:157
const mixer_t octocopter_plus_mixing
Definition: mixer.h:166
void param_change_callback(uint16_t param_id) override
Definition: mixer.cpp:52
const mixer_t quadcopter_plus_mixing
Definition: mixer.h:122
const mixer_t hex_x_mixing
Definition: mixer.h:155
void write_servo(uint8_t index, float value)
Definition: mixer.cpp:143
static constexpr uint8_t NUM_TOTAL_OUTPUTS
Definition: mixer.h:51
float outputs_[NUM_TOTAL_OUTPUTS]
Definition: mixer.h:105
const mixer_t octocopter_x_mixing
Definition: mixer.h:177
const mixer_t Y6_mixing
Definition: mixer.h:188
const mixer_t passthrough_mixing
Definition: mixer.h:232
static constexpr uint8_t NUM_MIXER_OUTPUTS
Definition: mixer.h:52
const mixer_t * array_of_mixers_[NUM_MIXERS]
Definition: mixer.h:245
const mixer_t * mixer_to_use_
Definition: mixer.h:243
void write_motor(uint8_t index, float value)
Definition: mixer.cpp:116
output_type_t combined_output_type_[NUM_TOTAL_OUTPUTS]
Definition: mixer.h:107
const mixer_t X8_mixing
Definition: mixer.h:199
aux_command_t aux_command_
Definition: mixer.h:106


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Oct 24 2019 03:17:19