Guest User

Untitled

a guest
Oct 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.38 KB | None | 0 0
  1. function [times, inputL, inputR, DCL, DCR, wx, wy, wz, wzavg, accelx, ...
  2.     accely, accelz, bemfL, bemfR, steeringOut, vbat] = ...
  3.     importORTelem(filename, Cx, Cy, Cz, Dx, Dy, Dz)
  4. %  importOrTelem(filename, calibs)  Imports telemtry data recorded from the
  5. %  OctoRoACH robot, saved into a CSV file in the expected format. The
  6. %  arguments provided are the filename, and a 6-vector of the accelerometer
  7. %  calibrations, in the format: [Cx Cy Cz Dx Dy Dz], such that:
  8. %  XLx = ((AccelX - Dx)/Cx)^2 , where XLx has the units of G's, and AccelX
  9. %  has the units of raw integer output, as recorded from the ADXL345.
  10.  
  11. % Current format:
  12. % time | Llegs | Rlegs | DCL | DCR | GyroX | GyroY | GyroZ | GryoZAvg |
  13. %        AccelX | AccelY |AccelZ | LBEMF | RBEMF | SteerOut | Vbatt
  14. % 16 columns total
  15. format = '%n %n %n %n %n %n %n %n %n %n %n %n %n %n %n %n';
  16.  
  17. fid = fopen(filename,'r');
  18.  
  19. %Import CSV data, and automatically skip header lines
  20. C = textscan(fid,format,'delimiter',',','commentstyle','%');
  21. D = cell2mat(C);
  22.  
  23. if any(isnan(D))
  24.     error('Imported data seems to contain a NaN. You are probably importing something with the wrong number of columns. Aborting.');
  25. end
  26.  
  27. % To convert gyro counts to deg/sec
  28. count2deg = 1/14.3750;
  29.  
  30. % Unpack the rows of D
  31. times = D(:,1);              % microseconds
  32. inputL = D(:,2);             % raw counts, max = vbat
  33. inputR = D(:,3);             % raw counts, max = vbat
  34. DCL = D(:,4);                % PWM counts, max = 3999 (see AP for details)
  35. DCR = D(:,5);                % PWM counts, max = 3999 (see AP for details)
  36. wx = D(:,6) * count2deg;     % degrees / second
  37. wy = D(:,7) * count2deg;     % degrees / second
  38. wz = D(:,8) * count2deg;     % degrees / second
  39. wzavg = D(:,9) * count2deg;  % degrees / second
  40. accelx = D(:,10);            % raw counts, converted to G's below
  41. accely = D(:,11);            % raw counts, converted to G's below
  42. accelz = D(:,12);            % raw counts, converted to G's below
  43. bemfL = D(:,13);             % ADC counts, max = vbat
  44. bemfR = D(:,14);             % ADC counts, max = vbat
  45. steeringOut = D(:,15);       % raw counts, no max
  46. vbat = D(:,16);              % ADC counts
  47.  
  48. % Apply important calibrations to accel data before returning:
  49. accelx = ((accelx - Dx)/Cx);
  50. accely = ((accely - Dy)/Cy);
  51. accelz = ((accelz - Dz)/Cz).^2 ;
  52.  
  53. % Cleanup
  54. dims = size(D);
  55. disp(['Got ', num2str(dims(1)), ' samples'])
  56. fclose(fid);
Add Comment
Please, Sign In to add comment