{"id":220989,"date":"2014-04-27T16:45:03","date_gmt":"2014-04-27T12:45:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=220989"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=220989","title":{"rendered":"<span class=\"post_title\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0440\u043e\u0431\u043e\u0442\u0430 \u0431\u0430\u043b\u0430\u043d\u0441\u0435\u0440\u0430 \u043d\u0430 arduino<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u041c\u043d\u0435 \u0434\u0430\u0432\u043d\u043e \u043d\u0435 \u0434\u0430\u0432\u0430\u043b\u043e \u043f\u043e\u043a\u043e\u044f \u0436\u0435\u043b\u0430\u043d\u0438\u0435 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0438 \u0432\u043e\u043f\u043b\u043e\u0442\u0438\u0442\u044c \u0435\u0433\u043e \u0436\u0438\u0437\u043d\u044c.<br \/>  \u0412\u044b\u0431\u043e\u0440 \u043f\u0430\u043b \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0443 \u043e\u0431 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043c\u0430\u044f\u0442\u043d\u0438\u043a\u0435. \u0418\u0442\u043e\u0433 \u043d\u0430 \u0432\u0438\u0434\u0435\u043e:<br \/>  <iframe loading=\"lazy\" width=\"560\" height=\"349\" src=\"\/\/www.youtube.com\/embed\/m5duyke8FDE?wmode=opaque\" frameborder=\"0\" allowfullscreen><\/iframe><br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c<\/h4>\n<p>  \u042f \u043d\u0435 \u0431\u0443\u0434\u0443 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0439 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f, \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u044d\u0442\u043e \u0442\u0440\u0435\u0442\u0438\u0439 \u043a\u0443\u0440\u0441 \u0438\u043d\u0441\u0442\u0438\u0442\u0443\u0442\u0430. \u0414\u043b\u044f \u0442\u0435\u0445 \u0436\u0435 \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0435\u043d \u0432\u044b\u0432\u043e\u0434, \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0441\u0441\u044b\u043b\u043a\u0430, \u0433\u0434\u0435 \u043e\u043d \u043e\u043f\u0438\u0441\u0430\u043d \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435.<br \/>  \u0421\u0438\u0441\u0442\u0435\u043c\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0432\u0438\u0434\u0435:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/6a4\/a3f\/b6b\/6a4a3fb6bafd82908ad62633580151c6.png\"\/><\/p>\n<p>  \u041c\u0430\u044f\u0442\u043d\u0438\u043a \u044d\u0442\u043e \u043c\u0430\u0441\u0441\u0430 m<sub>p<\/sub> \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u043d\u0430\u044f \u043d\u0430 \u043a\u043e\u043d\u0446\u0435 \u043d\u0435\u0432\u0435\u0441\u043e\u043c\u043e\u0433\u043e \u0441\u0442\u0435\u0440\u0436\u043d\u044f \u0434\u043b\u0438\u043d\u044b l. \u041d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043e\u043d\u0435\u0446 \u0441\u0442\u0435\u0440\u0436\u043d\u044f \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u0435\u043d \u0434\u0432\u0438\u0433\u0430\u0442\u0435\u043b\u044c, \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 M<sub>k<\/sub> \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0449\u0438\u0439 \u0435\u0433\u043e \u043d\u0430 \u043a\u043e\u043b\u0435\u0441\u043e \u043c\u0430\u0441\u0441\u043e\u0439 m<sub>w<\/sub> \u0438 \u0440\u0430\u0434\u0438\u0443\u0441\u043e\u043c r. <br \/>  \u0417\u0430\u0434\u0430\u0447\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u2014 \u0441\u0442\u0430\u0431\u0438\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u044f\u0442\u043d\u0438\u043a \u0432 \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0432 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0435\u0441\u043e.<\/p>\n<p>  \u0423\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u043c\u0430\u044f\u0442\u043d\u0438\u043a \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c\u044b \u0441 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0432\u0438\u0434\u0435:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/17f\/7af\/d49\/17f7afd49f9ffbe5980007145fad2be9.gif\"\/><\/p>\n<p>  \u041e\u043d\u0438 \u043a\u0430\u0436\u0443\u0442\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u044b\u043c\u0438, \u043d\u043e \u0441\u0430\u043c \u0440\u043e\u0431\u043e\u0442 \u043e \u043d\u0438\u0445 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u0435\u0442, \u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043b\u0438\u043d\u0435\u0430\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c, \u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0443\u044e:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/450\/1b2\/f01\/4501b2f0160de88ea3788b03ee70a44b.gif\"\/><\/p>\n<h4>\u0421\u0438\u043d\u0442\u0435\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f<\/h4>\n<p>  \u0417\u0430\u0432\u0438\u0434\u0443\u044e \u043b\u044e\u0434\u044f\u043c, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 PID-\u0440\u0435\u0433\u0443\u043b\u044f\u0442\u043e\u0440. \u042f \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0447\u0430\u0441\u043e\u0432 \u043d\u0430 \u043f\u043e\u0434\u0433\u043e\u043d\u043a\u0443 \u0435\u0433\u043e \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u043e\u0432, \u043d\u043e \u0442\u0430\u043a \u0438 \u043d\u0435 \u0441\u0443\u043c\u0435\u043b \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0441\u0442\u043e\u044f\u0449\u0435\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430. \u041d\u0430\u0443\u0447\u043d\u044b\u0439 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u043f\u043e\u0441\u043e\u0432\u0435\u0442\u043e\u0432\u0430\u043b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u043e-\u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u044b\u043c \u0440\u0435\u0433\u0443\u043b\u044f\u0442\u043e\u0440\u043e\u043c(<a href=\"http:\/\/ru.wikipedia.org\/wiki\/%D0%9B%D0%B8%D0%BD%D0%B5%D0%B9%D0%BD%D0%BE-%D0%BA%D0%B2%D0%B0%D0%B4%D1%80%D0%B0%D1%82%D0%B8%D1%87%D0%BD%D1%8B%D0%B9_%D1%80%D0%B5%D0%B3%D1%83%D0%BB%D1%8F%D1%82%D0%BE%D1%80\">\u0432\u0438\u043a\u0438<\/a>). \u042d\u0442\u043e\u0442 \u0440\u0435\u0433\u0443\u043b\u044f\u0442\u043e\u0440, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 PID-\u0440\u0435\u0433\u0443\u043b\u044f\u0442\u043e\u0440\u0430, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0438\u0445 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u043e\u0432 \u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0435. \u041d\u0438\u043a\u0430\u043a\u0438\u0445 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0430\u043d\u0430\u043b\u043e\u0433\u043e\u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u043e\u0439 \u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u043b\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f \u0435\u0433\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0438 \u0443\u043c\u0435\u043d\u0438\u0435 \u0440\u0435\u0448\u0430\u0442\u044c \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0420\u0438\u043a\u043a\u0430\u0442\u0438, \u043d\u0443 \u0438\u043b\u0438 Matlab.<\/p>\n<p>  \u0412 \u043c\u0430\u0442\u043b\u0430\u0431\u0435 \u0440\u0430\u0441\u0447\u0435\u0442 \u0440\u0435\u0433\u0443\u043b\u044f\u0442\u043e\u0440\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0442\u0430\u043a\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u043a\u043e\u043c\u043c\u0430\u043d\u0434:  <\/p>\n<pre><code class=\"matlab\">A=[0 1.0 0 0;0 0 -140 0;0 0 0 1.0;0 0 28 0] B=[0;212.85;0;-19.15] Q=[5 0 0 0;0 5 0 0;0 0 1 0;0 0 0 1] R=1500 [K,S,e]=lqr(A,B,Q,R) <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043c\u0430\u0442\u0440\u0438\u0446\u044b A \u0438 B \u2014 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0438\u0437 \u043b\u0438\u043d\u0435\u0430\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u043e\u0431\u043e\u0442\u0430.<br \/>  \u041c\u0430\u0442\u0440\u0438\u0446\u0430 Q \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e \u0448\u0442\u0440\u0430\u0444\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0437\u0430 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435 \u043e\u0442 \u043d\u0430\u0447\u0430\u043b\u0430 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442, \u0437\u0430\u043c\u0435\u0442\u044c\u0442\u0435 \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0432\u0445\u043e\u0434\u044f\u0442 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438.<br \/>  \u041c\u0430\u0442\u0440\u0438\u0446\u0430 R \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e \u0448\u0442\u0440\u0430\u0444\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0437\u0430 \u0440\u0430\u0441\u0442\u0440\u0430\u0442\u0443 \u044d\u043d\u0435\u0440\u0433\u0438\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c.<\/p>\n<p>  \u0412 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 K \u0431\u0443\u0434\u0443\u0442 \u043b\u0435\u0436\u0430\u0442\u044c \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u044b \u0440\u0435\u0433\u0443\u043b\u044f\u0442\u043e\u0440\u0430.<\/p>\n<h4>\u0421\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u044f<\/h4>\n<p>  \u0412 Matlab simulink \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u044d\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u0435\u0441\u043b\u0438 \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u044f \u043c\u043e\u0433\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u044c\u044e. \u0417\u0434\u0435\u0441\u044c \u0436\u0435 \u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0433\u0440\u0430\u0444\u0438\u043a\u0438.<br \/>  \u0423\u0433\u043e\u043b \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u044f \u043c\u0430\u044f\u0442\u043d\u0438\u043a\u0430:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/cb4\/d5e\/f43\/cb4d5ef438f960f1d4f0869a2fc0eb32.png\"\/><br \/>  \u0423\u0433\u043e\u043b \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u0435\u0441\u0430:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/4a7\/fd6\/43a\/4a7fd643a564b0c1880bd470a28e9e79.png\"\/><br \/>  \u041c\u043e\u043c\u0435\u043d\u0442 \u0434\u0432\u0438\u0433\u0430\u0442\u0435\u043b\u044f:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/76f\/9b1\/7f1\/76f9b17f1a29fbbab8248603fdaa874a.png\"\/><\/p>\n<h4>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432 \u0436\u0435\u043b\u0435\u0437\u0435<\/h4>\n<p>  \u0421\u0430\u043c \u043a\u0430\u0440\u043a\u0430\u0441 \u0440\u043e\u0431\u043e\u0442\u0430 \u044d\u0442\u043e \u0430\u043b\u044e\u043c\u0438\u043d\u0438\u0435\u0432\u044b\u0435 \u043f\u0440\u043e\u0444\u0438\u043b\u044f 12\u043c\u043c \u0438 14\u043c\u043c, \u043e\u043d\u0438 \u0432\u0445\u043e\u0434\u044f\u0442 \u0434\u0440\u0443\u0433 \u0432 \u0434\u0440\u0443\u0433\u0430. \u0421\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u044b \u0437\u0430\u043a\u043b\u0435\u043f\u043a\u0430\u043c\u0438. \u042d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u0438\u043a\u0430 \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0430 \u043d\u0430 \u043a\u0443\u0441\u043e\u043a \u0441\u0442\u0435\u043a\u043b\u043e\u0442\u0435\u043a\u0441\u0442\u043e\u043b\u0438\u0442\u0430 \u0432 \u0444\u043e\u0440\u043c\u0435 \u0431\u0443\u043a\u0432\u044b T. \u041c\u043e\u0442\u043e\u0440\u044b \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u044b \u0447\u0435\u0440\u0435\u0437 \u0441\u0442\u0435\u043a\u043b\u043e\u0442\u0435\u043a\u0441\u0442\u043e\u043b\u0438\u0442\u043e\u0432\u044b\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043d\u0438\u043a.<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/123\/abf\/c60\/123abfc606d73c2c9ab4adcd3c88d03c.jpg\"\/><\/p>\n<p>  \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u044f \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043c\u043e\u0442\u043e\u0440\u044b:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/cc1\/af0\/346\/cc1af03460bd0cdfa926516c921edca0.jpg\"\/><br \/>  \u0418\u0445 \u043a\u0440\u0443\u0442\u044f\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 2,2\u043a\u0433*\u0441\u043c \u0438\u043b\u0438 0.2\u041d\u043c. \u0418\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u043e\u043b\u044c\u0448\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u044b\u043b\u0438 \u0432\u044b\u0431\u0440\u0430\u043d\u044b \u0434\u0440\u0443\u0433\u0438\u0435 \u043c\u043e\u0442\u043e\u0440\u044b:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/de5\/e0e\/507\/de5e0e5072b68c36a79c22552e26eb62.jpg\"\/><br \/>  <a href=\"http:\/\/www.pololu.com\/product\/1445\">\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044f<\/a><br \/>  \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u0440\u0443\u0442\u044f\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 14\u043a\u0433*\u0441\u043c \u0438\u043b\u0438 1.4\u041d\u043c. \u0422\u043e\u043a\u0430 \u043e\u043d\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u044e\u0442 \u0434\u043e 5A, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u0443 \u0430\u0440\u0434\u0443\u0438\u043d\u0449\u0438\u043a\u043e\u0432 L293D \u0442\u0443\u0442 \u043d\u0435 \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442.<\/p>\n<p>  \u0414\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0443\u0433\u043b\u0430 \u0438 \u0443\u0433\u043b\u043e\u0432\u043e\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f IMU \u2014 \u0433\u0438\u0440\u043e\u0441\u043a\u043e\u043f \u0438 \u0430\u043a\u0441\u0435\u043b\u0435\u0440\u043e\u043c\u0435\u0442\u0440. \u0423 \u043c\u0435\u043d\u044f \u0437\u0430\u0432\u0430\u043b\u044f\u043b\u0430\u0441\u044c \u043f\u043b\u0430\u0442\u0430 \u0441 \u0433\u0438\u0440\u043e\u0441\u043a\u043e\u043f\u043e\u043c L3G \u0438 \u0430\u043a\u0441\u0435\u043b\u0435\u0440\u043e\u043c\u0435\u0442\u0440\u043e\u043c \u0441 \u043c\u0430\u0433\u043d\u0435\u0442\u043e\u043c\u0435\u0442\u0440\u043e\u043c LSM303. \u041f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043f\u043b\u0430\u0442 \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0438 \u044f \u043d\u0435 \u0441\u0442\u0430\u043d\u0443 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441\u0435\u043d\u0441\u043e\u0440\u043e\u0432. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0434\u0430\u0442\u0447\u0438\u043a\u043e\u0432 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c, \u0442\u0430\u043a \u043a\u0430\u043a \u0433\u0438\u0440\u043e\u0441\u043a\u043e\u043f \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0443\u0445\u043e\u0434\u0438\u0442, \u0430 \u0430\u043a\u0441\u0435\u043b\u0435\u0440\u043e\u043c\u0435\u0442\u0440 \u0448\u0443\u043c\u0438\u0442 \u0438 \u0441\u0438\u043b\u044c\u043d\u043e \u0432\u0440\u0435\u0442, \u0435\u0441\u043b\u0438 \u0440\u043e\u0431\u043e\u0442 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u043c\u0435\u043d\u044f\u044f \u0443\u0433\u043b\u0430.<br \/>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u044b, \u043d\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b \u0444\u0438\u043b\u044c\u0442\u0440 \u041a\u0430\u043b\u043c\u0430\u043d\u0430 \u0438 RC-\u0444\u0438\u043b\u044c\u0442\u0440 (complementary filter). \u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434:  <\/p>\n<pre><code class=\"cpp\">float lastCompTime=0; float filterAngle=1.50; float dt=0.005;  float comp_filter(float newAngle, float newRate) {  dt=(millis()-lastCompTime)\/1000.0; float filterTerm0; float filterTerm1; float filterTerm2; float timeConstant;  timeConstant=0.5;  filterTerm0 = (newAngle - filterAngle) * timeConstant * timeConstant; filterTerm2 += filterTerm0 * dt; filterTerm1 = filterTerm2 + ((newAngle - filterAngle) * 2 * timeConstant) + newRate; filterAngle = (filterTerm1 * dt) + filterAngle; lastCompTime=millis(); return filterAngle; } <\/code><\/pre>\n<p>  \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e, \u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. <\/p>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0441\u0435\u043d\u0441\u043e\u0440 \u2014 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0443\u0440\u043d\u044b\u0439 \u044d\u043d\u043a\u043e\u0434\u0435\u0440 \u043d\u0430 \u043c\u043e\u0442\u043e\u0440\u0435. \u041e\u043d \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u044b\u0435 \u0438\u043c\u043f\u0443\u043b\u044c\u0441\u044b \u043d\u0430 2\u0445 \u0441\u0432\u043e\u0438\u0445 \u0432\u044b\u0432\u043e\u0434\u0430\u0445:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/7d7\/420\/2d4\/7d74202d4c728ac742c98aa2e9e790b7.jpg\"\/><br \/>  \u0421\u0447\u0438\u0442\u0430\u0442\u044c \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u043b\u0438\u0431\u043e \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f\u043c\u0438, \u043b\u0438\u0431\u043e \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u0446\u0438\u043a\u043b\u0435. \u041d\u0430 arduino playground \u0435\u0441\u0442\u044c \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f <a href=\"http:\/\/playground.arduino.cc\/Main\/RotaryEncoders\">\u0441\u0442\u0430\u0442\u044c\u044f<\/a> \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043a\u043e\u0434\u0430. <\/p>\n<p>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0443\u0433\u043b\u043e\u0432\u0443\u044e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043a\u043e\u043b\u0435\u0441\u0430. \u0422\u0443\u0442 \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0448\u043a\u043e\u043b\u044c\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435\/\u0437\u0430\u0442\u0440\u0430\u0447\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f.  <\/p>\n<pre><code class=\"cpp\">#define ToPhiRad(x) ((x)*0.00280357142)  timer_old = timer; timer=millis(); G_Dt = (timer-timer_old)\/1000.0;     dPhi=(ToPhiRad(encoder0Pos)-lastPhi)\/G_Dt; <\/code><\/pre>\n<p>  ToPhiRad \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0438\u043a\u043e\u0432 \u044d\u043d\u043a\u043e\u0434\u0435\u0440\u0430 \u0432 \u0443\u0433\u043e\u043b \u043a\u043e\u043b\u0435\u0441\u0430, \u043c\u043e\u0439 \u044d\u043d\u043a\u043e\u0434\u0435\u0440 \u0432\u044b\u0434\u0430\u0435\u0442 \u043e\u043a\u043e\u043b\u043e 2240 \u0442\u0438\u043a\u043e\u0432 \u043d\u0430 \u043e\u0431\u043e\u0440\u043e\u0442. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0443\u0433\u043e\u043b \u043d\u0443\u0436\u043d\u043e \u0443\u043c\u043d\u043e\u0436\u0438\u0442\u044c \u0442\u0438\u043a\u0438 \u043d\u0430 2 \u041f\u0438 \u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u0438\u0445 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0438 \u043f\u043e\u043b\u043d\u043e\u043c \u043e\u0431\u043e\u0440\u043e\u0442\u0435 \u043a\u043e\u043b\u0435\u0441\u0430.<\/p>\n<p>  \u041f\u043e\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0441\u0435\u043d\u0441\u043e\u0440\u043e\u0432 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u0432 LQR \u0440\u0435\u0433\u0443\u043b\u044f\u0442\u043e\u0440:  <\/p>\n<pre><code class=\"cpp\">float K1=0.1,K2=0.29,K3=6.5,K4=1.12;  long getLQRSpeed(float phi,float dphi,float angle,float dangle){   return constrain((phi*K1+dphi*K2+K3*angle+dangle*K4)*285,-400,400); } <\/code><\/pre>\n<p>  \u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u044b \u0432\u0437\u044f\u0442\u044b \u0438\u0437 Matlab, \u043f\u0440\u0430\u0432\u0434\u0430 \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u044f \u043f\u043e\u0434\u043f\u0440\u0430\u0432\u0438\u043b 2 \u043f\u0435\u0440\u0432\u044b\u0445 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u0430.<br \/>  \u041c\u043e\u0439 \u0434\u0440\u0430\u0439\u0432\u0435\u0440, \u0432\u0435\u0440\u043d\u0435\u0435 \u0435\u0433\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0442 -400 \u0434\u043e 400. \u042f \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043b, \u0447\u0442\u043e \u043d\u0430 400 \u043e\u043d \u0432\u044b\u0434\u0430\u0435\u0442 \u043d\u0430 \u043c\u043e\u0442\u043e\u0440 12\u0412, \u0442.\u0435. \u043c\u043e\u0442\u043e\u0440 \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 (1.4\u041d\u043c). \u0420\u0430\u0437\u0434\u0435\u043b\u0438\u0432 400 \u043d\u0430 1.4 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u044d\u043d\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u0438\u0437 \u041d\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0434\u0430\u0435\u0442 LQR, \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0443.<\/p>\n<p>  \u041f\u0440\u043e\u0441\u0442\u043e \u0441\u0442\u0430\u0431\u0438\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u043e\u0431\u043e\u0442\u0430 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0435 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a \u043d\u0435\u043c\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0441\u044f BT-\u043c\u043e\u0434\u0443\u043b\u044c HC-05. \u041c\u043e\u0434\u0443\u043b\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043a \u0441\u0435\u0440\u0438\u0439\u043d\u043e\u043c\u0443 \u043f\u043e\u0440\u0442\u0443 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430. \u041e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 3.3\u0412, \u0430 arduino \u043d\u0430 5\u0412, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0439 \u0432\u0445\u043e\u0434 \u043c\u043e\u0434\u0443\u043b\u044f \u043d\u0430\u0434\u043e \u0447\u0435\u0440\u0435\u0437 \u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c \u043d\u0430\u043f\u0440\u044f\u0436\u0435\u043d\u0438\u044f. \u0412\u043e\u0442 \u0441\u0445\u0435\u043c\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/bfb\/00b\/570\/bfb00b570fe8fb3472ba904b9064d2bb.jpg\"\/><br \/>  \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0446\u0438\u043a\u043b\u0430 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u043c\u043e\u0434\u0443\u043b\u044c \u043d\u0430 \u043f\u0440\u0435\u0434\u043c\u0435\u0442 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432:  <\/p>\n<pre><code class=\"cpp\">float phiDif=0.f; float factorDif=0.f;  float getPhiAdding(float dif){ \/\/\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a \u0443\u0433\u043b\u0443 \u043a\u043e\u043b\u0435\u0441 \u0434\u043b\u044f \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f \u0432\u043f\u0435\u0440\u0435\u0434-\u043d\u0430\u0437\u0430\u0434    if(dif&lt;200 && dif&gt;-200){return 0.f;}   float ret = dif*0.08;    return ret; }  float getFactorAdding(float dif){\/\/\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u0434\u043b\u044f \u043f\u043e\u0432\u043e\u0440\u043e\u0442\u0430   if(dif&lt;200 && dif&gt;-200){return 0.f;}   float ret = dif\/500*20;   return ret; } \/\/======== if (Serial.available()){     BluetoothData=Serial.read();      if(BluetoothData=='w'){          phiDif=200;      } else if(BluetoothData=='s'){        phiDif=-200;      } else if(BluetoothData=='a'){          factorDif=200;      } else if(BluetoothData=='d'){          factorDif=-200;      } else if(BluetoothData=='c'){          factorDif=0;       phiDif=0;      }     } <\/code><\/pre>\n<p>  \u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0441\u0435\u043d\u0441\u043e\u0440\u043e\u0432 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u0432 \u0440\u0435\u0433\u0443\u043b\u044f\u0442\u043e\u0440, \u0430 \u0435\u0433\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u0432\u043e\u0437\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u043d\u0430 \u043c\u043e\u0442\u043e\u0440\u044b:  <\/p>\n<pre><code class=\"cpp\">    encoder0Pos+=getPhiAdding(phiDif);     lastPhi=ToPhiRad(encoder0Pos);         spd=getLQRSpeed(ToPhiRad(encoder0Pos),dPhi,balanceAt-angle,gyroRate[coordY]);     float factorL=getFactorAdding(factorDif);     md.setSpeeds(spd-factorL,spd+factorL); <\/code><\/pre>\n<p>  \u0420\u0430\u0437 \u0432 50 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u043e\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u043b\u0435\u043c\u0435\u0442\u0440\u0438\u044f-\u0443\u0433\u043e\u043b \u0440\u043e\u0431\u043e\u0442\u0430:  <\/p>\n<pre><code class=\"cpp\">    if(millis()%50==0){       Serial.println(angle);     } <\/code><\/pre>\n<h4>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0440\u0430\u0434\u0438\u043e\u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0423\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u0441 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430 \u043f\u043e\u0434 android.<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/d5a\/798\/51a\/d5a79851a9b4c197ec5ce99bf071912d.png\"\/><br \/>  \u041f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043a \u043a\u043e\u043c\u0443 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f, bt-\u043c\u043e\u0434\u0443\u043b\u044c \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0443\u0436\u0435 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d \u0441 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u043e\u043c (\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043a\u043e\u0434 1234).  <\/p>\n<pre><code class=\"java\">BluetoothAdapter bluetooth; String []boundedItems; protected static final int RECIEVE_MESSAGE = 1;  @Override protected void onCreate(Bundle savedInstanceState) { \t\t\/\/... \t\tbluetooth = BluetoothAdapter.getDefaultAdapter();\t\t \t\tif(bluetooth != null){ \t\t\tif (!bluetooth.isEnabled()) { \t\t\t    bluetooth.enable(); \t\t\t} \t\t} \t\tSet&lt;BluetoothDevice&gt; bounded=bluetooth.getBondedDevices(); \t\tboundedItems=new String[bounded.size()]; \t\tint i=0; \t\tfor (BluetoothDevice bluetoothDevice : bounded) { \t\t\tboundedItems[i++]=bluetoothDevice.getName(); \t\t} \t\t \t\tshowListDialog();\t\t \t\t\/\/... }  public void showListDialog(){ \t\tAlertDialog.Builder builder = new AlertDialog.Builder(this);  \t\tbuilder.setTitle(&quot;Pick a device&quot;); \t\tbuilder.setItems(boundedItems, new DialogInterface.OnClickListener() {  \t\t   public void onClick(DialogInterface dialog, int item) { \t\t        connectTo(item); \t\t   }  \t\t});  \t\tAlertDialog alert = builder.create();  \t\talert.show(); \t} <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u0431\u043e\u0440\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c\u0441\u044f \u043a \u043d\u0435\u043c\u0443:  <\/p>\n<pre><code class=\"java\">\tprivate static final UUID MY_UUID = UUID.fromString(&quot;00001101-0000-1000-8000-00805F9B34FB&quot;); \tBluetoothSocket btSocket;  \tpublic void connectTo(int id){ \t\tSet&lt;BluetoothDevice&gt; bounded=bluetooth.getBondedDevices(); \t\tfor (BluetoothDevice bluetoothDevice : bounded) { \t\t\tif(bluetoothDevice.getName().equalsIgnoreCase(boundedItems[id])){ \t\t\t\ttry { \t\t\t\t\tbtSocket=bluetoothDevice.createRfcommSocketToServiceRecord(MY_UUID); \t\t\t\t\tbtSocket.connect(); \t\t\t\t\tct=new ConnectionThread(btSocket); \t\t\t\t\tct.start(); \t\t\t\t} catch (IOException e) { \t\t\t\t\te.printStackTrace(); \t\t\t\t\ttry { \t\t\t\t\t\tbtSocket.close(); \t\t\t\t\t} catch (IOException e1) { \t\t\t\t\t\te1.printStackTrace(); \t\t\t\t\t} \t\t\t\t\tshowListDialog(); \t\t\t\t} \t\t\t\treturn; \t\t\t} \t\t} \t\t \t} <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0440\u0442\u0443\u0435\u0442 \u043f\u043e\u0442\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u0435\u0439 \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0438 \u0440\u043e\u0431\u043e\u0442\u043e\u043c:  <\/p>\n<pre><code class=\"java\">private class ConnectionThread extends Thread{ \tprivate final InputStream mmInStream;\t\t \tprivate final BufferedReader br;         private final OutputStream mmOutStream;                public ConnectionThread(BluetoothSocket socket) throws IOException {             mmInStream =  socket.getInputStream();             br=new BufferedReader(new InputStreamReader(mmInStream));             mmOutStream = socket.getOutputStream();                      }                public void run() {             while (true) {                                                     try {                 \t\t\tString line=br.readLine(); \t\t\t\t\th.obtainMessage(RECIEVE_MESSAGE, line).sendToTarget(); \t\t\t\t} catch (IOException e) { \t\t\t\t\te.printStackTrace(); \t\t\t\t}             }         }         public void sendCmd(char cmd){         \ttry{         \t\tmmOutStream.write(cmd);         \t}catch (IOException e) { \t\t\te.printStackTrace(); \t\t}         } } <\/code><\/pre>\n<p>  \u041f\u043e\u0442\u043e\u043a \u043f\u043e\u0441\u044b\u043b\u0430\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c\u0443 \u043f\u043e\u0442\u043e\u043a\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 Handler, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"java\">h = new Handler() {       public void handleMessage(android.os.Message msg) {       switch (msg.what) {             case RECIEVE_MESSAGE:                                                             \tString line=(String)msg.obj;             \ttry{             \t\tfloat a=Float.parseFloat(line.trim());             \t\tbalancerView.setAngle((float) (a-Math.PI\/2.f));\t\t                   \t}catch (Exception e) { }\t            \t             break; \t}       }; }; <\/code><\/pre>\n<p>  balancerView \u044d\u0442\u043e \u043f\u043e\u0442\u043e\u043c\u043e\u043a \u043a\u043b\u0430\u0441\u0441\u0430 SurfaceView, \u043e\u043d \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u0432\u043e\u0434\u043e\u043c \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0440\u043e\u0431\u043e\u0442\u0430.<br \/>  \u0412\u043e\u0442 \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434 \u043f\u0435\u0440\u0435\u0440\u0438\u0441\u043e\u0432\u043a\u0438:  <\/p>\n<pre><code class=\"java\">public void draw(Canvas canvas) { \tPaint paint=new Paint(); \tpaint.setStrokeWidth(3); \tcanvas.save(); \tcanvas.rotate((float) (angle*180.f\/Math.PI), cx, cy);\t\t \t\t \tpaint.setColor(Color.BLACK);         \tcanvas.drawRect(cx-15, cy-150, cx+15, cy, paint); \tpaint.setColor(Color.WHITE);         \tcanvas.drawRect(cx-12, cy-147, cx+12, cy-3, paint);          \tpaint.setColor(Color.BLACK);         \tcanvas.drawCircle(cx, cy, 30, paint); \tpaint.setColor(Color.WHITE);         \tcanvas.drawCircle(cx, cy, 25, paint);       \tcanvas.restore();\t\t } <\/code><\/pre>\n<p>  \u041a\u043e\u043c\u043c\u0430\u043d\u0434\u044b \u0440\u043e\u0431\u043e\u0442\u0443 \u043f\u043e\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 onTouch, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0440\u043e\u0431\u043e\u0442\u043e\u043c \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044f \u043a\u043d\u043e\u043f\u043a\u0443.  <\/p>\n<pre><code class=\"java\">\t@Override \tpublic boolean onTouch(View v, MotionEvent me) { \t\tif(me.getAction()==MotionEvent.ACTION_UP){ \t\t\tct.sendCmd('c'); \t\t\treturn false; \t\t} \t\tif(v==wB){ \t\t\tct.sendCmd('w'); \t\t}else if(v==aB){ \t\t\tct.sendCmd('a'); \t\t}else if(v==sB){ \t\t\tct.sendCmd('s'); \t\t}else if(v==dB){ \t\t\tct.sendCmd('d'); \t\t} \t\treturn false; \t} <\/code><\/pre>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0421\u0430\u043c\u043e\u0435 \u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0435 \u0432\u043e \u0432\u0441\u0435\u0439 \u043f\u043e\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u0441\u043a\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043e\u0448\u043b\u0430\u0441\u044c \u0441 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439. \u0421\u0430\u043c\u0430 \u043f\u043e\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0436\u0435\u043b\u0435\u0437\u043a\u0438 \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u043e\u0434\u043d\u0430\u043a\u043e \u043f\u043e\u0434\u0431\u043e\u0440 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0442\u043e\u0440\u043e\u0432, \u0432\u044b\u0441\u043e\u0442\u044b \u0440\u043e\u0431\u043e\u0442\u0430, \u043c\u0430\u0441\u0441\u044b \u0433\u0440\u0443\u0437\u0430 \u0441\u0432\u0435\u0440\u0445\u0443 \u0438 \u0441\u0438\u043d\u0442\u0435\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430.<\/p>\n<p>  \u041a\u0430\u043a \u0438 \u043e\u0431\u0435\u0449\u0430\u043b \u0432\u044b\u0432\u043e\u0434 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0439 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0432\u0435\u0440\u043d\u0443\u0442\u043e\u0433\u043e \u043c\u0430\u044f\u0442\u043d\u0438\u043a\u0430 \u043d\u0430 \u043a\u043e\u043b\u0435\u0441\u0435: <a href=\"http:\/\/spin7ion.ru\/ru\/blog\/balancerBuildSteps\">\u0412\u044b\u0432\u043e\u0434 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0439 \u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0439\u043a\u0435<\/a>    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/220989\/\"> http:\/\/habrahabr.ru\/post\/220989\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u041c\u043d\u0435 \u0434\u0430\u0432\u043d\u043e \u043d\u0435 \u0434\u0430\u0432\u0430\u043b\u043e \u043f\u043e\u043a\u043e\u044f \u0436\u0435\u043b\u0430\u043d\u0438\u0435 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0438 \u0432\u043e\u043f\u043b\u043e\u0442\u0438\u0442\u044c \u0435\u0433\u043e \u0436\u0438\u0437\u043d\u044c.<br \/>  \u0412\u044b\u0431\u043e\u0440 \u043f\u0430\u043b \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0443 \u043e\u0431 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043c\u0430\u044f\u0442\u043d\u0438\u043a\u0435. \u0418\u0442\u043e\u0433 \u043d\u0430 \u0432\u0438\u0434\u0435\u043e:<br \/>  <iframe loading=\"lazy\" width=\"560\" height=\"349\" src=\"\/\/www.youtube.com\/embed\/m5duyke8FDE?wmode=opaque\" frameborder=\"0\" allowfullscreen><\/iframe>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-220989","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/220989","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=220989"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/220989\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=220989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=220989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=220989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}