42 #include <mathlib/mathlib.h> 44 #include <px4_platform_common/defines.h> 46 #define debug(fmt, args...) do { } while(0) 54 Mixer(control_cb, cb_handle),
55 _mixer_info(mixer_info)
63 unsigned swash_plate_servo_count = 0;
73 if (sscanf(buf,
"H: %u%n", &swash_plate_servo_count, &used) != 1) {
74 debug(
"helicopter parse failed on '%s'", buf);
78 if (swash_plate_servo_count < 3 || swash_plate_servo_count > 4) {
79 debug(
"only supporting swash plate with 3 or 4 servos");
83 if (used > (
int)buflen) {
84 debug(
"OVERFLOW: helicopter spec used %d of %u", used, buflen);
91 debug(
"no line ending, line is incomplete");
95 buf =
findtag(buf, buflen,
'T');
97 if ((buf ==
nullptr) || (buflen < 12)) {
98 debug(
"control parser failed finding tag, ret: '%s'", buf);
102 if (sscanf(buf,
"T: %u %u %u %u %u",
103 &u[0], &u[1], &u[2], &u[3], &u[4]) != 5) {
104 debug(
"control parse failed on '%s'", buf);
114 if (buf ==
nullptr) {
115 debug(
"no line ending, line is incomplete");
119 buf =
findtag(buf, buflen,
'P');
121 if ((buf ==
nullptr) || (buflen < 12)) {
122 debug(
"control parser failed finding tag, ret: '%s'", buf);
126 if (sscanf(buf,
"P: %d %d %d %d %d",
127 &s[0], &s[1], &s[2], &s[3], &s[4]) != 5) {
128 debug(
"control parse failed on '%s'", buf);
133 mixer_info.
pitch_curve[i] = ((float) s[i]) / 10000.0f;
138 if (buf ==
nullptr) {
139 debug(
"no line ending, line is incomplete");
148 buf =
findtag(buf, buflen,
'S');
150 if ((buf ==
nullptr) || (buflen < 12)) {
151 debug(
"control parser failed finding tag, ret: '%s'", buf);
155 if (sscanf(buf,
"S: %u %u %d %d %d %d",
162 debug(
"control parse failed on '%s'", buf);
168 mixer_info.
servos[i].
scale = ((float) s[0]) / 10000.0f;
169 mixer_info.
servos[i].
offset = ((float) s[1]) / 10000.0f;
175 if (buf ==
nullptr) {
176 debug(
"no line ending, line is incomplete");
181 debug(
"remaining in buf: %d, first char: %c", buflen, buf[0]);
189 debug(
"could not allocate memory for mixer");
204 int idx = (thrust_cmd / 0.25f);
218 float throttle =
constrain(2.0f * (tg * thrust_cmd + to) - 1.0f, -1.0f, 1.0f);
223 float collective_pitch =
constrain((pg * thrust_cmd + po), -0.5f, 0.5f);
228 outputs[0] = throttle;
231 outputs[i + 1] = collective_pitch
constexpr _Tp constrain(_Tp val, _Tp min_val, _Tp max_val)
#define debug(fmt, args...)
static const char * skipline(const char *buf, unsigned &buflen)
Skip a line.
float throttle_curve[HELI_CURVES_NR_POINTS]
int(* ControlCallback)(uintptr_t handle, uint8_t control_group, uint8_t control_index, float &control)
Fetch a control value.
mixer_heli_servo_s servos[4]
up to four inputs
static bool string_well_formed(const char *buf, unsigned &buflen)
Check wether the string is well formed and suitable for parsing.
static HelicopterMixer * from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handle, const char *buf, unsigned &buflen)
Factory method.
#define HELI_CURVES_NR_POINTS
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
uint8_t control_count
number of inputs
float get_control(uint8_t group, uint8_t index)
Invoke the client callback to fetch a control value.
helicopter swash plate mixer
static const char * findtag(const char *buf, unsigned &buflen, char tag)
Find a tag.
float pitch_curve[HELI_CURVES_NR_POINTS]
HelicopterMixer(ControlCallback control_cb, uintptr_t cb_handle, mixer_heli_s mixer_info)
Constructor.
Abstract class defining a mixer mixing zero or more inputs to one or more outputs.
Generic helicopter mixer for helicopters with swash plate.
unsigned mix(float *outputs, unsigned space) override
Perform the mixing function.