Skip to content

Commit

Permalink
PWM: Draft implementation to respect PWM_OUT when loading defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
MaEtUgR authored and LorenzMeier committed Jul 2, 2021
1 parent 50b0f0e commit acf848b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ROMFS/px4fmu_common/init.d/rc.interface
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ then
fi
fi

param set PWM_AUX_OUT ${PWM_AUX_OUT}

if [ $MIXER_AUX != none -a $AUX_MODE = none -a -e $OUTPUT_AUX_DEV ]
then
#
Expand Down Expand Up @@ -268,6 +270,8 @@ then
fi
fi

param set PWM_MAIN_OUT ${PWM_OUT}

if [ $EXTRA_MIXER_MODE != none ]
then

Expand Down
17 changes: 14 additions & 3 deletions src/drivers/pwm_out/PWMOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ void PWMOut::update_params()
int32_t pwm_max_default = PWM_DEFAULT_MAX;
int32_t pwm_disarmed_default = 0;
int32_t pwm_rate_default = 50;
int32_t pwm_default_channels = 0;

const char *prefix;

Expand All @@ -673,6 +674,7 @@ void PWMOut::update_params()
param_get(param_find("PWM_MAIN_MAX"), &pwm_max_default);
param_get(param_find("PWM_MAIN_DISARM"), &pwm_disarmed_default);
param_get(param_find("PWM_MAIN_RATE"), &pwm_rate_default);
param_get(param_find("PWM_MAIN_OUT"), &pwm_default_channels);

} else if (_class_instance == CLASS_DEVICE_SECONDARY) {
prefix = "PWM_AUX";
Expand All @@ -681,6 +683,7 @@ void PWMOut::update_params()
param_get(param_find("PWM_AUX_MAX"), &pwm_max_default);
param_get(param_find("PWM_AUX_DISARM"), &pwm_disarmed_default);
param_get(param_find("PWM_AUX_RATE"), &pwm_rate_default);
param_get(param_find("PWM_AUX_OUT"), &pwm_default_channels);

} else if (_class_instance == CLASS_DEVICE_TERTIARY) {
prefix = "PWM_EXTRA";
Expand All @@ -695,6 +698,14 @@ void PWMOut::update_params()
return;
}

uint32_t single_ch = 0;
uint32_t pwm_default_channel_mask = 0;

while ((single_ch = pwm_default_channels % 10)) {
pwm_default_channel_mask |= 1 << (single_ch - 1);
pwm_default_channels /= 10;
}

// update the counter
// this is needed to decide if disarmed PWM output should be turned on or not
int num_disarmed_set = 0;
Expand All @@ -716,7 +727,7 @@ void PWMOut::update_params()
param_set(param_find(str), &pwm_min_new);
}

} else {
} else if (pwm_default_channel_mask & 1 << i) {
_mixing_output.minValue(i) = pwm_min_default;
}
}
Expand All @@ -736,7 +747,7 @@ void PWMOut::update_params()
param_set(param_find(str), &pwm_max_new);
}

} else {
} else if (pwm_default_channel_mask & 1 << i) {
_mixing_output.maxValue(i) = pwm_max_default;
}
}
Expand Down Expand Up @@ -773,7 +784,7 @@ void PWMOut::update_params()
param_set(param_find(str), &pwm_dis_new);
}

} else {
} else if (pwm_default_channel_mask & 1 << i) {
_mixing_output.disarmedValue(i) = pwm_disarmed_default;
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/lib/pwm/pwm_aux_params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ parameters:
- group: PWM Outputs
definitions:

PWM_AUX_OUT:
description:
short: PWM channels used as ESC outputs
long: |
Number representing the channels e.g. 134 - Channel 1, 3 and 4.
Global e.g. PWM_AUX_MIN/MAX/DISARM limits only apply to these channels.
type: int32
min: 0
max: 123456789
default: 0

PWM_AUX_RATE:
description:
short: PWM aux output frequency
Expand Down
11 changes: 11 additions & 0 deletions src/lib/pwm/pwm_main_params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ parameters:
- group: PWM Outputs
definitions:

PWM_MAIN_OUT:
description:
short: PWM channels used as ESC outputs
long: |
Number representing the channels e.g. 134 - Channel 1, 3 and 4.
Global e.g. PWM_MAIN_MIN/MAX/DISARM limits only apply to these channels.
type: int32
min: 0
max: 123456789
default: 0

PWM_MAIN_RATE:
description:
short: PWM main output frequency
Expand Down

1 comment on commit acf848b

@Kim-zhi-jiang
Copy link

Choose a reason for hiding this comment

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

@MaEtUgR VTOL one problem look here

#18177

Please sign in to comment.