Skip to content

Commit

Permalink
Tools: simulink: adjust for elimination of RCMAP_
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Mar 18, 2024
1 parent 9c53428 commit add4906
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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

8 changes: 4 additions & 4 deletions Tools/simulink/arducopter/sid_sim_init.m
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down

0 comments on commit add4906

Please sign in to comment.