From d1abdd0f8d5083625a30b4f983b5bb7aeee62223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Sat, 27 Nov 2021 18:57:49 +0100 Subject: [PATCH] output drivers: add option to generate a separate output range reversing param Makes it a bit easier to configure. Reversing by setting MIN > MAX is still supported. --- .../generate_actuators_metadata.py | 20 +++++++++--- Tools/module_config/generate_params.py | 32 +++++++++++++++++++ src/drivers/linux_pwm_out/module.yaml | 1 + src/drivers/pwm_out/module.yaml | 1 + src/drivers/pwm_out_sim/module_hil.yaml | 1 + src/drivers/pwm_out_sim/module_sim.yaml | 1 + src/drivers/px4io/module.yaml | 1 + src/drivers/uavcan/module.yaml | 1 + src/drivers/uavcan_v1/module.yaml | 1 + src/lib/mixer_module/mixer_module.cpp | 9 ++++++ src/lib/mixer_module/mixer_module.hpp | 1 + validation/module_schema.yaml | 3 ++ 12 files changed, 68 insertions(+), 4 deletions(-) diff --git a/Tools/module_config/generate_actuators_metadata.py b/Tools/module_config/generate_actuators_metadata.py index abff0a01a0..662471bdcb 100755 --- a/Tools/module_config/generate_actuators_metadata.py +++ b/Tools/module_config/generate_actuators_metadata.py @@ -130,7 +130,8 @@ def get_actuator_output(yaml_config, output_functions, timer_config_file, verbos return None - output_groups = yaml_config['actuator_output']['output_groups'] + actuator_output_yaml = yaml_config['actuator_output'] + output_groups = actuator_output_yaml['output_groups'] module_name = process_module_name(yaml_config['module_name']) group_idx = 0 @@ -139,8 +140,9 @@ def get_actuator_output(yaml_config, output_functions, timer_config_file, verbos actuator_output = { 'label': module_name } - if 'show_subgroups_if' in yaml_config['actuator_output']: - actuator_output['show-subgroups-if'] = yaml_config['actuator_output']['show_subgroups_if'] + if 'show_subgroups_if' in actuator_output_yaml: + actuator_output['show-subgroups-if'] = actuator_output_yaml['show_subgroups_if'] + add_reverse_range_param = actuator_output_yaml.get('add_reverse_range_param', False) # config parameters def get_config_params(param_list): @@ -159,7 +161,7 @@ def get_actuator_output(yaml_config, output_functions, timer_config_file, verbos parameters.append(param) return parameters - parameters = get_config_params(yaml_config['actuator_output'].get('config_parameters', [])) + parameters = get_config_params(actuator_output_yaml.get('config_parameters', [])) if len(parameters) > 0: actuator_output['parameters'] = parameters @@ -254,6 +256,16 @@ def get_actuator_output(yaml_config, output_functions, timer_config_file, verbos if show_if: param['show-if'] = show_if per_channel_params.append(param) + + if add_reverse_range_param: + param = { + 'label': 'Rev Range\n(for Servos)', + 'name': param_prefix+'_REV', + 'index-offset': -1, + 'show-as': 'bitset', + } + per_channel_params.append(param) + # TODO: support non-standard per-channel parameters subgroup['per-channel-parameters'] = per_channel_params diff --git a/Tools/module_config/generate_params.py b/Tools/module_config/generate_params.py index 6e2e0ce986..97a7dd249c 100755 --- a/Tools/module_config/generate_params.py +++ b/Tools/module_config/generate_params.py @@ -178,6 +178,9 @@ def get_actuator_output_params(yaml_config, output_functions, all_params = {} group_idx = 0 + add_reverse_range_param = yaml_config['actuator_output'].get('add_reverse_range_param', False) + all_param_prefixes = {} + def add_local_param(param_name, param_def): nonlocal all_params # add as a list, as there can be multiple entries with the same param_name @@ -259,6 +262,11 @@ def get_actuator_output_params(yaml_config, output_functions, for i in range(count): output_function_values[start+i] = function_name_label+' '+str(i+1) + if param_prefix not in all_param_prefixes: + all_param_prefixes[param_prefix] = [] + all_param_prefixes[param_prefix].append((instance_start, + instance_start_label, num_channels, channel_label)) + # function param param = { 'description': { @@ -338,6 +346,30 @@ When set to -1 (default), the value depends on the function (see {:}). } add_local_param(param_prefix+'_'+param_suffix+'${i}', param) + if add_reverse_range_param: + for param_prefix in all_param_prefixes: + groups = all_param_prefixes[param_prefix] + # collect the bits + channel_bits = {} + for instance_start, instance_start_label, num_instances, label in groups: + for instance in range(instance_start, instance_start+num_instances): + instance_label = instance - instance_start + instance_start_label + channel_bits[instance-1] = label + ' ' + str(instance_label) + + param = { + 'description': { + 'short': 'Reverse Output Range for '+module_name, + 'long': +'''Allows to reverse the output range for each channel. +Note: this is only useful for servos. +'''.format(channel_label), + }, + 'type': 'bitmask', + 'default': 0, + 'bit': channel_bits + } + add_local_param(param_prefix+'_REV', param) + if verbose: print('adding actuator params: {:}'.format(all_params)) return all_params diff --git a/src/drivers/linux_pwm_out/module.yaml b/src/drivers/linux_pwm_out/module.yaml index 133e04e155..e281224f62 100644 --- a/src/drivers/linux_pwm_out/module.yaml +++ b/src/drivers/linux_pwm_out/module.yaml @@ -1,5 +1,6 @@ module_name: PWM Output actuator_output: + add_reverse_range_param: true output_groups: - param_prefix: PWM_MAIN channel_label: 'Channel' diff --git a/src/drivers/pwm_out/module.yaml b/src/drivers/pwm_out/module.yaml index 3f4f380986..cc829ec9dc 100644 --- a/src/drivers/pwm_out/module.yaml +++ b/src/drivers/pwm_out/module.yaml @@ -1,5 +1,6 @@ module_name: '${PWM_MAIN_OR_AUX}' actuator_output: + add_reverse_range_param: true output_groups: - generator: pwm param_prefix: '${PWM_MAIN_OR_AUX}' diff --git a/src/drivers/pwm_out_sim/module_hil.yaml b/src/drivers/pwm_out_sim/module_hil.yaml index 25b9db39e0..faa32b96e2 100644 --- a/src/drivers/pwm_out_sim/module_hil.yaml +++ b/src/drivers/pwm_out_sim/module_hil.yaml @@ -1,6 +1,7 @@ module_name: HIL actuator_output: + add_reverse_range_param: true show_subgroups_if: 'SYS_HITL>0' output_groups: - param_prefix: HIL_ACT diff --git a/src/drivers/pwm_out_sim/module_sim.yaml b/src/drivers/pwm_out_sim/module_sim.yaml index 9964f0c419..14aa029e32 100644 --- a/src/drivers/pwm_out_sim/module_sim.yaml +++ b/src/drivers/pwm_out_sim/module_sim.yaml @@ -1,6 +1,7 @@ module_name: SIM actuator_output: + add_reverse_range_param: true output_groups: - param_prefix: PWM_MAIN channel_label: Channel diff --git a/src/drivers/px4io/module.yaml b/src/drivers/px4io/module.yaml index fcbde93c29..9a289c576b 100644 --- a/src/drivers/px4io/module.yaml +++ b/src/drivers/px4io/module.yaml @@ -1,5 +1,6 @@ module_name: PWM MAIN actuator_output: + add_reverse_range_param: true output_groups: - generator: pwm param_prefix: PWM_MAIN diff --git a/src/drivers/uavcan/module.yaml b/src/drivers/uavcan/module.yaml index 9c2ba643dc..c9267dd9d7 100644 --- a/src/drivers/uavcan/module.yaml +++ b/src/drivers/uavcan/module.yaml @@ -1,5 +1,6 @@ module_name: UAVCAN actuator_output: + add_reverse_range_param: true show_subgroups_if: 'UAVCAN_ENABLE>=3' config_parameters: - param: 'UAVCAN_ENABLE' diff --git a/src/drivers/uavcan_v1/module.yaml b/src/drivers/uavcan_v1/module.yaml index abd941df63..aec6153ec0 100644 --- a/src/drivers/uavcan_v1/module.yaml +++ b/src/drivers/uavcan_v1/module.yaml @@ -1,5 +1,6 @@ module_name: UAVCANv1 actuator_output: + add_reverse_range_param: true output_groups: - param_prefix: UCAN1_ESC channel_label: 'ESC' diff --git a/src/lib/mixer_module/mixer_module.cpp b/src/lib/mixer_module/mixer_module.cpp index c3e7a07102..ecd0f9ae8d 100644 --- a/src/lib/mixer_module/mixer_module.cpp +++ b/src/lib/mixer_module/mixer_module.cpp @@ -138,6 +138,9 @@ void MixingOutput::initParamHandles() snprintf(param_name, sizeof(param_name), "%s_%s%d", _param_prefix, "FAIL", i + 1); _param_handles[i].failsafe = param_find(param_name); } + + snprintf(param_name, sizeof(param_name), "%s_%s", _param_prefix, "REV"); + _param_handle_rev_range = param_find(param_name); } void MixingOutput::printStatus() const @@ -230,6 +233,12 @@ void MixingOutput::updateParams() } } + int32_t rev_range_param; + + if (_param_handle_rev_range != PARAM_INVALID && param_get(_param_handle_rev_range, &rev_range_param) == 0) { + _reverse_output_mask |= rev_range_param; + } + if (function_changed) { _need_function_update = true; } diff --git a/src/lib/mixer_module/mixer_module.hpp b/src/lib/mixer_module/mixer_module.hpp index 61893e01fc..bebb463be7 100644 --- a/src/lib/mixer_module/mixer_module.hpp +++ b/src/lib/mixer_module/mixer_module.hpp @@ -346,6 +346,7 @@ private: bool _has_backup_schedule{false}; const char *const _param_prefix; ParamHandles _param_handles[MAX_ACTUATORS]; + param_t _param_handle_rev_range{PARAM_INVALID}; hrt_abstime _lowrate_schedule_interval{300_ms}; ActuatorTest _actuator_test{_function_assignment}; uint32_t _reversible_mask{0}; ///< per-output bits. If set, the output is configured to be reversible (motors only) diff --git a/validation/module_schema.yaml b/validation/module_schema.yaml index 465b56b0e0..58df4c6b2c 100644 --- a/validation/module_schema.yaml +++ b/validation/module_schema.yaml @@ -251,6 +251,9 @@ actuator_output: function: type: string allowed: [ enable ] + add_reverse_range_param: + # Add a separate range reversing bitmask param. + type: boolean output_groups: type: list minlength: 1