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


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Apr 15 2021 05:07:47