PX4 Firmware
PX4 Autopilot Software http://px4.io
|
Multi-rotor mixer for pre-defined vehicle geometries. More...
#include <MultirotorMixer.hpp>
Classes | |
struct | Rotor |
Precalculated rotor mix. More... | |
union | saturation_status |
Public Member Functions | |
MultirotorMixer (ControlCallback control_cb, uintptr_t cb_handle, MultirotorGeometry geometry, float roll_scale, float pitch_scale, float yaw_scale, float idle_speed) | |
Constructor. More... | |
MultirotorMixer (ControlCallback control_cb, uintptr_t cb_handle, const Rotor *rotors, unsigned rotor_count) | |
Constructor (for testing). More... | |
virtual | ~MultirotorMixer () |
MultirotorMixer (const MultirotorMixer &)=delete | |
MultirotorMixer & | operator= (const MultirotorMixer &)=delete |
MultirotorMixer (MultirotorMixer &&)=delete | |
MultirotorMixer & | operator= (MultirotorMixer &&)=delete |
unsigned | mix (float *outputs, unsigned space) override |
Perform the mixing function. More... | |
uint16_t | get_saturation_status () override |
Get the saturation status. More... | |
void | groups_required (uint32_t &groups) override |
Analyses the mix configuration and updates a bitmask of groups that are required. More... | |
void | set_max_delta_out_once (float delta_out_max) override |
Update slew rate parameter. More... | |
unsigned | set_trim (float trim) override |
Set trim offset for this mixer. More... | |
unsigned | get_trim (float *trim) override |
Get trim offset for this mixer. More... | |
void | set_thrust_factor (float val) override |
Sets the thrust factor used to calculate mapping from desired thrust to motor control signal output. More... | |
void | set_airmode (Airmode airmode) override |
Set airmode. More... | |
unsigned | get_multirotor_count () override |
Public Member Functions inherited from Mixer | |
Mixer (ControlCallback control_cb, uintptr_t cb_handle) | |
Constructor. More... | |
virtual | ~Mixer ()=default |
Mixer (const Mixer &)=delete | |
Mixer & | operator= (const Mixer &)=delete |
Mixer (Mixer &&)=delete | |
Mixer & | operator= (Mixer &&)=delete |
Public Member Functions inherited from ListNode< Mixer *> | |
void | setSibling (Mixer * sibling) |
const Mixer * | getSibling () const |
Static Public Member Functions | |
static MultirotorMixer * | from_text (Mixer::ControlCallback control_cb, uintptr_t cb_handle, const char *buf, unsigned &buflen) |
Factory method. More... | |
Private Member Functions | |
float | compute_desaturation_gain (const float *desaturation_vector, const float *outputs, saturation_status &sat_status, float min_output, float max_output) const |
Computes the gain k by which desaturation_vector has to be multiplied in order to unsaturate the output that has the greatest saturation. More... | |
void | minimize_saturation (const float *desaturation_vector, float *outputs, saturation_status &sat_status, float min_output=0.f, float max_output=1.f, bool reduce_only=false) const |
Minimize the saturation of the actuators by adding or substracting a fraction of desaturation_vector. More... | |
void | mix_airmode_rp (float roll, float pitch, float yaw, float thrust, float *outputs) |
Mix roll, pitch, yaw, thrust and set the outputs vector. More... | |
void | mix_airmode_rpy (float roll, float pitch, float yaw, float thrust, float *outputs) |
Mix roll, pitch, yaw, thrust and set the outputs vector. More... | |
void | mix_airmode_disabled (float roll, float pitch, float yaw, float thrust, float *outputs) |
Mix roll, pitch, yaw, thrust and set the outputs vector. More... | |
void | mix_yaw (float yaw, float *outputs) |
Mix yaw by updating an existing output vector (that already contains roll/pitch/thrust). More... | |
void | update_saturation_status (unsigned index, bool clipping_high, bool clipping_low_roll_pitch, bool clipping_low_yaw) |
Private Attributes | |
float | _roll_scale {1.0f} |
float | _pitch_scale {1.0f} |
float | _yaw_scale {1.0f} |
float | _idle_speed {0.0f} |
float | _delta_out_max {0.0f} |
float | _thrust_factor {0.0f} |
Airmode | _airmode {Airmode::disabled} |
saturation_status | _saturation_status {} |
unsigned | _rotor_count |
const Rotor * | _rotors |
float * | _outputs_prev {nullptr} |
float * | _tmp_array {nullptr} |
Additional Inherited Members | |
Public Types inherited from Mixer | |
enum | Airmode : int32_t { Airmode::disabled = 0, Airmode::roll_pitch = 1, Airmode::roll_pitch_yaw = 2 } |
typedef int(* | ControlCallback) (uintptr_t handle, uint8_t control_group, uint8_t control_index, float &control) |
Fetch a control value. More... | |
Protected Member Functions inherited from Mixer | |
float | get_control (uint8_t group, uint8_t index) |
Invoke the client callback to fetch a control value. More... | |
Static Protected Member Functions inherited from Mixer | |
static const char * | findtag (const char *buf, unsigned &buflen, char tag) |
Find a tag. More... | |
static char | findnexttag (const char *buf, unsigned buflen) |
Find next tag and return it (0 is returned if no tag is found) More... | |
static const char * | skipline (const char *buf, unsigned &buflen) |
Skip a line. More... | |
static bool | string_well_formed (const char *buf, unsigned &buflen) |
Check wether the string is well formed and suitable for parsing. More... | |
Protected Attributes inherited from Mixer | |
ControlCallback | _control_cb |
client-supplied callback used when fetching control values More... | |
uintptr_t | _cb_handle |
Protected Attributes inherited from ListNode< Mixer *> | |
Mixer * | _list_node_sibling |
Multi-rotor mixer for pre-defined vehicle geometries.
Collects four inputs (roll, pitch, yaw, thrust) and mixes them to a set of outputs based on the configured geometry.
Definition at line 52 of file MultirotorMixer.hpp.
MultirotorMixer::MultirotorMixer | ( | ControlCallback | control_cb, |
uintptr_t | cb_handle, | ||
MultirotorGeometry | geometry, | ||
float | roll_scale, | ||
float | pitch_scale, | ||
float | yaw_scale, | ||
float | idle_speed | ||
) |
Constructor.
control_cb | Callback invoked to read inputs. |
cb_handle | Passed to control_cb. |
geometry | The selected geometry. |
roll_scale | Scaling factor applied to roll inputs compared to thrust. |
pitch_scale | Scaling factor applied to pitch inputs compared to thrust. |
yaw_wcale | Scaling factor applied to yaw inputs compared to thrust. |
idle_speed | Minimum rotor control output value; usually tuned to ensure that rotors never stall at the low end of their control range. |
Definition at line 82 of file MultirotorMixer.cpp.
References _idle_speed, _pitch_scale, _roll_scale, and _yaw_scale.
Referenced by from_text().
MultirotorMixer::MultirotorMixer | ( | ControlCallback | control_cb, |
uintptr_t | cb_handle, | ||
const Rotor * | rotors, | ||
unsigned | rotor_count | ||
) |
Constructor (for testing).
control_cb | Callback invoked to read inputs. |
cb_handle | Passed to control_cb. |
rotors | control allocation matrix |
rotor_count | length of rotors array (= number of motors) |
Definition at line 92 of file MultirotorMixer.cpp.
References _idle_speed, _outputs_prev, and _rotor_count.
|
virtual |
Definition at line 105 of file MultirotorMixer.cpp.
References _outputs_prev, and _tmp_array.
|
delete |
|
delete |
|
private |
Computes the gain k by which desaturation_vector has to be multiplied in order to unsaturate the output that has the greatest saturation.
Definition at line 169 of file MultirotorMixer.cpp.
References _rotor_count, MultirotorMixer::saturation_status::flags, FLT_EPSILON, MultirotorMixer::saturation_status::motor_neg, and MultirotorMixer::saturation_status::motor_pos.
Referenced by minimize_saturation().
|
static |
Factory method.
Given a pointer to a buffer containing a text description of the mixer, returns a pointer to a new instance of the mixer.
control_cb | The callback to invoke when fetching a control value. |
cb_handle | Handle passed to the control callback. |
buf | Buffer containing a text description of the mixer. |
buflen | Length of the buffer in bytes, adjusted to reflect the bytes consumed. |
Definition at line 112 of file MultirotorMixer.cpp.
References debug, f(), MultirotorMixer(), Mixer::skipline(), and Mixer::string_well_formed().
Referenced by uart_esc::initialize_mixer(), snapdragon_pwm::initialize_mixer(), and MixerGroup::load_from_buf().
|
inlineoverridevirtual |
Reimplemented from Mixer.
Definition at line 151 of file MultirotorMixer.hpp.
Referenced by MixerGroup::get_multirotor_count().
|
inlineoverridevirtual |
Get the saturation status.
Reimplemented from Mixer.
Definition at line 123 of file MultirotorMixer.hpp.
Referenced by MixerGroup::get_saturation_status().
|
inlineoverridevirtual |
Get trim offset for this mixer.
Reimplemented from Mixer.
Definition at line 140 of file MultirotorMixer.hpp.
Referenced by MixerGroup::get_trims().
|
inlineoverridevirtual |
Analyses the mix configuration and updates a bitmask of groups that are required.
groups | A bitmask of groups (0-31) that the mixer requires. |
Reimplemented from Mixer.
Definition at line 125 of file MultirotorMixer.hpp.
Referenced by MixerGroup::groups_required(), and snapdragon_pwm::task_main().
|
private |
Minimize the saturation of the actuators by adding or substracting a fraction of desaturation_vector.
desaturation_vector is the vector that added to the output outputs, modifies the thrust or angular acceleration on a specific axis. For example, if desaturation_vector is given to slide along the vertical thrust axis (thrust_scale), the saturation will be minimized by shifting the vertical thrust setpoint, without changing the roll/pitch/yaw accelerations.
Note that as we only slide along the given axis, in extreme cases outputs can still contain values outside of [min_output, max_output].
desaturation_vector | vector that is added to the outputs, e.g. thrust_scale |
outputs | output vector that is modified |
sat_status | saturation status output |
min_output | minimum desired value in outputs |
max_output | maximum desired value in outputs |
reduce_only | if true, only allow to reduce (substract) a fraction of desaturation_vector |
Definition at line 207 of file MultirotorMixer.cpp.
References _rotor_count, compute_desaturation_gain(), and f().
Referenced by mix_airmode_disabled(), mix_airmode_rp(), mix_airmode_rpy(), and mix_yaw().
|
overridevirtual |
Perform the mixing function.
outputs | Array into which mixed output(s) should be placed. |
space | The number of available entries in the output array; |
Implements Mixer.
Definition at line 336 of file MultirotorMixer.cpp.
References _airmode, _delta_out_max, _idle_speed, _outputs_prev, _pitch_scale, _roll_scale, _rotor_count, _saturation_status, _thrust_factor, _yaw_scale, math::constrain(), Mixer::disabled, f(), Mixer::get_control(), mix_airmode_disabled(), mix_airmode_rp(), mix_airmode_rpy(), Mixer::roll_pitch, Mixer::roll_pitch_yaw, update_saturation_status(), and MultirotorMixer::saturation_status::value.
Referenced by main(), MixerGroup::mix(), uart_esc::task_main(), and snapdragon_pwm::task_main().
|
inlineprivate |
Mix roll, pitch, yaw, thrust and set the outputs vector.
Desaturation behavior: no airmode, thrust is NEVER increased to meet the demanded roll/pitch/yaw. Instead roll/pitch/yaw is reduced as much as needed. Thrust can be reduced to unsaturate the upper side.
Definition at line 279 of file MultirotorMixer.cpp.
References _rotor_count, _rotors, _saturation_status, _tmp_array, f(), minimize_saturation(), mix_yaw(), MultirotorMixer::Rotor::pitch_scale, MultirotorMixer::Rotor::roll_scale, and MultirotorMixer::Rotor::thrust_scale.
Referenced by mix().
|
inlineprivate |
Mix roll, pitch, yaw, thrust and set the outputs vector.
Desaturation behavior: airmode for roll/pitch: thrust is increased/decreased as much as required to meet the demanded roll/pitch. Yaw is not allowed to increase the thrust,
Definition at line 231 of file MultirotorMixer.cpp.
References _rotor_count, _rotors, _saturation_status, _tmp_array, minimize_saturation(), mix_yaw(), MultirotorMixer::Rotor::pitch_scale, MultirotorMixer::Rotor::roll_scale, and MultirotorMixer::Rotor::thrust_scale.
Referenced by mix().
|
inlineprivate |
Mix roll, pitch, yaw, thrust and set the outputs vector.
Desaturation behavior: full airmode for roll/pitch/yaw: thrust is increased/decreased as much as required to meet demanded the roll/pitch/yaw, while giving priority to roll and pitch over yaw.
Definition at line 252 of file MultirotorMixer.cpp.
References _rotor_count, _rotors, _saturation_status, _tmp_array, minimize_saturation(), MultirotorMixer::Rotor::pitch_scale, MultirotorMixer::Rotor::roll_scale, MultirotorMixer::Rotor::thrust_scale, and MultirotorMixer::Rotor::yaw_scale.
Referenced by mix().
|
inlineprivate |
Mix yaw by updating an existing output vector (that already contains roll/pitch/thrust).
Desaturation behavior: thrust is allowed to be decreased up to 15% in order to allow some yaw control on the upper end. On the lower end thrust will never be increased, but yaw is decreased as much as required.
yaw | demanded yaw |
outputs | output vector that is updated |
Definition at line 313 of file MultirotorMixer.cpp.
References _rotor_count, _rotors, _saturation_status, _tmp_array, f(), minimize_saturation(), MultirotorMixer::Rotor::thrust_scale, and MultirotorMixer::Rotor::yaw_scale.
Referenced by mix_airmode_disabled(), and mix_airmode_rp().
|
delete |
|
delete |
|
inlineoverridevirtual |
Set airmode.
Airmode allows the mixer to increase the total thrust in order to unsaturate the motors.
[in] | airmode | Select airmode type (0 = disabled, 1 = roll/pitch, 2 = roll/pitch/yaw) |
Reimplemented from Mixer.
Definition at line 149 of file MultirotorMixer.hpp.
Referenced by main(), MixerGroup::set_airmode(), and snapdragon_pwm::task_main().
|
inlineoverridevirtual |
Update slew rate parameter.
This tells the multicopter mixer the maximum allowed change of the output values per cycle. The value is only valid for one cycle, in order to have continuous slew rate limiting this function needs to be called before every call to mix().
[in] | delta_out_max | Maximum delta output. |
Reimplemented from Mixer.
Definition at line 137 of file MultirotorMixer.hpp.
Referenced by MixerGroup::set_max_delta_out_once().
|
inlineoverridevirtual |
Sets the thrust factor used to calculate mapping from desired thrust to motor control signal output.
[in] | val | The value |
Reimplemented from Mixer.
Definition at line 147 of file MultirotorMixer.hpp.
References math::constrain(), and f().
Referenced by MixerGroup::set_thrust_factor().
|
inlineoverridevirtual |
Set trim offset for this mixer.
Reimplemented from Mixer.
Definition at line 139 of file MultirotorMixer.hpp.
Referenced by MixerGroup::set_trims().
|
private |
Definition at line 438 of file MultirotorMixer.cpp.
References _rotors, _saturation_status, f(), MultirotorMixer::saturation_status::flags, MultirotorMixer::saturation_status::pitch_neg, MultirotorMixer::saturation_status::pitch_pos, MultirotorMixer::saturation_status::roll_neg, MultirotorMixer::saturation_status::roll_pos, MultirotorMixer::saturation_status::thrust_neg, MultirotorMixer::saturation_status::thrust_pos, MultirotorMixer::saturation_status::valid, MultirotorMixer::saturation_status::yaw_neg, and MultirotorMixer::saturation_status::yaw_pos.
Referenced by mix().
|
private |
Definition at line 251 of file MultirotorMixer.hpp.
Referenced by mix().
|
private |
Definition at line 248 of file MultirotorMixer.hpp.
Referenced by mix().
|
private |
Definition at line 247 of file MultirotorMixer.hpp.
Referenced by mix(), and MultirotorMixer().
|
private |
Definition at line 258 of file MultirotorMixer.hpp.
Referenced by mix(), MultirotorMixer(), and ~MultirotorMixer().
|
private |
Definition at line 245 of file MultirotorMixer.hpp.
Referenced by mix(), and MultirotorMixer().
|
private |
Definition at line 244 of file MultirotorMixer.hpp.
Referenced by mix(), and MultirotorMixer().
|
private |
Definition at line 255 of file MultirotorMixer.hpp.
Referenced by compute_desaturation_gain(), minimize_saturation(), mix(), mix_airmode_disabled(), mix_airmode_rp(), mix_airmode_rpy(), mix_yaw(), and MultirotorMixer().
|
private |
Definition at line 256 of file MultirotorMixer.hpp.
Referenced by mix_airmode_disabled(), mix_airmode_rp(), mix_airmode_rpy(), mix_yaw(), and update_saturation_status().
|
private |
Definition at line 253 of file MultirotorMixer.hpp.
Referenced by mix(), mix_airmode_disabled(), mix_airmode_rp(), mix_airmode_rpy(), mix_yaw(), and update_saturation_status().
|
private |
Definition at line 249 of file MultirotorMixer.hpp.
Referenced by mix().
|
private |
Definition at line 259 of file MultirotorMixer.hpp.
Referenced by mix_airmode_disabled(), mix_airmode_rp(), mix_airmode_rpy(), mix_yaw(), and ~MultirotorMixer().
|
private |
Definition at line 246 of file MultirotorMixer.hpp.
Referenced by mix(), and MultirotorMixer().