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.
This commit is contained in:
Beat Küng 2021-11-27 18:57:49 +01:00 committed by Daniel Agar
parent 1901edf13c
commit d1abdd0f8d
12 changed files with 68 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -1,5 +1,6 @@
module_name: PWM Output
actuator_output:
add_reverse_range_param: true
output_groups:
- param_prefix: PWM_MAIN
channel_label: 'Channel'

View File

@ -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}'

View File

@ -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

View File

@ -1,6 +1,7 @@
module_name: SIM
actuator_output:
add_reverse_range_param: true
output_groups:
- param_prefix: PWM_MAIN
channel_label: Channel

View File

@ -1,5 +1,6 @@
module_name: PWM MAIN
actuator_output:
add_reverse_range_param: true
output_groups:
- generator: pwm
param_prefix: PWM_MAIN

View File

@ -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'

View File

@ -1,5 +1,6 @@
module_name: UAVCANv1
actuator_output:
add_reverse_range_param: true
output_groups:
- param_prefix: UCAN1_ESC
channel_label: 'ESC'

View File

@ -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;
}

View File

@ -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)

View File

@ -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