Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [times, inputL, inputR, DCL, DCR, wx, wy, wz, wzavg, accelx, ...
- accely, accelz, bemfL, bemfR, steeringOut, vbat] = ...
- importORTelem(filename, Cx, Cy, Cz, Dx, Dy, Dz)
- % importOrTelem(filename, calibs) Imports telemtry data recorded from the
- % OctoRoACH robot, saved into a CSV file in the expected format. The
- % arguments provided are the filename, and a 6-vector of the accelerometer
- % calibrations, in the format: [Cx Cy Cz Dx Dy Dz], such that:
- % XLx = ((AccelX - Dx)/Cx)^2 , where XLx has the units of G's, and AccelX
- % has the units of raw integer output, as recorded from the ADXL345.
- % Current format:
- % time | Llegs | Rlegs | DCL | DCR | GyroX | GyroY | GyroZ | GryoZAvg |
- % AccelX | AccelY |AccelZ | LBEMF | RBEMF | SteerOut | Vbatt
- % 16 columns total
- format = '%n %n %n %n %n %n %n %n %n %n %n %n %n %n %n %n';
- fid = fopen(filename,'r');
- %Import CSV data, and automatically skip header lines
- C = textscan(fid,format,'delimiter',',','commentstyle','%');
- D = cell2mat(C);
- if any(isnan(D))
- error('Imported data seems to contain a NaN. You are probably importing something with the wrong number of columns. Aborting.');
- end
- % To convert gyro counts to deg/sec
- count2deg = 1/14.3750;
- % Unpack the rows of D
- times = D(:,1); % microseconds
- inputL = D(:,2); % raw counts, max = vbat
- inputR = D(:,3); % raw counts, max = vbat
- DCL = D(:,4); % PWM counts, max = 3999 (see AP for details)
- DCR = D(:,5); % PWM counts, max = 3999 (see AP for details)
- wx = D(:,6) * count2deg; % degrees / second
- wy = D(:,7) * count2deg; % degrees / second
- wz = D(:,8) * count2deg; % degrees / second
- wzavg = D(:,9) * count2deg; % degrees / second
- accelx = D(:,10); % raw counts, converted to G's below
- accely = D(:,11); % raw counts, converted to G's below
- accelz = D(:,12); % raw counts, converted to G's below
- bemfL = D(:,13); % ADC counts, max = vbat
- bemfR = D(:,14); % ADC counts, max = vbat
- steeringOut = D(:,15); % raw counts, no max
- vbat = D(:,16); % ADC counts
- % Apply important calibrations to accel data before returning:
- accelx = ((accelx - Dx)/Cx);
- accely = ((accely - Dy)/Cy);
- accelz = ((accelz - Dz)/Cz).^2 ;
- % Cleanup
- dims = size(D);
- disp(['Got ', num2str(dims(1)), ' samples'])
- fclose(fid);
Add Comment
Please, Sign In to add comment