Skip to content

Commit

Permalink
changed the array_of_mixers to use pointers to reduce storage
Browse files Browse the repository at this point in the history
  • Loading branch information
JMoore5353 committed Jan 10, 2025
1 parent e0a9a7d commit cfa96c8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
28 changes: 14 additions & 14 deletions include/mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Mixer : public ParamListenerInterface

void load_primary_mixer_values();
void load_secondary_mixer_values();
mixer_t invert_mixer(const mixer_t mixer_to_invert);
mixer_t invert_mixer(const mixer_t* mixer_to_invert);
float mix_multirotor_with_motor_parameters(Controller::Output commands);
float mix_multirotor_without_motor_parameters(Controller::Output commands);
void select_primary_or_secondary_mixer();
Expand Down Expand Up @@ -255,19 +255,19 @@ class Mixer : public ParamListenerInterface
mixer_selection_t mixer_to_use_;
bool primary_mixer_is_selected_ = false;

const mixer_t array_of_mixers_[NUM_MIXERS] = {
esc_calibration_mixing,
quadcopter_plus_mixing,
quadcopter_x_mixing,
hex_plus_mixing,
hex_x_mixing,
octocopter_plus_mixing,
octocopter_x_mixing,
Y6_mixing,
X8_mixing,
fixedwing_mixing,
fixedwing_inverted_vtail_mixing,
custom_mixing,
const mixer_t* array_of_mixers_[NUM_MIXERS] = {
&esc_calibration_mixing,
&quadcopter_plus_mixing,
&quadcopter_x_mixing,
&hex_plus_mixing,
&hex_x_mixing,
&octocopter_plus_mixing,
&octocopter_x_mixing,
&Y6_mixing,
&X8_mixing,
&fixedwing_mixing,
&fixedwing_inverted_vtail_mixing,
&custom_mixing,
};

// clang-format on
Expand Down
22 changes: 11 additions & 11 deletions src/mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void Mixer::init_mixing()
primary_mixer_ = invert_mixer(array_of_mixers_[mixer_choice]);
} else {
// Don't invert the fixedwing mixers
primary_mixer_ = array_of_mixers_[mixer_choice];
primary_mixer_ = *array_of_mixers_[mixer_choice];
}

// Load the primary mixer header to the mixer_to_use_ header. Note that both the primary and
Expand Down Expand Up @@ -293,7 +293,7 @@ void Mixer::init_mixing()
secondary_mixer_ = invert_mixer(array_of_mixers_[mixer_choice]);
} else {
// Don't invert the fixedwing mixers
secondary_mixer_ = array_of_mixers_[mixer_choice];
secondary_mixer_ = *array_of_mixers_[mixer_choice];
}

init_PWM();
Expand All @@ -317,19 +317,19 @@ void Mixer::update_parameters()
V_max_ = RF_.params_.get_param_float(PARAM_VOLT_MAX);
}

Mixer::mixer_t Mixer::invert_mixer(const mixer_t mixer_to_invert)
Mixer::mixer_t Mixer::invert_mixer(const mixer_t* mixer_to_invert)
{
Eigen::Matrix<float, 6, NUM_MIXER_OUTPUTS> mixer_matrix;
mixer_matrix.setZero();

// Convert the mixer_t to an Eigen matrix
for (int i=0; i<NUM_MIXER_OUTPUTS; i++) {
mixer_matrix(0, i) = mixer_to_invert.Fx[i];
mixer_matrix(1, i) = mixer_to_invert.Fy[i];
mixer_matrix(2, i) = mixer_to_invert.Fz[i];
mixer_matrix(3, i) = mixer_to_invert.Qx[i];
mixer_matrix(4, i) = mixer_to_invert.Qy[i];
mixer_matrix(5, i) = mixer_to_invert.Qz[i];
mixer_matrix(0, i) = mixer_to_invert->Fx[i];
mixer_matrix(1, i) = mixer_to_invert->Fy[i];
mixer_matrix(2, i) = mixer_to_invert->Fz[i];
mixer_matrix(3, i) = mixer_to_invert->Qx[i];
mixer_matrix(4, i) = mixer_to_invert->Qy[i];
mixer_matrix(5, i) = mixer_to_invert->Qz[i];
}

// Calculate the pseudoinverse of the mixing matrix using the SVD
Expand All @@ -355,8 +355,8 @@ Mixer::mixer_t Mixer::invert_mixer(const mixer_t mixer_to_invert)
mixer_t inverted_mixer;

for (int i = 0; i < NUM_MIXER_OUTPUTS; i++) {
inverted_mixer.output_type[i] = mixer_to_invert.output_type[i];
inverted_mixer.default_pwm_rate[i] = mixer_to_invert.default_pwm_rate[i];
inverted_mixer.output_type[i] = mixer_to_invert->output_type[i];
inverted_mixer.default_pwm_rate[i] = mixer_to_invert->default_pwm_rate[i];
inverted_mixer.Fx[i] = mixer_matrix_pinv(i, 0);
inverted_mixer.Fy[i] = mixer_matrix_pinv(i, 1);
inverted_mixer.Fz[i] = mixer_matrix_pinv(i, 2);
Expand Down

1 comment on commit cfa96c8

@avtoku
Copy link
Contributor

@avtoku avtoku commented on cfa96c8 Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well have primary_mixer and secondary_mixer as pointers as well, initialized pointing to a default mixer.

Please sign in to comment.