diff --git a/loadardu.m b/loadardu.m new file mode 100644 index 0000000000000000000000000000000000000000..dba4718a871b2960f4222871cb0bdc034eda25a6 --- /dev/null +++ b/loadardu.m @@ -0,0 +1,93 @@ +function arduData = loadardu(arduFile) + % LOADARDU Load the Arduino data and clean it. + % This function loads the Arduino data. Then it: + % - removes the unneeded columns + % - convert time into milliseconds + % - converts the output into an array instead of a table + % - calculates the power + % - re-aligns the angles properly from the raw wing positions + % ----- + % Output format: + % The output array has one row per timestep. The columns are ordered as follows: + % angleFrontLeft, angleFrontRight, angleAftLeft, angleAftRight, powerFront, powerAft + % + % Syntax: + % arduData = loadardu(arduFile) load the Arduino data file, then clean it and return a cleaned + % version with only the relevant fields in form of an array. + % + % Inputs: + % arduFile: Arduino file. + % + % Outputs: + % arduData: Array with the cleaned data. + % + % See also: readdata. + + % ---------------------------------------------------------------------------------------------- + % TODO: Check for inconsistencies in the table + % ---------------------------------------------------------------------------------------------- + % (c) Copyright 2022 University of Liege + % Author: Thomas Lambert <t.lambert@uliege.be> + % ULiege - Aeroelasticity and Experimental Aerodynamics + % MIT License + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + % Load data + arduTable = table; + if ~isempty(arduFile) + arduTable = loadcsv(['arduinoFiles/', arduFile, '.csv']); + end + + % Time conversion + arduTable.time = timetomilli(arduTable.time); + + % Remove data with duplicate timecode + [~, idx] = unique(arduTable.time); % indexes of unique timecodes + + arduTable = arduTable(idx, :); + + % Convert into table + arduData = table2array(arduTable); + + % Calculate power, remove tension and current + power = arduData(:, [5, 7]) .* arduData(:, [6, 8]); + arduData(:, 5:end) = []; + arduData = [arduData, power]; + + % Recalculate angles properly + +end + +function rawTable = loadcsv(file) + % LOADCSV Load the csv into a table + + % Tweak options before import + opts = detectImportOptions(file); + opts.VariableNamesLine = 1; + + opts.SelectedVariableNames = {'x_RXDate_Time', 'x1_Left_field6_', 'x1_Right_field7_', ... + 'x2_Left_field8_', 'x2_Right_field9_', 'x1_Tension_field14_', ... + 'x1_Current_field15_', 'x2_Tension_field16_', ... + 'x2_Current_field17_'}; + opts.DataLines = [2 Inf]; + + % Import + rawTable = readtable(file, opts); + + % Rename columns + rawTable.Properties.VariableNames = {'time', 'angleFrontLeft', 'angleFrontRight', ... + 'angleAftLeft', 'angleAftRight', ... + 'tensionF', 'currentF', 'tensionA', 'currentA'}; + +end + +function timeMilli = timetomilli(time) + % TIMETOMILLI Converts datetime data into milliseconds since start + + % Parse time properly + time = datetime(time, 'InputFormat', 'uuuu/MM/dd''/ ''HH:mm:ss::SSS', 'TimeZone', 'UTC'); + + % Converts into difference from the first time + timeMilli = milliseconds(time - time(1)) + 1; % Shift of 1 so first time is 1 millisecond + +end