PX4 Firmware
PX4 Autopilot Software http://px4.io
MixerGroup.hpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (C) 2012-2019 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 #pragma once
35 
36 #include "Mixer/Mixer.hpp"
37 
38 /**
39  * Group of mixers, built up from single mixers and processed
40  * in order when mixing.
41  */
43 {
44 public:
45  MixerGroup() = default;
46 
48  {
49  reset();
50  }
51 
52  // no copy, assignment, move, move assignment
53  MixerGroup(const MixerGroup &) = delete;
54  MixerGroup &operator=(const MixerGroup &) = delete;
55  MixerGroup(MixerGroup &&) = delete;
56  MixerGroup &operator=(MixerGroup &&) = delete;
57 
58  unsigned mix(float *outputs, unsigned space);
59 
60  uint16_t get_saturation_status();
61 
62  void groups_required(uint32_t &groups);
63 
64  /**
65  * Add a mixer to the group.
66  *
67  * @param mixer The mixer to be added.
68  */
69  void add_mixer(Mixer *mixer) { _mixers.add(mixer); }
70 
71  /**
72  * Remove all the mixers from the group.
73  */
74  void reset() { _mixers.clear(); }
75 
76  /**
77  * Count the mixers in the group.
78  */
79  unsigned count() const { return _mixers.size(); }
80 
81  /**
82  * Adds mixers to the group based on a text description in a buffer.
83  *
84  * Mixer definitions begin with a single capital letter and a colon.
85  * The actual format of the mixer definition varies with the individual
86  * mixers; they are summarised here, but see ROMFS/mixers/README for
87  * more details.
88  *
89  * Null Mixer
90  * ..........
91  *
92  * The null mixer definition has the form:
93  *
94  * Z:
95  *
96  * Simple Mixer
97  * ............
98  *
99  * A simple mixer definition begins with:
100  *
101  * M: <control count>
102  * O: <-ve scale> <+ve scale> <offset> <lower limit> <upper limit>
103  *
104  * The second line O: can be omitted. In that case 'O: 10000 10000 0 -10000 10000' is used.
105  * The definition continues with <control count> entries describing the control
106  * inputs and their scaling, in the form:
107  *
108  * S: <group> <index> <-ve scale> <+ve scale> <offset> <lower limit> <upper limit>
109  *
110  * Multirotor Mixer
111  * ................
112  *
113  * The multirotor mixer definition is a single line of the form:
114  *
115  * R: <geometry> <roll scale> <pitch scale> <yaw scale> <deadband>
116  *
117  * Helicopter Mixer
118  * ................
119  *
120  * The helicopter mixer includes throttle and pitch curves
121  *
122  * H: <swash plate servo count>
123  * T: <0> <2500> <5000> <7500> <10000>
124  * P: <-10000> <-5000> <0> <5000> <10000>
125  *
126  * The definition continues with <swash plate servo count> entries describing
127  * the position of the servo, in the following form:
128  *
129  * S: <angle (deg)> <normalized arm length> <scale> <offset> <lower limit> <upper limit>
130  *
131  * @param buf The mixer configuration buffer.
132  * @param buflen The length of the buffer, updated to reflect
133  * bytes as they are consumed.
134  * @return Zero on successful load, nonzero otherwise.
135  */
136  int load_from_buf(Mixer::ControlCallback control_cb, uintptr_t cb_handle, const char *buf, unsigned &buflen);
137 
138  /**
139  * @brief Update slew rate parameter. This tells instances of the class MultirotorMixer
140  * the maximum allowed change of the output values per cycle.
141  * The value is only valid for one cycle, in order to have continuous
142  * slew rate limiting this function needs to be called before every call
143  * to mix().
144  *
145  * @param[in] delta_out_max Maximum delta output.
146  *
147  */
148  void set_max_delta_out_once(float delta_out_max);
149 
150  /*
151  * Invoke the set_offset method of each mixer in the group
152  * for each value in page r_page_servo_control_trim
153  */
154  unsigned set_trims(int16_t *v, unsigned n);
155  unsigned get_trims(int16_t *values);
156 
157  /**
158  * @brief Sets the thrust factor used to calculate mapping from desired thrust to motor control signal output.
159  *
160  * @param[in] val The value
161  */
162  void set_thrust_factor(float val);
163 
164  void set_airmode(Mixer::Airmode airmode);
165 
166  unsigned get_multirotor_count();
167 
168 private:
169  List<Mixer *> _mixers; /**< linked list of mixers */
170 };
MixerGroup & operator=(const MixerGroup &)=delete
int load_from_buf(Mixer::ControlCallback control_cb, uintptr_t cb_handle, const char *buf, unsigned &buflen)
Adds mixers to the group based on a text description in a buffer.
Definition: MixerGroup.cpp:173
void reset()
Remove all the mixers from the group.
Definition: MixerGroup.hpp:74
uint16_t get_saturation_status()
Definition: MixerGroup.cpp:153
unsigned get_multirotor_count()
Definition: MixerGroup.cpp:139
void add_mixer(Mixer *mixer)
Add a mixer to the group.
Definition: MixerGroup.hpp:69
Generic, programmable, procedural control signal mixers.
unsigned count() const
Count the mixers in the group.
Definition: MixerGroup.hpp:79
int(* ControlCallback)(uintptr_t handle, uint8_t control_group, uint8_t control_index, float &control)
Fetch a control value.
Definition: Mixer.hpp:154
unsigned set_trims(int16_t *v, unsigned n)
Definition: MixerGroup.cpp:75
static MultirotorMixer * mixer
mixer initialization
void set_max_delta_out_once(float delta_out_max)
Update slew rate parameter.
Definition: MixerGroup.cpp:240
Definition: List.hpp:59
void set_thrust_factor(float val)
Sets the thrust factor used to calculate mapping from desired thrust to motor control signal output...
Definition: MixerGroup.cpp:123
Airmode
Definition: Mixer.hpp:139
void groups_required(uint32_t &groups)
Definition: MixerGroup.cpp:165
MixerGroup()=default
void set_airmode(Mixer::Airmode airmode)
Definition: MixerGroup.cpp:131
unsigned mix(float *outputs, unsigned space)
Definition: MixerGroup.cpp:53
Group of mixers, built up from single mixers and processed in order when mixing.
Definition: MixerGroup.hpp:42
Abstract class defining a mixer mixing zero or more inputs to one or more outputs.
Definition: Mixer.hpp:136
unsigned get_trims(int16_t *values)
Definition: MixerGroup.cpp:102
List< Mixer * > _mixers
linked list of mixers
Definition: MixerGroup.hpp:169