Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.54 KB | None | 0 0
  1. % This function takes in a square positon on the chess board,
  2. % e.g. 'A2' or 'h8'
  3. % Returns motor angles based off calibration values
  4.  
  5. % +------------------------+
  6. % |a8                    h8|
  7. % |                        |
  8. % |                        |
  9. % |                        |
  10. % |                        |
  11. % |a1                   h1 |
  12. % +------------------------+
  13.  
  14. % TODO:
  15. % If X,Y motor axes not perpendicular and parallel to
  16. % respective sides of chess board, need to calculate
  17. % based off the board being diagonal
  18. function [bigDC, smallDC] = squareToDegrees(spot)
  19.     % Make sure spot is 2 chars long
  20.     if length(spot) ~= 2
  21.        fprintf("Error: square spot not 2 chars.\n");
  22.        return;
  23.     end
  24.    
  25.     % Get ascii values for spot
  26.     ascii = double(spot);
  27.    
  28.     %% CALIBRATION
  29.     % Going from h1 to h8, bigDC Motor values for each square
  30.     % Based off -12800 at 8, 0 at 1
  31.     calibrationBigDC = [-12800, -10971, -9143, -7314,...
  32.                          -5486, -3657, -1829, 0];
  33.    
  34.     % Going from a1 to h1, smallDC motor values for each square
  35.     % These calculated based off -21500 at a, 0 at h
  36.     calibrationSmallDC  = [-21500, -18426, -15355, -12284, ...
  37.                             -9213, -6142, -3071, 0];
  38.                        
  39.     %% USE CALIBRATION
  40.     % ascii(1) = 97 for a, 104 for h (-96 gives 1through8)
  41.     smallDC = calibrationSmallDC(ascii(1) - 96);
  42.    
  43.     % ascii(2) = 49 for '1', 56 for '8' (-48 gives 1through8)
  44.     bigDC   = calibrationBigDC(8 - (ascii(2) - 48 - 1));
  45.    
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement