Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. % Delete Opened Ports in MATLAB
  2. clear all;
  3. clc;
  4.  
  5. delete(instrfind)
  6.  
  7. ser = serial('COM9', 'BaudRate',115200, 'Timeout',10);
  8. syms right;
  9. syms left;
  10. syms stan;
  11. stan = 1;
  12. syms i;
  13. syms iPuls;
  14. volume = 0;
  15. fopen(ser);
  16. i=0;
  17. tim = 0;
  18. actval=0;
  19. tim2 = 0;
  20. while true
  21. d = fscanf(ser, '%d %d %d');
  22. value1 = d(1,:);
  23. value2 = d(2,:);
  24. value3 = d(3,:);
  25.  
  26. fprintf("%d\t%d\t%d\t%d\t%d\t%d\r\n", value1,value3,stan,volume,i,tim);
  27.  
  28.  
  29. %stan 1
  30. %%%%%oczekiwanie na ruch
  31. if(value1<600 && value3>600 && stan == 1)
  32. stan = 2;
  33. tim = i;
  34. tim2 = i;
  35. elseif(value1>600 && value3<600 && stan == 1)
  36. stan = 3;
  37. tim=i;
  38. tim2 = i;
  39. end
  40. %stan 2
  41.  
  42. if((value1<400 || value3<400) && stan == 2 && (i-tim)>30)
  43. stan = 6;
  44. elseif(value1>600 && value3<600 && (i-tim2) < 20 && stan == 2)
  45. stan = 4;
  46. elseif(value1>600 && (i-tim2) > 20 && stan == 2)
  47. stan = 1;
  48.  
  49. end
  50. %stan 3
  51. if((value1<600 || value3<600) && stan == 3 && (i-tim)>30)
  52. stan = 6;
  53. elseif(value1<600 && value3>600 && (i-tim2) < 20 && stan == 3)
  54. stan = 5;
  55. elseif(value3>600 && (i-tim2) > 20 && stan == 3)
  56. stan = 1;
  57. end
  58. %stan 4
  59. %%%%przewiniecie w prawo
  60. if(stan==4)
  61. system('nircmd.exe sendkey 176 press');
  62. if(value1>600 && value3>600 && stan == 4)
  63. stan = 1;
  64. end
  65. end
  66.  
  67. %stan 5
  68. if(stan == 5)
  69. %%%przewinięcie w lewo
  70.  
  71. system('nircmd.exe sendkey 177 press');
  72. end
  73. if(value1>600 && value3>600 && stan == 5)
  74. stan = 1;
  75. end
  76.  
  77.  
  78. if(stan == 6)
  79.  
  80. volume = (value2 / 4) * 1000;
  81. volume = floor(volume);
  82.  
  83. if(value2>600 || (actval-value2)>1000)
  84. stan = 1;
  85. else
  86. system(sprintf('nircmd.exe setsysvolume %d',volume));
  87. end
  88.  
  89. actval=value2;
  90. end
  91. pause(10/1000);
  92. i = i+1;
  93.  
  94. plot(d, 'LineWidth',2,'Color',[0,0,1.0])
  95. ylim([0,4000])
  96.  
  97. drawnow
  98. end
  99.  
  100.  
  101. fclose(ser);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement