Skip to content

Save mixer values to params when canned mixer is selected#448

Merged
gabesnow99 merged 1 commit intoremove-gnss-fullfrom
vtail_mixing_issues_in_sim
May 21, 2025
Merged

Save mixer values to params when canned mixer is selected#448
gabesnow99 merged 1 commit intoremove-gnss-fullfrom
vtail_mixing_issues_in_sim

Conversation

@JMoore5353
Copy link
Contributor

Motivation

This rosflight_ros_pkgs PR adds the functionality for other nodes to query rosflight_io for the current values of the firmware parameters.

Previously, the canned mixer types were not stored in the firmware's parameters, so rosflight_io had no idea what the correct mixer parameters were when a canned mixer was selected.

What I did:

  • Added a save_secondary_mixer_params and save_primary_mixer_params methods to the firmware mixer. When a canned mixer is selected, it now inverts it like normal and then saves those values to the mixer parameters.

Note that this is consistent with how custom mixers are saved -- the "inverted" version is saved to the parameters, which is then directly multiplied by the force vector to get the desired outputs.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the mixer functionality so that when a canned mixer is selected, its inverted values are also stored in the firmware parameters.

  • Adds two new methods, save_primary_mixer_params() and save_secondary_mixer_params(), to persist mixer values.
  • Calls these new methods appropriately in the mixer initialization process.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/mixer.cpp Introduces new parameter saving functions and calls them in init_mixing() to store the mixer values.
include/mixer.h Declares the new save_primary_mixer_params() and save_secondary_mixer_params() methods.

Comment on lines +412 to +444
// This assumes the parameters are stored in order in the param enum
int output_param_index = (int) PARAM_PRIMARY_MIXER_OUTPUT_0 + i;
int pwm_rate_param_index = (int) PARAM_PRIMARY_MIXER_PWM_RATE_0 + i;
RF_.params_.set_param_int(output_param_index, primary_mixer_.output_type[i]);
RF_.params_.set_param_float(pwm_rate_param_index, primary_mixer_.default_pwm_rate[i]);
}

// Save the mixer values to the firmware parameters
for (int i=0; i<NUM_MIXER_OUTPUTS; ++i) {
// This assumes the parameters are stored in order in the param enum
int param_index = (int) PARAM_PRIMARY_MIXER_0_0 + 6 * i;
RF_.params_.set_param_float(param_index++, primary_mixer_.Fx[i]);
RF_.params_.set_param_float(param_index++, primary_mixer_.Fy[i]);
RF_.params_.set_param_float(param_index++, primary_mixer_.Fz[i]);
RF_.params_.set_param_float(param_index++, primary_mixer_.Qx[i]);
RF_.params_.set_param_float(param_index++, primary_mixer_.Qy[i]);
RF_.params_.set_param_float(param_index, primary_mixer_.Qz[i]);
}
}

void Mixer::save_secondary_mixer_params()
{
// Save the mixer values to the firmware parameters
// The secondary mixer does not have header values (they are the same as the primary mixer)
for (int i=0; i<NUM_MIXER_OUTPUTS; ++i) {
// This assumes the parameters are stored in order in the param enum
int param_index = (int) PARAM_SECONDARY_MIXER_0_0 + 6 * i;
RF_.params_.set_param_float(param_index++, secondary_mixer_.Fx[i]);
RF_.params_.set_param_float(param_index++, secondary_mixer_.Fy[i]);
RF_.params_.set_param_float(param_index++, secondary_mixer_.Fz[i]);
RF_.params_.set_param_float(param_index++, secondary_mixer_.Qx[i]);
RF_.params_.set_param_float(param_index++, secondary_mixer_.Qy[i]);
RF_.params_.set_param_float(param_index, secondary_mixer_.Qz[i]);
Copy link

Copilot AI May 14, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider refactoring the similar parameter saving loops in save_primary_mixer_params() and save_secondary_mixer_params() into a helper function to reduce code duplication and potential maintenance issues.

Suggested change
// This assumes the parameters are stored in order in the param enum
int output_param_index = (int) PARAM_PRIMARY_MIXER_OUTPUT_0 + i;
int pwm_rate_param_index = (int) PARAM_PRIMARY_MIXER_PWM_RATE_0 + i;
RF_.params_.set_param_int(output_param_index, primary_mixer_.output_type[i]);
RF_.params_.set_param_float(pwm_rate_param_index, primary_mixer_.default_pwm_rate[i]);
}
// Save the mixer values to the firmware parameters
for (int i=0; i<NUM_MIXER_OUTPUTS; ++i) {
// This assumes the parameters are stored in order in the param enum
int param_index = (int) PARAM_PRIMARY_MIXER_0_0 + 6 * i;
RF_.params_.set_param_float(param_index++, primary_mixer_.Fx[i]);
RF_.params_.set_param_float(param_index++, primary_mixer_.Fy[i]);
RF_.params_.set_param_float(param_index++, primary_mixer_.Fz[i]);
RF_.params_.set_param_float(param_index++, primary_mixer_.Qx[i]);
RF_.params_.set_param_float(param_index++, primary_mixer_.Qy[i]);
RF_.params_.set_param_float(param_index, primary_mixer_.Qz[i]);
}
}
void Mixer::save_secondary_mixer_params()
{
// Save the mixer values to the firmware parameters
// The secondary mixer does not have header values (they are the same as the primary mixer)
for (int i=0; i<NUM_MIXER_OUTPUTS; ++i) {
// This assumes the parameters are stored in order in the param enum
int param_index = (int) PARAM_SECONDARY_MIXER_0_0 + 6 * i;
RF_.params_.set_param_float(param_index++, secondary_mixer_.Fx[i]);
RF_.params_.set_param_float(param_index++, secondary_mixer_.Fy[i]);
RF_.params_.set_param_float(param_index++, secondary_mixer_.Fz[i]);
RF_.params_.set_param_float(param_index++, secondary_mixer_.Qx[i]);
RF_.params_.set_param_float(param_index++, secondary_mixer_.Qy[i]);
RF_.params_.set_param_float(param_index, secondary_mixer_.Qz[i]);
int output_param_index = (int) PARAM_PRIMARY_MIXER_OUTPUT_0 + i;
int pwm_rate_param_index = (int) PARAM_PRIMARY_MIXER_PWM_RATE_0 + i;
RF_.params_.set_param_int(output_param_index, primary_mixer_.output_type[i]);
RF_.params_.set_param_float(pwm_rate_param_index, primary_mixer_.default_pwm_rate[i]);
}
// Save the mixer values using the helper function
save_mixer_params(primary_mixer_, PARAM_PRIMARY_MIXER_0_0);
}
void Mixer::save_secondary_mixer_params()
{
// Save the mixer values using the helper function
save_mixer_params(secondary_mixer_, PARAM_SECONDARY_MIXER_0_0);
}
void Mixer::save_mixer_params(const mixer_t& mixer, int base_param_index)
{
for (int i=0; i<NUM_MIXER_OUTPUTS; ++i) {
int param_index = base_param_index + 6 * i;
RF_.params_.set_param_float(param_index++, mixer.Fx[i]);
RF_.params_.set_param_float(param_index++, mixer.Fy[i]);
RF_.params_.set_param_float(param_index++, mixer.Fz[i]);
RF_.params_.set_param_float(param_index++, mixer.Qx[i]);
RF_.params_.set_param_float(param_index++, mixer.Qy[i]);
RF_.params_.set_param_float(param_index, mixer.Qz[i]);

Copilot uses AI. Check for mistakes.
@gabesnow99 gabesnow99 merged commit 0c1d48e into remove-gnss-full May 21, 2025
2 checks passed
@gabesnow99 gabesnow99 deleted the vtail_mixing_issues_in_sim branch May 21, 2025 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants