{"id":165,"date":"2021-04-01T16:22:25","date_gmt":"2021-04-01T08:22:25","guid":{"rendered":"http:\/\/mgspace.wiki\/docs\/?post_type=docs&#038;p=165"},"modified":"2022-01-21T23:34:08","modified_gmt":"2022-01-21T15:34:08","slug":"%e8%87%aa%e5%88%b6%e8%88%b5%e6%9c%ba","status":"publish","type":"docs","link":"http:\/\/mgspace.wiki\/docs\/?docs=%e8%87%aa%e5%88%b6%e8%88%b5%e6%9c%ba","title":{"rendered":"\u81ea\u5236\u8235\u673a-\u6559\u5177"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-480 size-medium\" src=\"http:\/\/mgspace.wiki\/docs\/wp-content\/uploads\/2021\/04\/\u5fae\u4fe1\u56fe\u7247_20200302145424-1024x768-1-500x375.jpeg\" alt=\"\" width=\"500\" height=\"375\" srcset=\"http:\/\/mgspace.wiki\/docs\/wp-content\/uploads\/2021\/04\/\u5fae\u4fe1\u56fe\u7247_20200302145424-1024x768-1-500x375.jpeg 500w, http:\/\/mgspace.wiki\/docs\/wp-content\/uploads\/2021\/04\/\u5fae\u4fe1\u56fe\u7247_20200302145424-1024x768-1-768x576.jpeg 768w, http:\/\/mgspace.wiki\/docs\/wp-content\/uploads\/2021\/04\/\u5fae\u4fe1\u56fe\u7247_20200302145424-1024x768-1.jpeg 1024w\" sizes=\"auto, (max-width: 500px) 85vw, 500px\" \/><\/p>\n<h1>\u4e00\u3001\u6982\u8ff0<\/h1>\n<hr \/>\n<p>\u8be5\u88c5\u7f6e\u4e3a\u8235\u673a\u6f14\u793a\u6559\u5177\uff0c\u5229\u7528\u5b66\u751f\u5e38\u89c1\u7684\u666e\u901a\u76f4\u6d41\u51cf\u901f\u7535\u673a\uff0c\u914d\u5408\u7535\u673a\u9a71\u52a8\u677f\u3001arduino\u4e3b\u63a7\u677f\u548c\u7535\u4f4d\u5668\u7b49\u7535\u5b50\u5143\u4ef6\uff0c\u6447\u8eab\u4e00\u53d8\uff0c\u6210\u4e3a\u4e86\u4e00\u4e2a\u53ef\u4ee5\u76f8\u5bf9\u7cbe\u786e\u63a7\u5236\u89d2\u5ea6\u7b49MINI\u8235\u673a\u3002\u4ece\u4e2d\u53ef\u4ee5\u8ba9\u5b66\u751f\u66f4\u52a0\u5f7b\u5e95\u7684\u660e\u767d\u8235\u673a\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u4ee5\u53ca\u4e0d\u540c\u90e8\u4ef6\u7684\u529f\u80fd\u3002<\/p>\n<h1>\u4e8c\u3001\u7ed3\u6784\u7ec6\u8282<\/h1>\n<hr \/>\n<p>\u51cf\u901f\u7535\u673a\u8f74\u4e0a\u901a\u8fc7\u8054\u8f74\u5668\uff0c\u8fde\u63a5\u7740\u4e00\u4e2a\u7535\u4f4d\u5668\uff0carduino\u901a\u8fc7\u4e0d\u65ad\u7684\u8bfb\u53d6\u7528\u6237\u8f6c\u52a8\u7684\u7535\u4f4d\u5668\u548c\u8fde\u63a5\u7740\u7535\u673a\u7684\u7535\u4f4d\u5668\uff0c\u6765\u83b7\u53d6\u5dee\u503c\uff0c\u7136\u540e\u7ed9\u7535\u673a\u9a71\u52a8\u677f\u4fe1\u53f7\uff0c\u63a7\u5236\u7535\u673a\u8fdb\u884c\u79fb\u52a8\uff0c\u7f29\u5c0f\u8bef\u5dee\uff0c\u4ece\u800c\u63a7\u5236\u7535\u673a\u4e0a\u56fa\u5b9a\u7684\u6307\u9488\u8fd0\u52a8\u5230\u6307\u5b9a\u7684\u4f4d\u7f6e\uff0c<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-481 size-medium\" src=\"http:\/\/mgspace.wiki\/docs\/wp-content\/uploads\/2021\/04\/\u5fae\u4fe1\u56fe\u7247_20200302145418-1024x768-1-500x375.jpeg\" alt=\"\" width=\"500\" height=\"375\" srcset=\"http:\/\/mgspace.wiki\/docs\/wp-content\/uploads\/2021\/04\/\u5fae\u4fe1\u56fe\u7247_20200302145418-1024x768-1-500x375.jpeg 500w, http:\/\/mgspace.wiki\/docs\/wp-content\/uploads\/2021\/04\/\u5fae\u4fe1\u56fe\u7247_20200302145418-1024x768-1-768x576.jpeg 768w, http:\/\/mgspace.wiki\/docs\/wp-content\/uploads\/2021\/04\/\u5fae\u4fe1\u56fe\u7247_20200302145418-1024x768-1.jpeg 1024w\" sizes=\"auto, (max-width: 500px) 85vw, 500px\" \/><\/p>\n<h1>\u4e09\u3001\u89c6\u9891\u6f14\u793a<\/h1>\n<hr \/>\n<div style=\"width: 840px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-165-1\" width=\"840\" height=\"476\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"http:\/\/mgspace.wiki\/docs\/wp-content\/uploads\/2021\/04\/0c52f56cd1a6593192cdba18c1183200.mp4?_=1\" \/><a href=\"http:\/\/mgspace.wiki\/docs\/wp-content\/uploads\/2021\/04\/0c52f56cd1a6593192cdba18c1183200.mp4\">http:\/\/mgspace.wiki\/docs\/wp-content\/uploads\/2021\/04\/0c52f56cd1a6593192cdba18c1183200.mp4<\/a><\/video><\/div>\n<h1>\u56db\u3001\u6e90\u7801<\/h1>\n<hr \/>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\">\/\/variables\nshort int valRead = 0;\nshort int motorPWM = 110; \/\/amount of power motor (0-255) were 255 is max.\n\n\/\/constants\nconst short int wireMT_1 = 9; \/\/for wire motor H bridge\nconst short int wireMT_2 = 10; \/\/for wire motor H bridge\nconst short int potMT = A0; \/\/motor potentiometer\nconst short int potIn = A1; \/\/input potentiometer\nconst short int diff_error = 3; \/\/max error to potentiometer motor\nconst short int minPot = 400;  \/\/minimal position potentiometer motor (0-1023)\nconst short int maxPot = 1010; \/\/max position potentiometer motor (0-1023)\nconst short int maxValIn = 1023; \/\/max *input value. For this case 1023, the max of pot.\n\/\/ *here can use something like degress, where max could be 180\n\n\/\/setup\nvoid setup() {\n  Serial.begin(9600);\n  pinMode (wireMT_1, OUTPUT); \/\/wire motor to H bridge\n  pinMode (wireMT_2, OUTPUT); \/\/wire motor to H bridge\n  pinMode (potMT, INPUT); \/\/motor potentiometer\n  pinMode (potIn, INPUT); \/\/input potentiometer\n  digitalWrite (wireMT_1, LOW);\n  digitalWrite (wireMT_2, LOW);\n}\n\n\/\/run motor function\nvoid runMotor(short int valTarget) {\n  \/\/proportionality between input and output value\n  while (valRead &lt;= valTarget &amp;&amp; abs(valRead - valTarget) &gt;  diff_error) {\n    valRead = (((float)analogRead(potMT) - minPot) \/ (maxPot - minPot)) * maxValIn;\n    \/\/run motor\n    analogWrite (wireMT_1, motorPWM);\n    analogWrite (wireMT_2, 0);\n  }\n  analogWrite (wireMT_1, 0); \/\/turn off motor\n  \n  \/\/proportionality between input and output value\n  while (valRead &gt;= valTarget &amp;&amp; abs(valRead - valTarget) &gt;  diff_error) {\n    valRead = (((float)analogRead(potMT) - minPot) \/ (maxPot - minPot)) * maxValIn;\n    \/\/run motor\n    analogWrite (wireMT_2, motorPWM);\n    analogWrite (wireMT_1, 0);\n  }\n  analogWrite (wireMT_2, 0); \/\/turn off motor\n}\n\n\/\/loop\nvoid loop() {\n  short int val = analogRead(potIn); \/\/read input potentiometer\n  runMotor(val); \/\/run motor for target value\n  \/\/runMotor(1023-val); \/\/use for invert direction motor\n  Serial.print(\"motor: \");\n  Serial.print(analogRead(A0));\n  Serial.print(\"   input: \");\n  Serial.print(analogRead(A1));\n  Serial.println();\n}<\/pre>\n<h1>\u4e94\u3001\u8d44\u6599\u4e0b\u8f7d<\/h1>\n<hr \/>\n<p>\u300c1\u300d\u8054\u8f74\u56683D\u6a21\u578b\uff1a<a href=\"http:\/\/mgspace.wiki\/docs\/wp-content\/uploads\/2021\/04\/diy-servo-connector.stl_.zip\">diy-servo-connector.stl<\/a><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-486\" src=\"http:\/\/mgspace.wiki\/docs\/wp-content\/uploads\/2021\/04\/speedmeter.psd\" alt=\"\" width=\"1\" height=\"1\" \/>\u300c2\u300d\u4eea\u8868\u76d8\u9762\u677f\u56fe\u7eb8\uff1a<a href=\"http:\/\/mgspace.wiki\/docs\/wp-content\/uploads\/2021\/04\/speedmeter.psd.zip\">speedmeter.psd<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u6982\u8ff0 \u8be5\u88c5\u7f6e\u4e3a\u8235\u673a\u6f14\u793a\u6559\u5177\uff0c\u5229\u7528\u5b66\u751f\u5e38\u89c1\u7684\u666e\u901a\u76f4\u6d41\u51cf\u901f\u7535\u673a\uff0c\u914d\u5408\u7535\u673a\u9a71\u52a8\u677f\u3001arduino\u4e3b\u63a7\u677f\u548c\u7535\u4f4d\u5668\u7b49 &hellip; <a href=\"http:\/\/mgspace.wiki\/docs\/?docs=%e8%87%aa%e5%88%b6%e8%88%b5%e6%9c%ba\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u81ea\u5236\u8235\u673a-\u6559\u5177\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":4236,"parent":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"doc_category":[84],"doc_tag":[],"class_list":["post-165","docs","type-docs","status-publish","has-post-thumbnail","hentry","doc_category-teaching-tools"],"_links":{"self":[{"href":"http:\/\/mgspace.wiki\/docs\/index.php?rest_route=\/wp\/v2\/docs\/165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/mgspace.wiki\/docs\/index.php?rest_route=\/wp\/v2\/docs"}],"about":[{"href":"http:\/\/mgspace.wiki\/docs\/index.php?rest_route=\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"http:\/\/mgspace.wiki\/docs\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/mgspace.wiki\/docs\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=165"}],"version-history":[{"count":6,"href":"http:\/\/mgspace.wiki\/docs\/index.php?rest_route=\/wp\/v2\/docs\/165\/revisions"}],"predecessor-version":[{"id":4237,"href":"http:\/\/mgspace.wiki\/docs\/index.php?rest_route=\/wp\/v2\/docs\/165\/revisions\/4237"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/mgspace.wiki\/docs\/index.php?rest_route=\/wp\/v2\/media\/4236"}],"wp:attachment":[{"href":"http:\/\/mgspace.wiki\/docs\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=165"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"http:\/\/mgspace.wiki\/docs\/index.php?rest_route=%2Fwp%2Fv2%2Fdoc_category&post=165"},{"taxonomy":"doc_tag","embeddable":true,"href":"http:\/\/mgspace.wiki\/docs\/index.php?rest_route=%2Fwp%2Fv2%2Fdoc_tag&post=165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}