Skip to content

Commit 17ed113

Browse files
committed
save mixer values to params when canned mixer is selectedf
1 parent b76c4e6 commit 17ed113

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

include/mixer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ class Mixer : public ParamListenerInterface
126126
float mix_multirotor_with_motor_parameters(Controller::Output commands);
127127
float mix_multirotor_without_motor_parameters(Controller::Output commands);
128128
void select_primary_or_secondary_mixer();
129+
void save_primary_mixer_params();
130+
void save_secondary_mixer_params();
129131

130132
// clang-format off
131133

src/mixer.cpp

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,10 @@ void Mixer::init_mixing()
247247
RF_.comm_manager_.log(CommLinkInterface::LogSeverity::LOG_INFO,
248248
"Inverting selected mixing matrix...");
249249
primary_mixer_ = invert_mixer(array_of_mixers_[mixer_choice]);
250-
250+
251+
// Save the primary mixer values to the params
252+
save_primary_mixer_params();
253+
251254
// If using a canned mixer but the USE_MOTOR_PARAM is set to 1 (true), raise a warning.
252255
// Motor parameters (thus motor speed/voltage calculations) should not be used with the canned
253256
// mixers, since the output will be vanishingly small. Check online documentation for more
@@ -263,6 +266,9 @@ void Mixer::init_mixing()
263266
// Don't invert the fixedwing mixers
264267
primary_mixer_ = *array_of_mixers_[mixer_choice];
265268

269+
// Save the primary mixer values to the params
270+
save_primary_mixer_params();
271+
266272
// For the fixedwing canned mixers, the RC_F_AXIS parameter should be set to 0 (X-AXIS).
267273
// Otherwise, the aircraft will arm and appear to be ok, but will zero out any RC throttle
268274
// commands. Raise a warning if this condition is detected
@@ -305,6 +311,7 @@ void Mixer::init_mixing()
305311
"Secondary mixer defaulting to primary!");
306312

307313
secondary_mixer_ = primary_mixer_;
314+
save_secondary_mixer_params();
308315
} else if (mixer_choice == CUSTOM) {
309316
// Load the custom mixer for the secondary mixer based off the saved parameters.
310317
RF_.comm_manager_.log(CommLinkInterface::LogSeverity::LOG_INFO,
@@ -317,10 +324,13 @@ void Mixer::init_mixing()
317324
RF_.comm_manager_.log(CommLinkInterface::LogSeverity::LOG_INFO,
318325
"Inverting selected mixing matrix...");
319326

327+
// Invert the secondary mixer
320328
secondary_mixer_ = invert_mixer(array_of_mixers_[mixer_choice]);
329+
save_secondary_mixer_params();
321330
} else {
322331
// Don't invert the fixedwing mixers
323332
secondary_mixer_ = *array_of_mixers_[mixer_choice];
333+
save_secondary_mixer_params();
324334
}
325335

326336
init_PWM();
@@ -395,6 +405,46 @@ Mixer::mixer_t Mixer::invert_mixer(const mixer_t* mixer_to_invert)
395405
return inverted_mixer;
396406
}
397407

408+
void Mixer::save_primary_mixer_params()
409+
{
410+
// Save the mixer header values
411+
for (int i=0; i<NUM_MIXER_OUTPUTS; ++i) {
412+
// This assumes the parameters are stored in order in the param enum
413+
int output_param_index = (int) PARAM_PRIMARY_MIXER_OUTPUT_0 + i;
414+
int pwm_rate_param_index = (int) PARAM_PRIMARY_MIXER_PWM_RATE_0 + i;
415+
RF_.params_.set_param_int(output_param_index, primary_mixer_.output_type[i]);
416+
RF_.params_.set_param_float(pwm_rate_param_index, primary_mixer_.default_pwm_rate[i]);
417+
}
418+
419+
// Save the mixer values to the firmware parameters
420+
for (int i=0; i<NUM_MIXER_OUTPUTS; ++i) {
421+
// This assumes the parameters are stored in order in the param enum
422+
int param_index = (int) PARAM_PRIMARY_MIXER_0_0 + 6 * i;
423+
RF_.params_.set_param_float(param_index++, primary_mixer_.Fx[i]);
424+
RF_.params_.set_param_float(param_index++, primary_mixer_.Fy[i]);
425+
RF_.params_.set_param_float(param_index++, primary_mixer_.Fz[i]);
426+
RF_.params_.set_param_float(param_index++, primary_mixer_.Qx[i]);
427+
RF_.params_.set_param_float(param_index++, primary_mixer_.Qy[i]);
428+
RF_.params_.set_param_float(param_index, primary_mixer_.Qz[i]);
429+
}
430+
}
431+
432+
void Mixer::save_secondary_mixer_params()
433+
{
434+
// Save the mixer values to the firmware parameters
435+
// The secondary mixer does not have header values (they are the same as the primary mixer)
436+
for (int i=0; i<NUM_MIXER_OUTPUTS; ++i) {
437+
// This assumes the parameters are stored in order in the param enum
438+
int param_index = (int) PARAM_SECONDARY_MIXER_0_0 + 6 * i;
439+
RF_.params_.set_param_float(param_index++, secondary_mixer_.Fx[i]);
440+
RF_.params_.set_param_float(param_index++, secondary_mixer_.Fy[i]);
441+
RF_.params_.set_param_float(param_index++, secondary_mixer_.Fz[i]);
442+
RF_.params_.set_param_float(param_index++, secondary_mixer_.Qx[i]);
443+
RF_.params_.set_param_float(param_index++, secondary_mixer_.Qy[i]);
444+
RF_.params_.set_param_float(param_index, secondary_mixer_.Qz[i]);
445+
}
446+
}
447+
398448
void Mixer::load_primary_mixer_values()
399449
{
400450
// Load the mixer header values

0 commit comments

Comments
 (0)