From add4906638e0508706d168237acb7dd0e3688dfc Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Mon, 18 Mar 2024 11:42:35 +1100 Subject: [PATCH] Tools: simulink: adjust for elimination of RCMAP_ --- .../findRCChannelNumberForAuxFunction.m | 40 +++++++++++++++++++ Tools/simulink/arducopter/sid_sim_init.m | 8 ++-- 2 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 Tools/simulink/arducopter/functions/findRCChannelNumberForAuxFunction.m diff --git a/Tools/simulink/arducopter/functions/findRCChannelNumberForAuxFunction.m b/Tools/simulink/arducopter/functions/findRCChannelNumberForAuxFunction.m new file mode 100644 index 00000000000000..84982b2e8b6c49 --- /dev/null +++ b/Tools/simulink/arducopter/functions/findRCChannelNumberForAuxFunction.m @@ -0,0 +1,40 @@ +function RCChannelNumberForAuxFunction = findRCChannelNumberForAuxFunction(obj,functionNumber) +% Return a channel number for the supplied function number from the enumeration in RC_Channel.h +% +% Peter Barker, based on getParamVal.m by Fabian Bredemeier +% License: GPL v3 + +% Get list of parameter names +param_names = cell(length(obj.PARM.Name),1); +for i=1:length(obj.PARM.Name) + param_names{i,1} = deblank(obj.PARM.Name(i,1:16)); +end + +% Translate parameter name to cell array if only one name is provided +if ~iscell(paramName) + desParamNames{1} = paramName; +else + desParamNames = paramName; +end + +FIXME below this point + +% Read parameter(s) with boolean indexing +paramVals = single(zeros(numel(desParamNames),1)); +for i = 1:length(desParamNames) + paramIdx = strcmp(param_names, desParamNames{i}); + paramVal = single(obj.PARM.Value(paramIdx)); + if isempty(paramVal) + warning('Parameter could not be found!'); + paramVal = []; + return; + end + paramVals(i,1) = paramVal(1); % Prevent nultidimensional parameters + + if isempty(paramVals) + error(['Parameter ' desParam{i} ' could not be found.']); + end +end + +end + diff --git a/Tools/simulink/arducopter/sid_sim_init.m b/Tools/simulink/arducopter/sid_sim_init.m index fb331a61271880..8a0ef389ffdffa 100644 --- a/Tools/simulink/arducopter/sid_sim_init.m +++ b/Tools/simulink/arducopter/sid_sim_init.m @@ -119,10 +119,10 @@ clear trim_x trim_y %% RCIN - Radio Input and parameters for Attitude Control -rollCh = getParamVal(sid, 'RCMAP_ROLL'); -pitchCh = getParamVal(sid, 'RCMAP_PITCH'); -yawCh = getParamVal(sid, 'RCMAP_YAW'); -thrCh = getParamVal(sid, 'RCMAP_THROTTLE'); +rollCh = findRCChannelNumberForAuxFunction(sid, 201); +pitchCh = findRCChannelNumberForAuxFunction(sid, 202); +yawCh = findRCChannelNumberForAuxFunction(sid, 204); +thrCh = findRCChannelNumberForAuxFunction(sid, 203); simIn.param.RCIN.DZ_RLL = getParamVal(sid, ['RC' num2str(rollCh) '_DZ']); simIn.param.RCIN.MIN_RLL = getParamVal(sid, ['RC' num2str(rollCh) '_MIN']);