function [Beta_DIDIM, it, Betas, flag]=DIDIM_identification(robot, benchmarkSettings, experimentDataStruct, expNb, Xhi_0, Beta_0, optionsDIDIM) % Authors: Quentin Leboutet, Julien Roux, Alexandre Janot and Gordon Cheng % % Identify the dynamics parameters of the robot using the DIDIM method: %% Data Decimation and Filtering: [~, ~, ~, ~, ~, ~, Tau_decim, ~, ~, ~, optionsDIDIM] = getFilteredData(robot, benchmarkSettings, experimentDataStruct, optionsDIDIM, expNb, 'DIDIM'); %% Populating the Torque Vector: if strcmp(benchmarkSettings.codeImplementation,'optim') % Compute the sampled vector: Y_tau = torqueVector_mex(Tau_decim); elseif strcmp(benchmarkSettings.codeImplementation,'classic') % Compute the sampled vector: Y_tau = torqueVector(Tau_decim); else error("DIDIM: unknown option"); end %% Starting Conditions: W = zeros(robot.nbDOF*optionsDIDIM.nbSampleDecim, robot.paramVectorSize); t_ctrl = linspace(benchmarkSettings.t_i, benchmarkSettings.t_f, benchmarkSettings.nbCtrlSamples); % Control epochs augmentedDesiredState = benchmarkSettings.trajectoryData.getTrajectoryData(t_ctrl, benchmarkSettings.interpolationAlgorithm); % augmentedState = [Qpp; Qp; Q]; Beta = Beta_0; eps_curr_it = 1; Betas = zeros(robot.paramVectorSize, optionsDIDIM.stopCrit.Max_it+1); crit_1=1; crit_2=1; thresholdOmega = 1e-2; thresholdWeight = 1; %% DIDIM algorithm: it = 1; Betas(:,it)=Beta; % Set of unidentifiable parameters: Xhi_d = feval(sprintf('Regressor_Xhi_d_%s', robot.name),Xhi_0); nd = length(Xhi_d); while (( (crit_1 >= optionsDIDIM.stopCrit.tol_1) && (crit_2 >= optionsDIDIM.stopCrit.tol_2 ) ) && (it= optionsDIDIM.stopCrit.Max_it flag = robot.nbDOF; fprintf("Reached iteration limit\n"); else flag = 0; fprintf("Error...\n"); end end end Beta_DIDIM = Beta; %% Debug plot: debugPlot(robot, benchmarkSettings, experimentDataStruct, Beta_0, Beta_DIDIM, optionsDIDIM, expNb , 'DIDIM'); end