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 <stdint.h>
37 #include <stdbool.h>
38 
39 namespace rosflight_firmware
40 {
41 
42 class ROSflight;
43 
44 class Mixer
45 {
46 
47 public:
48 
49  enum
50  {
54  HEX_PLUS = 3,
55  HEX_X = 4,
56  OCTO_PLUS = 5,
57  OCTO_X = 6,
58  Y6 = 7,
59  X8 = 8,
60  TRICOPTER = 9,
61  FIXEDWING = 10,
64  };
65 
66  typedef enum
67  {
68  NONE, // None
69  S, // Servo
70  M, // Motor
71  G // GPIO
72  } output_type_t;
73 
74  typedef struct
75  {
76  output_type_t output_type[8];
77  float F[8];
78  float x[8];
79  float y[8];
80  float z[8];
81  uint32_t default_pwm_rate;
82  } mixer_t;
83 
84 private:
86 
87  float raw_outputs_[8];
89 
90  void write_motor(uint8_t index, float value);
91  void write_servo(uint8_t index, float value);
92 
94  {
95  {M, M, M, M, M, M, NONE, NONE},
96  { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}, // F Mix
97  { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
98  { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
99  { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
100  490
101  };
102 
104  {
105  {M, M, M, M, NONE, NONE, NONE, NONE}, // output_type
106 
107  { 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // F Mix
108  { 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
109  { 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Y Mix
110  { 1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Z Mix
111  490
112  };
113 
115  {
116  {M, M, M, M, NONE, NONE, NONE, NONE}, // output_type
117 
118  { 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // F Mix
119  {-1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
120  { 1.0f, -1.0f,-1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Y Mix
121  { 1.0f, -1.0f, 1.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Z Mix
122  490
123  };
124 
126  {
127  {M, M, M, M, M, M, M, M}, // output_type
128 
129  { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f}, // F Mix
130  { 0.0f, -0.866025f, -0.866025f, 0.0f, 0.866025f, 0.866025f, 0.0f, 0.0f}, // X Mix
131  { 1.0f, 0.5f, -0.5f, -1.0f, -0.5f, 0.5f, 0.0f, 0.0f}, // Y Mix
132  { 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f}, // Z Mix
133  490
134  };
135 
137  {
138  {M, M, M, M, M, M, M, M}, // output_type
139 
140  { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f}, // F Mix
141  { -0.5f, -1.0f, -0.5f, 0.5f, 1.0f, 0.5f, 0.0f, 0.0f}, // X Mix
142  { 0.866025f, 0.0f, -0.866025f, -0.866025f, 0.0f, 0.866025f, 0.0f, 0.0f}, // Y Mix
143  { 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f}, // Z Mix
144  490
145  };
146 
148  {
149  {M, M, M, M, M, M, M, M}, // output_type
150 
151  { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}, // F Mix
152  { 0.0f, -0.707f, -1.0f, -0.707f, 0.0f, 0.707f, 1.0f, 0.707f}, // X Mix
153  { 1.0f, 0.707f, 0.0f, -0.707f, -1.0f, -0.707f, 0.0f, 0.707f}, // Y Mix
154  { 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f}, // Z Mix
155  490
156  };
157 
159  {
160  {M, M, M, M, M, M, M, M}, // output_type
161 
162  { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}, // F Mix
163  {-0.414f, -1.0f, -1.0f, -0.414f, 0.414f, 1.0f, 1.0f, 0.414}, // X Mix
164  { 1.0f, 0.414f, -0.414f, -1.0f, -1.0f, -0.414f, 0.414f, 1.0}, // Y Mix
165  { 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f}, // Z Mix
166  490
167  };
168 
170  {
171  {M, M, M, M, M, M, NONE, NONE}, // output_type
172 
173  { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f}, // F Mix
174  {-1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f}, // X Mix
175  { 0.667f, 0.667f, -1.333f, -1.333f, 0.667f, 0.667f, 0.0f, 0.0f}, // Y Mix
176  { 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f}, // Z Mix
177  490
178  };
179 
181  {
182  {M, M, M, M, M, M, M, M}, // output_type
183 
184  { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}, // F Mix
185  {-1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f}, // X Mix
186  { 1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f}, // Y Mix
187  { 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f}, // Z Mix
188  490
189  };
190 
192  {
193  {M, M, M, S, NONE, NONE, NONE, NONE}, // output_type
194 
195  { 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // F Mix
196  {-1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
197  { 0.667f, 0.0f, 0.667f, -1.333f, 0.0f, 0.0f, 0.0f, 0.0f}, // Y Mix
198  { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Z Mix
199  490
200  };
201 
203  {
204  {S, S, M, S, S, M, NONE, NONE},
205 
206  { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // F Mix
207  { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // X Mix
208  { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Y Mix
209  { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // Z Mix
210  50
211  };
212 
214 
216  {
221  &hex_x_mixing,
224  &Y6_mixing,
225  &X8_mixing,
227  &fixedwing_mixing
228  };
229 
230 public:
231  Mixer(ROSflight &_rf);
232  void init();
233  void init_PWM();
234  void init_mixing();
235  void mix_output();
236  void param_change_callback(uint16_t param_id);
237  inline const float *get_outputs() const
238  {
239  return raw_outputs_;
240  }
241 };
242 
243 } // namespace rosflight_firmware
244 
245 #endif // ROSFLIGHT_FIRMWARE_MIXER_H
const mixer_t tricopter_mixing
Definition: mixer.h:191
const mixer_t quadcopter_x_mixing
Definition: mixer.h:114
const mixer_t esc_calibration_mixing
Definition: mixer.h:93
Mixer(ROSflight &_rf)
Definition: mixer.cpp:41
const mixer_t fixedwing_mixing
Definition: mixer.h:202
const float * get_outputs() const
Definition: mixer.h:237
ROSflight & RF_
Definition: mixer.h:85
const mixer_t hex_plus_mixing
Definition: mixer.h:125
const mixer_t octocopter_plus_mixing
Definition: mixer.h:147
const mixer_t quadcopter_plus_mixing
Definition: mixer.h:103
const mixer_t hex_x_mixing
Definition: mixer.h:136
void write_servo(uint8_t index, float value)
Definition: mixer.cpp:151
float raw_outputs_[8]
Definition: mixer.h:87
void param_change_callback(uint16_t param_id)
Definition: mixer.cpp:64
const mixer_t octocopter_x_mixing
Definition: mixer.h:158
const mixer_t Y6_mixing
Definition: mixer.h:169
const mixer_t * array_of_mixers_[NUM_MIXERS]
Definition: mixer.h:215
const mixer_t * mixer_to_use_
Definition: mixer.h:213
float unsaturated_outputs_[8]
Definition: mixer.h:88
void write_motor(uint8_t index, float value)
Definition: mixer.cpp:124
const mixer_t X8_mixing
Definition: mixer.h:180


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Wed Jul 3 2019 19:59:25