{"id":6777,"date":"2018-07-31T12:08:28","date_gmt":"2018-07-31T03:08:28","guid":{"rendered":"https:\/\/techclass.wfjydl.com\/?p=6777"},"modified":"2022-09-09T17:31:44","modified_gmt":"2022-09-09T09:31:44","slug":"%e6%99%ba%e8%83%bd%e6%9c%ba%e5%99%a8%e4%ba%ba%e6%89%8b%e8%87%82-%e7%ac%ac2%e9%83%a8%e5%88%86%ef%bc%9a%e7%bc%96%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/techclass.wfjydl.com\/knowledge\/deviceplus\/how-tos\/arduino\/smart-robotic-arm-part-2-programming","title":{"rendered":"\u667a\u80fd\u673a\u5668\u4eba\u624b\u81c2\u2013\u7b2c2\u90e8\u5206\uff1a\u7f16\u7a0b"},"content":{"rendered":"<p><script type=\"text\/javascript\" src=\"https:\/\/ssl-cache.stream.ne.jp\/www50\/eqa194obdo\/jmc_pub\/jmc_swf\/player\/t3\/if.js\" charset=\"UTF-8\"><\/script><\/p>\n<div class=\"\u201cthe_content_wrapper\u201d\">\u8fd9\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8e<a href=\"https:\/\/www.deviceplus.com\/\">DevicePlus.com<\/a>\u82f1\u8bed\u7f51\u7ad9\u7684\u7ffb\u8bd1\u7a3f\u3002<a href=\"https:\/\/techclass.wfjydl.com\/knowledge\/deviceplus\/how-tos\/arduino\/smart-robotic-arm-part-1-mechanics-and-wiring\"><strong>\u70b9\u51fb\u6b64\u5904\u9605\u8bfb\u672c\u6587\u7684\u7b2c1\u90e8\u5206&gt;<\/strong><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6309\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/08\/image001-copy-1.jpg\" sizes=\"auto, (max-width: 695px) 100vw, 695px\" srcset=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/08\/image001-copy-1.jpg 695w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/08\/image001-copy-1-300x213.jpg 300w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/08\/image001-copy-1-205x146.jpg 205w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/08\/image001-copy-1-50x36.jpg 50w, https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/08\/image001-copy-1-106x75.jpg 106w\" alt=\"robotic arm\" width=\"695\" height=\"494\" \/><\/p>\n<p><script type=\"text\/javascript\"><br \/>\n\tjstream_t3.PlayerFactoryIF.create({<br \/>\n\tb:\"eqa194obdo.eq.webcdn.stream.ne.jp\/www50\/eqa194obdo\/jmc_pub\/jmc_swf\/player\/\",<br \/>\n\tc:\"NDc3\",<br \/>\n\tm:\"NDI5\",<br \/>\n\ts:{<br \/>\n\t\thp:360,<br \/>\n\t\til:\"off\",<br \/>\n\t\trb:\"off\",<br \/>\n\t\tsn:\"f,t,g\",<br \/>\n\t\twp:640<br \/>\n\t}});<br \/>\n<\/script><\/p>\n<p>\u5728<a href=\"https:\/\/techclass.wfjydl.com\/knowledge\/deviceplus\/how-tos\/arduino\/smart-robotic-arm-part-1-mechanics-and-wiring\"><strong>\u667a\u80fd\u673a\u5668\u4eba\u624b\u81c2\u2013\u7b2c1\u90e8\u5206\uff1a\u673a\u68b0\u7ed3\u6784\u548c\u63a5\u7ebf<\/strong><\/a>\u4e2d\uff0c\u6211\u4eec\u5df2\u7ecf\u5c06\u673a\u68b0\u624b\u81c2\u7684\u672c\u4f53\u7ec4\u88c5\u5728\u4e00\u8d77\u3002\u673a\u68b0\u624b\u81c2\u642d\u8f7d\u4e86\u4e00\u4e2a\u7f51\u7edc\u6444\u50cf\u5934\u548c\u4e00\u4e2a\u9ea6\u514b\u98ce\uff0c\u4ee5\u8fdb\u884c\u4eba\u8138\u548c\u7269\u4f53\u8bc6\u522b\u4ee5\u53ca\u8bed\u97f3\u8bc6\u522b\u3002\u8fd9\u6b3e\u5728\u77ed\u77ed15\u5c0f\u65f6\u5185\u5f00\u53d1\u51fa\u6765\u7684\u673a\u5668\u4eba\u624b\u81c2\u5728MakeMIT\u786c\u4ef6\u9a6c\u62c9\u677e\u9879\u76ee\u4e2d\u6392\u540d\u524d10\u3002<\/p>\n<p>\u8be5\u673a\u5668\u4eba\u624b\u81c2\u7684\u4e3b\u8981\u529f\u80fd\u662f\u7ed3\u5408\u8bed\u97f3\u547d\u4ee4\u68c0\u6d4b\u5f69\u8272\u7269\u4f53\uff08\u4f8b\u5982\u7ea2\u7403\u6216\u84dd\u7403\uff09\u3001\u62fe\u53d6\u7269\u4f53\u3001\u8fdb\u884c\u4eba\u8138\u8bc6\u522b\uff0c\u5e76\u5c06\u7269\u4f53\u79fb\u4ea4\u7ed9\u6307\u5b9a\u7684\u4eba\u7269\/\u7528\u6237\u3002\u4e3a\u4e86\u6210\u529f\u5b9e\u73b0\u8fd9\u4e9b\u529f\u80fd\uff0c\u6211\u4eec\u96c6\u6210\u4e86\u591a\u4e2a\u5e73\u53f0\uff0c\u6bd4\u5982OpenCV\u3001Microsoft Cognitive Services Speech\u3001Speaker Recognition API\u4ee5\u53caOpen Weather API\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u786c\u4ef6<\/strong><\/p>\n<p>\u6839\u636e<a href=\"https:\/\/techclass.wfjydl.com\/knowledge\/deviceplus\/how-tos\/arduino\/smart-robotic-arm-part-1-mechanics-and-wiring\">\u7b2c1\u90e8\u5206<\/a>\uff1a<\/p>\n<ul>\n<li>Arduino Uno<\/li>\n<li>\u9ea6\u514b\u98ce<\/li>\n<li>\u7f51\u7edc\u6444\u50cf\u5934<\/li>\n<li>\u4f3a\u670d\u7535\u673a<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>\u8f6f\u4ef6<\/strong><\/p>\n<ul>\n<li>Arduino IDE<\/li>\n<li>Visual Studio<\/li>\n<li>JARVIS [<a href=\"https:\/\/github.com\/isacandrei\/Jarvis-Rocket\">https:\/\/github.com\/isacandrei\/Jarvis-Rocket<\/a>]<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2><b>\u7b2c1\u6b65\uff1a\u5236\u4f5cApp<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">\u6211\u4eec\u5df2\u7ecf\u8bbe\u6cd5\u6253\u9020\u4e86\u4e00\u4e2a\u80fd\u591f\u5904\u7406\u8bed\u97f3\u547d\u4ee4\u7684\u673a\u5668\u4eba\u624b\u81c2\u3002\u4eba\u4eec\u8bf4\u51fa\u8981\u6c42\u540e\uff0c\u8be5\u624b\u81c2\u4f1a\u627e\u5230\u76ee\u6807\u7269\u4f53\u5e76\u5c06\u5176\u4ea4\u7ed9\u6307\u5b9a\u4eba\u7269\uff08\u673a\u5668\u4eba\u53ef\u4ee5\u533a\u5206\u4e0d\u540c\u7684\u4eba\uff09\u3002\u6b64\u5916\uff0c\u5b83\u8fd8\u53ef\u4ee5\u64ad\u653e\u5728\u7ebf\u97f3\u4e50\u6216\u544a\u8bc9\u60a8\u5f53\u524d\u7684\u5929\u6c14\u60c5\u51b5\u3002 <\/span><\/p>\n<p>\u8be5\u5e94\u7528\u7a0b\u5e8f\u7684\u8f6f\u4ef6\u90e8\u5206\u7528Visual Studio 2015\u5b8c\u6210\u3002Visual Studio\u7b80\u5355\u6613\u7528\uff0c\u5e76\u4e14\u63d0\u4f9b\u4e86\u5f88\u591a\u529f\u80fd\u3002\u5176\u4e2d\u4e00\u4e2a\u529f\u80fd\u5c31\u662fEmgu CV\u2014\u2014\u4e00\u4e2a\u7528\u4e8e\u8c03\u7528OpenCv\u51fd\u6570\u7684\u5305\u88f9\u51fd\u6570\u5e93\u3002\u6b64\u529f\u80fd\u901a\u8fc7Visual Studio Windows Forms\u5b9e\u73b0\uff0c\u5728\u5904\u7406\u56fe\u50cf\u65f6\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<p><span style=\"font-weight: 400;\">\u5982\u679c\u60f3\u542f\u52a8\u9879\u76ee\uff0c\u60a8\u53ea\u9700\u5728\u7535\u8111\u4e0a\u5b89\u88c5Emgu CV\u5373\u53ef\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b:<\/span><\/p>\n<p><b>1. \u4e0b\u8f7d<strong>EmguCV<\/strong><br \/>\n<\/b><span style=\"font-weight: 400;\">\u60a8\u53ef\u4ee5\u70b9\u51fb<a href=\"https:\/\/www.emgu.com\/wiki\/index.php\/Download_And_Installation\">\u672c\u9875<\/a> <strong>\u201c\u6784\u5efa\u793a\u4f8b\u201d<\/strong>\u4e0b\u65b9\u7684\u8d85\u94fe\u63a5\u4e0b\u8f7dEmgu CV\u5de5\u7a0b:<\/span><\/p>\n<div id=\"attachment_6310\" style=\"width: 710px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6310\" class=\"size-full wp-image-6310\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/08\/image005-copy.jpg\" alt=\"robotic arm\" width=\"700\" height=\"138\" \/><p id=\"caption-attachment-6310\" class=\"wp-caption-text\">\u56fe1: \u5982\u4f55\u4e0b\u8f7dEmguCV<\/p><\/div>\n<p><b>2. <strong>\u6dfb\u52a0\u6587\u4ef6<\/strong><br \/>\n<\/b>\u7531\u4e8e\u60a8\u9700\u8981\u4f7f\u7528\u6dfb\u52a0\u5e93\uff0c\u56e0\u6b64\u5e94\u5c06\u5b83\u4eec\u5305\u542b\u5728Visual Studio\u4e2d\u3002OpenCV\u57fa\u4e8eC\/C++\u8bed\u8a00\u5f00\u53d1\uff0c\u5982\u679c\u60a8\u60f3\u5728C\uff03\u4e2d\u4f7f\u7528\uff0c\u90a3\u4e48\u9700\u8981\u6dfb\u52a0DLL\uff08\u52a8\u6001\u94fe\u63a5\u5e93\uff09\u6587\u4ef6\u2014\u2014\u5904\u7406\u89c6\u9891\u65f6\u5fc5\u987b\u5305\u542bDLL\u6587\u4ef6\u3002\u53c2\u8003\u6587\u4ef6\u4f4d\u4e8eVisual Studio\u83dc\u5355\u7684<strong>Solution Explorer<\/strong>\u5904<span style=\"font-weight: 400;\">. <\/span><\/p>\n<div id=\"attachment_6311\" style=\"width: 710px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6311\" class=\"size-full wp-image-6311\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/08\/image007-copy-1.jpg\" alt=\"robotic arm\" width=\"700\" height=\"253\" \/><p id=\"caption-attachment-6311\" class=\"wp-caption-text\">\u56fe2: \u53c2\u8003\u6587\u4ef6\u4f4d\u7f6e<\/p><\/div>\n<p><span style=\"font-weight: 400;\">\u5982\u679c\u60a8\u60f3\u6dfb\u52a0\u66f4\u591a\u6587\u4ef6\uff0c\u8bf7\u70b9\u51fb<strong>References -&gt; Add references<\/strong>\uff0c\u7136\u540e\u4ece\u4e0b\u8f7d\u7684\u6587\u4ef6\u4e2d\u9009\u62e9\u4ee5\u4e0b\u5185\u5bb9:<\/span><\/p>\n<div id=\"attachment_6312\" style=\"width: 710px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6312\" class=\"size-full wp-image-6312\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/08\/image009-copy-1.jpg\" alt=\"robotic arm\" width=\"700\" height=\"373\" \/><p id=\"caption-attachment-6312\" class=\"wp-caption-text\">\u56fe3: \u53c2\u8003\u7ba1\u7406\u5668\uff08Reference Manager\uff09<\/p><\/div>\n<p>\u66f4\u591a\u4fe1\u606f\u53ef\u4ee5\u53c2\u8003\u4ee5\u4e0b\u94fe\u63a5\uff1a<a href=\"https:\/\/www.emgu.com\/wiki\/index.php\/Setting_up_EMGU_C_Sharp\">https:\/\/www.emgu.com\/wiki\/index.php\/Setting_up_EMGU_C_Sharp<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><b>3. <strong>\u793a\u4f8b<\/strong><br \/>\n<\/b><\/p>\n<p><span style=\"font-weight: 400;\">\u5728\u4e0b\u8f7d\u7684\u5e93\u4e2d\uff0c\u60a8\u53ef\u4ee5\u627e\u5230\u66f4\u591a\u4f7f\u7528\u89c6\u9891\u5904\u7406\uff08\u8fd0\u52a8\u68c0\u6d4b\u3001\u4eba\u8138\u68c0\u6d4b\u548c\u6444\u50cf\u5934\u6355\u6349\uff09\u7684\u7a0b\u5e8f\u4ee3\u7801\u793a\u4f8b.<\/span><\/p>\n<div id=\"attachment_6313\" style=\"width: 710px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6313\" class=\"size-full wp-image-6313\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/08\/image011-copy.jpg\" alt=\"robotic arm\" width=\"700\" height=\"374\" \/><p id=\"caption-attachment-6313\" class=\"wp-caption-text\">\u56fe4: OpenCV\u5e94\u7528\u793a\u4f8b<\/p><\/div>\n<p><b>4. <strong>Arduino\u7a0b\u5e8f<\/strong><br \/>\n<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Arduino\u4ee3\u7801\u5177\u67094\u4e2a\u547d\u4ee4\uff1a<strong>up\/down<\/strong>\u8d1f\u8d23\u63a7\u5236\u4f3a\u670d\u7535\u673a\uff1b<strong>reset<\/strong>\u662f\u6307\u5728\u51fa\u73b0\u95ee\u9898\u65f6\u91cd\u7f6e\u673a\u5668\u4eba\u624b\u81c2\u4f4d\u7f6e\uff1b\u67d0\u4e2a\u90e8\u4ef6\u6ca1\u6709\u52a8\u4f5c\u65f6\u5219\u4f7f\u7528<strong>do nothing<\/strong>\u3002\u7a0b\u5e8f\u5177\u6709\u56db\u4e2a\u81ea\u7531\u5ea6:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">circle \u2013 \u624b\u81c2\u53ef\u4ee5\u65cb\u8f6c;<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">base \u2013 \u8c03\u6574\u7f51\u7edc\u6444\u50cf\u5934\u7684\u503e\u659c\u5ea6;<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">elbow\u2013 \u65e8\u5728\u83b7\u53d6\u624b\u81c2\u7684\u6700\u4f73\u4f4d\u7f6e;<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">wrist \u2013 \u8c03\u6574\u6293\u63e1\u529b.<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u6bcf\u4e2a\u4f3a\u670d\u7535\u673a\u90fd\u6709\u4e00\u4e2a\u7ed9\u5b9a\u547d\u4ee4\uff0c\u5e76\u4e14\u4f7f\u7528\u4e0d\u540c\u5f15\u811a\u8fdb\u884c\u63a7\u5236\uff1aElbow\u4f7f\u7528\u5f15\u811a7\uff1bBase\u4f7f\u7528\u5f15\u811a8\uff1bCircle\u4f7f\u7528\u5f15\u811a9\uff1bWrist\u4f7f\u7528\u5f15\u811a10\u3002\u5bf9\u4e8e\u4f3a\u670d\u7535\u673a\u63a7\u5236\uff0cC\uff03\u5e94\u7528\u7a0b\u5e8f\u901a\u8fc7\u4e32\u884c\u4f20\u8f93\u53d1\u90014\u4e2a\u5b57\u6bcd\uff0c\u6bcf\u4e2a\u72b6\u6001\u5bf9\u5e94\u4e8e\u4e00\u4e2a\u5177\u4f53\u7684<strong>\u7535\u673a\u63a7\u5236<\/strong>\u6307\u4ee4:<\/span><\/p>\n<p style=\"color: white; background-color: black; padding-left: 30px;\"><i><span style=\"font-weight: 400;\">if(cmd == &#8216;A&#8217;) state = 1;<\/span><\/i> <span style=\"font-weight: 400;\">\u2192<\/span><i><span style=\"font-weight: 400;\"> control(1, posCircle);<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">if(cmd == &#8216;B&#8217;) state = 2; <\/span><\/i><span style=\"font-weight: 400;\">\u2192<\/span><i><span style=\"font-weight: 400;\">control(2, posBase);<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">if(cmd == &#8216;C&#8217;) state = 3; <\/span><\/i><span style=\"font-weight: 400;\">\u2192<\/span><i><span style=\"font-weight: 400;\"> control(3, posElbow);<br \/>\n<\/span><\/i><i><span style=\"font-weight: 400;\">if(cmd == &#8216;D&#8217;) state = 4; <\/span><\/i><span style=\"font-weight: 400;\">\u2192<\/span><i><span style=\"font-weight: 400;\">control(4, posGH);<\/span><\/i><\/p>\n<p>\u6839\u636e\u4f3a\u670d\u7535\u673a\u7684\u8fd0\u52a8\u89d2\u5ea6\uff0c\u4ee3\u7801\u5206\u4e3a\u63a7\u5236\u548c\u547d\u4ee4\u6307\u4ee4\u3002<\/p>\n<p>\u5728<strong>Case 1<\/strong>\u4e2d\uff0cCircle\uff08\u65cb\u8f6c\uff09\u8fd0\u52a8\u7684\u547d\u4ee4\u4e3a<strong>left\/right\uff08\u5de6\/\u53f3\uff09\u3002<\/strong><\/p>\n<p><b>Case 1:<\/b><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>      switch (cmd)\r\n      {\r\n          case '0':\r\n              Left();\r\n              Break;\r\n          case '1':\r\n               \/\/do nothing\r\n              break;\r\n          case '2':\r\n              Right();\r\n              break;\r\n          case '3':\r\n              posCircle = 0;\r\n              break;\r\n      }\r\n      state = 0;\r\n      break;\r\n<\/code><\/pre>\n<\/div>\n<p><b>\u5728<strong>Case 2\u548cCase 3<\/strong>\u4e2d\uff0c\u6211\u4eec\u8003\u8651\u57fa\u5ea7\u548c\u8098\u90e8\u7684\u4f3a\u670d\u7535\u673a\uff0c\u8fd9\u610f\u5473\u7740\u4ed6\u4eec\u53ef\u4ee5<strong>\u4e0a\/\u4e0b\uff08up\/down\uff09<\/strong>\u5f15\u5bfc\u624b\u81c2\uff1b\u9047\u5230\u9519\u8bef\u65f6\uff0c\u673a\u5668\u4eba\u624b\u81c2\u4f1a\u628a\u81ea\u5df1\u8bbe\u7f6e\u4e3a<strong>posBase = 50\uff1b<\/strong>\u6216<strong>posElbow = 50<\/strong>;<\/b><\/p>\n<p><b>Case 2:<\/b><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>      switch (cmd)\r\n      {\r\n          case '0':\r\n              downBase();\r\n              break;\r\n\t\t\t  \r\n          case '1':\r\n              \/\/do nothing\r\n              break;\r\n\t\t\t  \r\n          case '2':\r\n              upBase();\r\n              break;\r\n\t\t\t  \r\n          case '3':\r\n              posBase = 50;\r\n              break;\r\n      }\r\n      state = 0;\r\n      break;\r\n<\/code><\/pre>\n<\/div>\n<p><b>Case 3:<\/b><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>      switch (cmd)\r\n      {\r\n          case '0':\r\n              downElbow();\r\n              break;\r\n\t\t\t  \r\n          case '1':\r\n              \/\/do nothing\r\n              break;\r\n\t\t\t  \r\n          case '2':\r\n              upElbow();\r\n              break;\r\n\t\t\t  \r\n          case '3':\r\n              posElbow = 50;\r\n              break;\r\n\t\t\t  \r\n          case '4':\r\n              posElbow = 10;\r\n              break;\r\n      }\r\n      state = 0;\r\n      break;\r\n<\/code><\/pre>\n<\/div>\n<p><b>\u5728<strong>Case 4<\/strong>\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u63a7\u5236\u722a\u94b3\uff0c\u8fd9\u4e2a\u975e\u5e38\u7b80\u5355\u2014\u2014\u5c06\u5176\u521d\u59cb\u4f4d\u7f6e\u8bbe\u7f6e\u4e3a<strong>posGH = 50<\/strong>;<\/b><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u8bf7\u5c06\u4ee5\u4e0b\u4ee3\u7801\u6dfb\u52a0\u5230Arduino UNO\u4e2d\uff0c\u4ee5\u8fdb\u884c\u673a\u5668\u4eba\u624b\u81c2\u63a7\u5236:<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>\/\/ States for the RoboticArm:\r\n\/\/0 Down on the left\r\n\/\/1 Pause\r\n\/\/2 Top on the right\r\n\/\/3 Reset\r\n\r\n\r\n#include &lt;Servo.h&gt;\r\n\r\nServo Circle; \/\/1\r\nServo Base; \/\/2\r\nServo Elbow;  \/\/3\r\nServo Wrist; \/\/4\r\n\r\nint posCircle = 0;\r\nint posBase = 50;\r\nint posElbow = 50;\r\nint posGH = 50;\r\n\r\nint state = 0;\r\n\r\nvoid setup() {\r\n  Serial.begin(9600);\r\n  Elbow.attach(7);\r\n  Base.attach(8);\r\n  Circle.attach(9);\r\n  Wrist.attach(10);\r\n  delay(1000);\r\n  control(1, posCircle);\r\n  control(2, posBase);\r\n  control(3, posElbow);\r\n  control(4, posGH);\r\n}\r\n\r\nvoid loop() \r\n{\r\n\r\nif(Serial.available() &gt; 0)\r\n{\r\nchar cmd = Serial.read();\r\n\r\nswitch (state) {\r\n    case 0:\r\n     if(cmd == 'A') state = 1;\r\n     if(cmd == 'B') state = 2;\r\n     if(cmd == 'C') state = 3;\r\n     if(cmd == 'D') state = 4;\r\n    \r\n      break;\r\n      \r\n    case 1:\r\n            \r\n             switch (cmd)\r\n             {\r\n              case '0':\r\n              Left();\r\n              break;\r\n\t\t\t  \r\n              case '1':\r\n              \/\/do nothing\r\n              break;\r\n\t\t\t  \r\n              case '2':\r\n              Right();\r\n              break;\r\n\t\t\t  \r\n              case '3':\r\n              posCircle = 0;\r\n              break;\r\n             }\r\n             state = 0;\r\n      break;\r\n      \r\n      case 2:\r\n            \r\n             switch (cmd)\r\n             {\r\n              case '0':\r\n              downBase();\r\n              break;\r\n\t\t\t  \r\n              case '1':\r\n              \/\/do nothing\r\n              break;\r\n\t\t\t  \r\n              case '2':\r\n              upBase();\r\n              break;\r\n\t\t\t  \r\n              case '3':\r\n              posBase = 50;\r\n              break;\r\n             }\r\n             state = 0;\r\n      break;\r\n      \r\n      case 3:\r\n       \r\n             switch (cmd)\r\n             {\r\n              case '0':\r\n              downElbow();\r\n              break;\r\n\t\t\t  \r\n              case '1':\r\n              \/\/do nothing\r\n              break;\r\n\t\t\t  \r\n              case '2':\r\n              upElbow();\r\n              break;\r\n\t\t\t  \r\n              case '3':\r\n              posElbow = 50;\r\n              break;\r\n\t\t\t  \r\n              case '4':\r\n              posElbow = 10;\r\n              break;\r\n             }\r\n             state = 0;\r\n      break;\r\n      \r\n      case 4:\r\n          \r\n             switch (cmd)\r\n             {\r\n              case '0':\r\n              break;\r\n\t\t\t  \r\n              case '1':\r\n              break;\r\n\t\t\t  \r\n              case '2':\r\n              break;\r\n\t\t\t  \r\n              case '3':\r\n              posGH = 50;\r\n              break;\r\n             }\r\n             state = 0;\r\n      break;\r\n   \r\n  }\r\n  \r\n}\r\n       \r\n}\r\n\r\nvoid control(int motor, int angle)\r\n{\r\nswitch (motor) {\r\n    case 1:\r\n    if(angle &gt;= 0) if(angle &lt;= 140) Circle.write(angle + 10);                         \r\n    break;\r\n    \r\n    case 2:\r\n    if(angle &gt;= 0) if(angle &lt;= 60) Base.write(140 - angle);\r\n    break;\r\n\r\n    case 3:\r\n    if(angle &gt;= 0) if(angle &lt;= 70) Elbow.write(80 - angle);\r\n    break;\r\n\r\n    case 4:\r\n    if(angle &gt;= 0) if(angle &lt;= 65) Wrist.write(75 - angle);\r\n    break; \r\n  }  \r\n}\r\n\r\nvoid Left()\r\n{\r\nif(posCircle &lt;= 136)\r\n{\r\n  posCircle = posCircle + 4;\r\n}\r\nelse posCircle = 140;\r\ncontrol(1, posCircle);\r\n}\r\n\r\nvoid Right()\r\n{\r\nif(posCircle &gt;= 4)\r\n{\r\n  posCircle = posCircle - 4;\r\n}\r\nelse posCircle = 0;\r\ncontrol(1, posCircle);\r\n}\r\n\r\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\nvoid downElbow()\r\n{\r\nif(posElbow &gt;= 4)\r\n{\r\n  posElbow = posElbow - 4;\r\n}\r\nelse posElbow = 0;\r\ncontrol(3, posElbow);\r\n}\r\n\r\nvoid upElbow()\r\n{\r\nif(posElbow &lt;= 66)\r\n{\r\n  posElbow = posElbow + 4;\r\n}\r\nelse posElbow = 70;\r\ncontrol(3, posElbow);\r\n}\r\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\nvoid downBase()\r\n{\r\nif(posBase &gt;= 4)\r\n{\r\n  posBase = posBase - 4;\r\n}\r\nelse posBase = 0;\r\ncontrol(2, posBase);\r\n}\r\n\r\nvoid upBase()\r\n{\r\nif(posBase &lt;= 56)\r\n{\r\n  posBase = posBase + 4;\r\n}\r\nelse posBase = 60;\r\ncontrol(2, posBase);\r\n}\r\n<\/code><\/pre>\n<\/div>\n<h2><b>\u7b2c2\u6b65\uff1a\u5982\u4f55\u5236\u4f5c\u6f14\u793aApp<\/b><\/h2>\n<p>\u4e3a\u4e86\u5236\u4f5c\u4e00\u4e2a\u7c7b\u4f3c\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u6211\u4eec\u9700\u8981\u77e5\u9053\u5982\u4f55\u4f7f\u7528C\uff03\u7f16\u5199\u5e94\u7528\u7a0b\u5e8f\u3002\u7531\u4e8eWindows Forms App\u5f88\u7b80\u5355\uff0c\u5e76\u4e14\u62e5\u6709\u5728\u7ebf\u6587\u6863\uff0c\u9700\u8981\u65f6\u53ef\u4ee5\u968f\u65f6\u83b7\u53d6\uff0c\u56e0\u6b64\u6211\u4eec\u91c7\u7528\u4e86\u8be5App\u3002\u5bf9\u4e8e\u8fd9\u4e2a\u9879\u76ee\uff0c\u6211\u4eec\u9700\u8981Visual Studio\u548c.NET framework\uff08\u60a8\u53ef\u4ee5\u5728<a href=\"https:\/\/www.visualstudio.com\/downloads\/\">\u8fd9\u91cc<\/a>\u4e0b\u8f7d\u8fd9\u4e24\u4e2a\u7a0b\u5e8f\uff09\u3002\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6587\u4ef6\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5f00\u59cb\u5236\u4f5c\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u5de5\u7a0b\u3002\u521b\u5efa\u65b0\u5de5\u7a0b\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a\u70b9\u51fb<strong>File<\/strong>\u2192<strong>New<\/strong>\u2192<strong>Project<\/strong>\u548c<strong>Windows Forms App(.NET Framework)\u3002<\/strong><\/p>\n<div id=\"attachment_6314\" style=\"width: 710px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6314\" class=\"size-full wp-image-6314\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/08\/image019-copy.jpg\" alt=\"robotic arm\" width=\"700\" height=\"375\" \/><p id=\"caption-attachment-6314\" class=\"wp-caption-text\">\u56fe5: \u5982\u4f55\u5728Visual Studio\u4e2d\u5236\u4f5cApp<\/p><\/div>\n<p>\u6b64\u65f6\u7cfb\u7edf\u4f1a\u663e\u793a\u4e00\u4e2a\u5e26\u6709\u7a97\u4f53\u7684\u7a97\u53e3\u2014\u2014\u8fd9\u662f\u5e94\u7528\u7a0b\u5e8f\u81ea\u52a8\u751f\u6210\u7684\u683c\u5f0f\u3002\u53f3\u4fa7\uff08<strong>Properties<\/strong>\uff09\u662f\u8868\u683c\u5c5e\u6027\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u504f\u597d\u8fdb\u884c\u8c03\u6574\u3002\u5de6\u4fa7\uff08<strong>Toolbox<\/strong>\uff09\u63d0\u4f9b\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528\u7684\u529f\u80fd\uff0c\u6bd4\u5982\u6309\u94ae\u3001\u590d\u9009\u6846\u3001\u4e32\u53e3\u7b49\u3002<\/p>\n<div id=\"attachment_6315\" style=\"width: 710px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6315\" class=\"size-full wp-image-6315\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/08\/image021-copy.jpg\" alt=\"robotic arm\" width=\"700\" height=\"376\" \/><p id=\"caption-attachment-6315\" class=\"wp-caption-text\">\u56fe6: Visual Studio\u4e2d\u7684App\u5c5e\u6027<\/p><\/div>\n<p>\u5bf9\u4e8e\u6d4b\u8bd5\u6f14\u793a\uff0c\u6211\u4eec\u53ef\u4ee5\u5236\u4f5c\u8fd9\u6837\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff1a\u70b9\u51fb\u6309\u94ae\uff0c\u7cfb\u7edf\u663e\u793a\u4e00\u6761\u6587\u672c\u4fe1\u606f\u3002<\/p>\n<p><span style=\"font-weight: 400;\">\u53cc\u51fb<strong>Toolbox\uff08\u5de5\u5177\u7bb1\uff09<\/strong>\u4e2d\u7684\u6309\u94ae\uff0c\u7a0b\u5e8f\u4f1a\u5728\u5de6\u4e0a\u89d2\u81ea\u52a8\u6dfb\u52a0\u4e00\u4e2a\u6309\u94ae\u3002\u8be5\u6309\u94ae\u4f1a\u88ab\u547d\u540d\u4e3a\u201cbutton1\u201d\uff0c\u56e0\u4e3a.NET Framework\u4f1a\u5bf9\u6309\u94ae\u7c7b\u5b9e\u4f8b\u8fdb\u884c\u81ea\u52a8\u7f16\u53f7\u3002\u5728button1\u5c5e\u6027\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06<strong>Text<\/strong>\u4ecebutton1\u6539\u4e3a<strong>Click here<\/strong>\uff01\u73b0\u5728\uff0c\u6211\u4eec\u9700\u8981\u7f16\u5199\u4ee3\u7801\uff0c\u4ee5\u4fbf\u8ba9\u6309\u94ae\u8d77\u4f5c\u7528\uff08\u53cc\u51fb\u56fe\u5f62\u754c\u9762\u4e0a\u7684\u6309\u94ae\uff09: <\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-c\" data-lang=\"C\"><code>namespace WindowsFormsApp3\r\n{\r\n    public partial class Form1 : Form\r\n    {\r\n        public Form1()\r\n        {\r\n            InitializeComponent();\r\n        }\r\n\r\n        private void button1_Click(object sender, EventArgs e)\r\n        {\r\n            MessageBox.Show(\"App made for DevicePlus\");\r\n        }\r\n    }\r\n}\r\n<\/code><\/pre>\n<\/div>\n<p>\u5f53\u7528\u6237\u70b9\u51fb\u8be5\u6309\u94ae\u65f6\uff0c\u4e0a\u8ff0\u4ee3\u7801\u4f1a\u663e\u793a\u4e00\u4e2a\u6587\u672c\u3002\u5177\u4f53\u7ed3\u679c\u5982\u56fe7\u6240\u793a\u3002<\/p>\n<div id=\"attachment_6316\" style=\"width: 710px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6316\" class=\"size-full wp-image-6316\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/08\/image023-copy.jpg\" alt=\"robotic arm\" width=\"700\" height=\"464\" \/><p id=\"caption-attachment-6316\" class=\"wp-caption-text\">\u56fe7: \u6f14\u793aApp<\/p><\/div>\n<h2><b>\u7b2c3\u6b65\uff1aApp\u5c5e\u6027<\/b><\/h2>\n<p>\u51ed\u501f.NET\u3001OpenCV\u548cMicrosoft API\u7684\u529f\u80fd\uff0c\u6211\u4eec\u80fd\u591f\u5236\u4f5c\u51fa\u5b8c\u6574\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u5bf9\u4e8e\u8be5\u5e94\u7528\u7a0b\u5e8f\uff0c\u6211\u4eec\u9700\u8981\u6309\u94ae\u3001\u4e32\u53e3\u548c\u6587\u672c\u6846\u3002<\/p>\n<p>\u9ed1\u8272\u7a97\u53e3\u4f1a\u663e\u793a\u6765\u81ea\u6444\u50cf\u5934\u7684\u56fe\u50cf\uff0c\u7a97\u53e3\u4e2d\u8fd8\u4f1a\u6dfb\u52a0\u4e00\u4e2a\u955c\u5934\u6846\uff0c\u6846\u5185\u663e\u793a\u4eba\u7269\u540d\u79f0\u3002<\/p>\n<p>\u5de6\u4fa7\u7684\u767d\u8272\u7a97\u53e3\u53ef\u4ee5\u6dfb\u52a0TTS API\uff08\u6587\u672c\u8f6c\u8bed\u97f3\uff09\u7684\u6587\u672c\uff0c\u63d0\u4f9b\u53cd\u9988\u4ee5\u68c0\u67e5\u5de5\u4f5c\uff0c\u5e76\u68c0\u67e5\u8bf4\u51fa\u7684\u8bdd\u8bed\u662f\u5426\u4e0e\u663e\u793a\u7684\u5b57\u8bcd\u76f8\u7b26\u3002<\/p>\n<div id=\"attachment_6317\" style=\"width: 710px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6317\" class=\"size-full wp-image-6317\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/08\/image025-copy.jpg\" alt=\"robotic arm\" width=\"700\" height=\"484\" \/><p id=\"caption-attachment-6317\" class=\"wp-caption-text\">\u56fe8: \u673a\u5668\u4eba\u624b\u81c2\u5e94\u7528\u7a0b\u5e8f<\/p><\/div>\n<h2><b>\u7b2c4\u6b65\uff1a\u4eba\u8138\u8bc6\u522b<\/b><\/h2>\n<p>\u4e3a\u4e86\u83b7\u5f97\u66f4\u597d\u7684\u7a0b\u5e8f\u7ed3\u679c\uff0c\u60a8\u9700\u8981\u5728\u8bad\u7ec3\u6a21\u5f0f\u4e0b\u6dfb\u52a0\u591a\u4e2a\u8138\u90e8\u8bb0\u5f55\u3002\u8bad\u7ec3\u662f\u6307\u901a\u8fc7\u62cd\u6444\u591a\u4e2a\u8138\u90e8\u4f4d\u7f6e\u4ee5\u83b7\u5f97\u6700\u4f73\u8bc6\u522b\uff08\u4e0d\u540c\u62cd\u6444\u89d2\u5ea6\u3001\u5149\u7ebf\u6761\u4ef6\u7b49\uff09\u3002\u60a8\u9700\u8981\u6309\u4e0b<strong>Record 10 Faces<\/strong>\u6309\u94ae\uff0c\u901a\u8fc7\u5e94\u7528\u7a0b\u5e8f\u8bb0\u5f55\u8138\u90e8\u753b\u9762\u3002<\/p>\n<p>\u5728\u4ee3\u7801\u4e2d\uff0c\u5b9e\u73b0\u8fd9\u4e2a\u529f\u80fd\u7684\u8bed\u53e5\u4e3a<strong>Face = Parent.faceClassifier\uff1b<\/strong>\u8fd9\u901a\u8fc7EmguCV\u5e73\u53f0\u5b8c\u6210\u3002\u4eba\u8138\u68c0\u6d4b\u901a\u8fc7\u57fa\u4e8e\u4e3b\u6210\u5206\u5206\u6790\uff08PCA\uff09\u7684\u590d\u6742\u7b97\u6cd5\u5b9e\u73b0\uff0c\u7cfb\u7edf\u4f1a\u5c06\u68c0\u6d4b\u5230\u7684\u8138\u90e8\u4e0e\u8bad\u7ec3\u540e\u5b58\u50a8\u7684\u56fe\u50cf\u8fdb\u884c\u591a\u6b21\u6bd4\u8f83\u3002<\/p>\n<div id=\"attachment_6318\" style=\"width: 710px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6318\" class=\"size-full wp-image-6318\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/08\/image027.jpg\" alt=\"robotic arm\" width=\"700\" height=\"394\" \/><p id=\"caption-attachment-6318\" class=\"wp-caption-text\">\u56fe9: \u4eba\u8138\u68c0\u6d4b<\/p><\/div>\n<p>\u84dd\u8272\u77e9\u5f62\u4e2d\u7684\u56fe\u50cf\u662f\u9700\u8981\u5b58\u50a8\u7684\u56fe\u50cf\uff0c\u56e0\u4e3a\u5b83\u5305\u542b\u9762\u90e8\u7684\u72ec\u7279\u7279\u5f81\u3002<\/p>\n<p>\u6211\u4eec\u9700\u8981\u5728\u4e0d\u540c\u7684\u4f4d\u7f6e\u548c\u4e0d\u540c\u7684\u5149\u7ebf\u4e0b\u83b7\u53d6\u66f4\u591a\u7684\u9762\u90e8\u7279\u5f81<span style=\"font-weight: 400;\">:<\/span><\/p>\n<div id=\"attachment_6319\" style=\"width: 1049px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6319\" class=\"size-full wp-image-6319\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/08\/image029.jpg\" alt=\"robotic arm\" width=\"1039\" height=\"540\" \/><p id=\"caption-attachment-6319\" class=\"wp-caption-text\">\u56fe10: \u6dfb\u52a0\u66f4\u591a\u4eba\u8138\u8fdb\u884c\u8bad\u7ec3<\/p><\/div>\n<p>\u7ecf\u8fc7\u4e00\u7cfb\u5217\u9762\u90e8\u68c0\u6d4b\u62cd\u6444\uff0c\u5982\u679c\u60a8\u8ba4\u4e3a\u4e4b\u524d\u8bb0\u5f55\u7684\u8138\u90e8\u56fe\u50cf\u4e0d\u5229\u4e8e\u7b97\u6cd5\u8ba1\u7b97\uff0c\u90a3\u4e48\u53ef\u4ee5\u70b9\u51fb<strong>Restart 1 Face<\/strong>\u6309\u94ae\u5220\u9664\u5df2\u7ecf\u4fdd\u5b58\u7684\u6587\u4ef6\uff0c\u7cfb\u7edf\u5c06\u4e0d\u518d\u68c0\u6d4b\u8be5\u8138\u90e8\u4fe1\u606f\u3002<\/p>\n<p>\u5982\u679c\u8981\u8bb0\u5f55\u591a\u4e2a\u4eba\u3001\u8ba9\u673a\u5668\u4eba\u624b\u81c2\u53ef\u4ee5\u533a\u5206\u8bb8\u591a\u4e2a\u4eba\uff0c\u90a3\u4e48\u53ef\u4ee5\u4f7f\u7528<strong>Delete Data<\/strong>\u6309\u94ae\u5220\u9664\u7167\u7247\u3002<\/p>\n<div id=\"attachment_6320\" style=\"width: 710px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6320\" class=\"size-full wp-image-6320\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/08\/image031.jpg\" alt=\"robotic arm\" width=\"700\" height=\"363\" \/><p id=\"caption-attachment-6320\" class=\"wp-caption-text\">\u56fe11:\u91cd\u542f\u8bad\u7ec3\u6a21\u5f0f<\/p><\/div>\n<p><span style=\"font-weight: 400;\">\u5f55\u5236\u66f4\u591a\u56fe\u50cf\u540e\uff0c\u8be5\u7b97\u6cd5\u5e94\u8be5\u80fd\u591f\u68c0\u6d4b\u4eba\u8138\uff0c\u5e76\u5728\u84dd\u6846\u4e0a\u65b9\u663e\u793a\u540d\u79f0\u3002\u673a\u5668\u4eba\u53ef\u4ee5\u7cbe\u786e\u68c0\u6d4b\u50cf\u773c\u955c\u8fd9\u6837\u7684\u7279\u5f81\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u7279\u5f81\u5c5e\u4e8e\u533a\u522b\u6027\u7279\u5f81.<\/span><\/p>\n<div id=\"attachment_6321\" style=\"width: 710px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6321\" class=\"size-full wp-image-6321\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/08\/image033-copy.jpg\" alt=\"robotic arm\" width=\"700\" height=\"484\" \/><p id=\"caption-attachment-6321\" class=\"wp-caption-text\">\u56fe12: \u8bad\u7ec3\u4e4b\u540e\u7684\u7ed3\u679c<\/p><\/div>\n<h2><b>\u7b2c5\u6b65\uff1a\u5929\u6c14API<\/b><\/h2>\n<p>\u901a\u8fc7\u5929\u6c14API\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u4ee5\u4e0b\u65b9\u5f0f\u6536\u96c6\u57ce\u5e02\u6570\u636e\uff1a\u57ce\u5e02\u540d\u79f0\u3001\u57ce\u5e02ID\u3001\u5730\u7406\u5750\u6807\u751a\u81f3\u90ae\u653f\u7f16\u7801\u3002\u8be5API\u7684\u4f18\u70b9\u662f\u514d\u8d39\u4e14\u6613\u4e8e\u4f7f\u7528\u3002\u4f46\u662f\u8be5API\u6709\u4e00\u4e2a\u9650\u5236\uff1a<span style=\"color: red;\">\u4f7f\u7528\u6b21\u6570\u6216\u8005\u6d41\u91cf\u4e0d\u80fd\u8d85\u8fc760\u6b21\/\u5206\u949f\u621650k\/\u5929<\/span>\uff0c\u5982\u679c\u8fdd\u53cd\u8be5\u89c4\u5b9a\uff0c\u60a8\u7684\u5e10\u6237\u5c06\u88ab\u5c01\u9501\u3002<\/p>\n<p>\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u9009\u62e9\u6839\u636e\u57ce\u5e02ID\u8c03\u7528API\u3002\u6bcf\u4e2a\u57ce\u5e02\u90fd\u6709\u4e00\u4e2aID\uff0c\u8be6\u7ec6\u4fe1\u606f\u8bf7\u53c2\u89c1<a href=\"https:\/\/bulk.openweathermap.org\/sample\/city.list.json.gz\">https:\/\/bulk.openweathermap.org\/sample\/city.list.json.gz<\/a>\u3002\u6269\u5c55\u540d<strong>.json<\/strong>\u7528\u4e8e\u5728\u6d4f\u89c8\u5668\u548c\u670d\u52a1\u5668\u4e4b\u95f4\u8fdb\u884c\u4ea4\u6362\u6570\u636e\u3002\u53ea\u6709\u5f53\u6570\u636e\u662f\u6587\u672c\u683c\u5f0f\u65f6\u624d\u80fd\u5b9e\u73b0\u901a\u4fe1\u3002<\/p>\n<p>\u6211\u4eec\u5df2\u7ecf\u5c06\u6570\u636e\u7528\u4f5cWebClient\u7c7b\u2014\u2014\u8fd9\u4f7f\u5f97\u6587\u4ef6\u4e0b\u8f7d\u66f4\u52a0\u8f7b\u677e\u3002\u5728\u6211\u4eec\u7684\u4f8b\u5b50\u4e2d\uff0c\u6784\u9020\u51fd\u6570WebClient\u7528\u4e8e\u521d\u59cb\u5316\u4e00\u4e2a\u65b0\u7684\u5b9e\u4f8b<span style=\"font-weight: 400;\">:<\/span><\/p>\n<p><span style=\"color: #33cccc;\"><b>WebClient<\/b><\/span><b> client = <\/b><span style=\"color: #0000ff;\"><b>new<\/b><\/span> <span style=\"color: #33cccc;\"><b>WebClient<\/b><\/span><b>();<\/b><\/p>\n<p>\u6211\u4eec\u9700\u8981\u5c06\u6570\u636e\u7f16\u7801\u4e3aUTF8\u683c\u5f0f\uff0c\u8fd9\u610f\u5473\u7740\u7cfb\u7edf\u75288\u4f4d\u5757\u6765\u8868\u793a\u5b57\u7b26\uff0c\u5177\u4f53\u6307\u4ee4\u5982\u4e0b\uff1a<strong>client.Encoding = System.Text.<\/strong><strong>Encoding<\/strong><strong>.UTF8<\/strong><\/p>\n<p>\u5982\u679c\u4e92\u8054\u7f51\u8fde\u63a5\u51fa\u73b0\u95ee\u9898\uff0c\u65e0\u6cd5\u5efa\u7acb\u8fde\u63a5\u65f6\uff0c\u7a0b\u5e8f\u4f1a\u81ea\u52a8\u663e\u793a\u6d88\u606f\u201c<strong>Internet Connection failed<\/strong>\u2013<strong>throw new WeatherDataServiceException<\/strong>\u201d\u3002\u901a\u8fc7<strong>throw<\/strong>\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u5f02\u5e38\u3002<\/p>\n<p>\u5728C\uff03\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<strong>try<\/strong>\u548c<strong>catch<\/strong>\u6765\u89e3\u51b3\u90e8\u5206\u4ee3\u7801\u65e0\u6cd5\u6210\u529f\u7684\u60c5\u51b5\u3002<\/p>\n<p>\u7ed3\u5408\u6587\u672c\u8f6c\u8bed\u97f3API\uff0c\u5982\u679c\u7528\u6237\u8be2\u95ee\u5929\u6c14\u60c5\u51b5\uff0c\u7cfb\u7edf\u4f1a\u53d1\u51fa\u4ee5\u4e0b\u58f0\u97f3\uff1a\u201cThe weather in Boston is\uff08\u6ce2\u58eb\u987f\u7684\u5929\u6c14\u662f\uff09&#8230;\u201d\u3002<\/p>\n<h2><b>\u7b2c6\u6b65\uff1a\u8bed\u97f3\u5408\u6210<\/b><\/h2>\n<p>\u5f53\u60a8\u4f7f\u7528\u6587\u672c\u8f6c\u8bed\u97f3API\u65f6\uff0c\u60a8\u9700\u8981\u4e00\u4e2a\u53ef\u4ee5\u5feb\u901f\u5904\u7406\u7684\u6587\u4ef6\u2014\u2014\u8fd9\u5c31\u662f\u6211\u4eec\u9700\u8981\u4f7f\u7528\u670d\u52a1\u5668\u7684\u539f\u56e0\u3002\u5bf9\u4e8eBING API\uff0c\u6211\u4eec\u9700\u8981\u6388\u6743\u4ee4\u724c\uff0c\u5177\u4f53\u4fe1\u606f\u8bf7\u53c2\u9605<strong>https:\/\/api.cognitive.microsoft.com\/sts\/v1.0\/issueToken<\/strong>\u3002<\/p>\n<p>\u8be5API\u7684\u6709\u6548\u671f\u4e3a10\u5206\u949f\u3002\u8fd9\u662f\u4e00\u4e2a\u975e\u5e38\u68d2\u7684\u8ba1\u65f6\u5668\uff0c\u53ef\u4ee5\u8ba1\u6570\u52309\uff0c\u540c\u65f6\u6bcf9\u5206\u949f\u66f4\u65b0\u4e00\u6b21\u8fde\u63a5\u3002<\/p>\n<p>\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u60a8\u53ef\u4ee5\u770b\u5230\u8bed\u97f3\u5408\u6210\u7684\u6700\u7ec8\u7ed3\u679c\u662f\u201cTesting the app for Device Plus\u201d\u3002<\/p>\n<div id=\"attachment_6322\" style=\"width: 710px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6322\" class=\"size-full wp-image-6322\" src=\"https:\/\/techclass.wfjydl.com\/wp-content\/uploads\/2017\/08\/image035-copy.jpg\" alt=\"robotic arm\" width=\"700\" height=\"319\" \/><p id=\"caption-attachment-6322\" class=\"wp-caption-text\">\u56fe13: \u6d4b\u8bd5API<\/p><\/div>\n<p>\u603b\u4f53\u6765\u8bf4\uff0c\u8fd9\u662f\u4e00\u4e2a\u6709\u8da3\u7684\u9879\u76ee\u3002\u8be5\u9879\u76ee\u8ba9\u6211\u61c2\u5f97\u786c\u4ef6\u548c\u8f6f\u4ef6\u4e4b\u95f4\u7684\u826f\u597d\u540c\u6b65\u5bf9\u4e8e\u5b9e\u73b0\u6700\u4f73\u6027\u80fd\u81f3\u5173\u91cd\u8981\u3002\u4f7f\u7528Visual Studio\u7684\u5f88\u591a\u5e93\u4f7f\u9879\u76ee\u6709\u70b9\u590d\u6742\uff0c\u4f46\u6700\u7ec8\u7ed3\u679c\u4ee4\u4eba\u6ee1\u610f\u3002<\/p>\n<p>\u6211\u8ba4\u4e3a\u8fd9\u79cd\u9879\u76ee\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u8fdb\u884c\u5f00\u53d1\u548c\u6539\u8fdb\uff0c\u4ee5\u6ee1\u8db3\u6bcf\u4e2a\u7528\u6237\u7684\u9700\u6c42\u3002<\/p>\n<div class=\"author-box-wrapper\">\n<div class=\"avatar-wrapper\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/micro.wfjydl.com\/deviceplus\/wp-content\/uploads\/2019\/03\/Tiberia-Todeila_avatar_1496261149-64x64.jpg\" alt=\"DevicePlus \u7f16\u8f91\u56e2\u961f\" width=\"64\" height=\"64\" \/><\/div>\n<div class=\"desc-wrapper\">\n<h5>Tiberia Todeila<\/h5>\n<div class=\"desc\">\n<p>Tiberia\u76ee\u524d\u662f\u5e03\u52a0\u52d2\u65af\u7279\u7406\u5de5\u5927\u5b66\u7535\u6c14\u5de5\u7a0b\u5b66\u9662\u7684\u5927\u56db\u5b66\u751f\u3002\u5979\u975e\u5e38\u70ed\u8877\u4e8e\u667a\u80fd\u5bb6\u5c45\u8bbe\u5907\u7684\u8bbe\u8ba1\u548c\u5f00\u53d1\uff0c\u65e8\u5728\u8ba9\u6211\u4eec\u7684\u65e5\u5e38\u751f\u6d3b\u66f4\u52a0\u8f7b\u677e\u3002<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"\u8fd9\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8eDevicePlus.com\u82f1\u8bed\u7f51\u7ad9\u7684\u7ffb\u8bd1\u7a3f\u3002\u70b9\u51fb\u6b64\u5904\u9605\u8bfb\u672c\u6587\u7684\u7b2c1\u90e8\u5206&gt; &nbsp; \u5728\u667a\u80fd\u673a\u5668\u4eba\u624b\u81c2\u2013\u7b2c1\u90e8\u5206\uff1a\u673a\u68b0\u7ed3\u6784\u548c\u63a5\u7ebf\u4e2d\uff0c\u6211\u4eec\u5df2\u7ecf\u5c06\u673a\u68b0\u624b\u81c2\u7684\u672c\u4f53\u7ec4\u88c5\u5728\u4e00\u8d77\u3002\u673a\u68b0\u624b\u81c2\u642d\u8f7d\u4e86\u4e00\u4e2a\u7f51\u7edc\u6444\u50cf\u5934 [&hellip;]","protected":false},"author":3,"featured_media":20714,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1130],"tags":[],"class_list":["post-6777","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino"],"acf":[],"wps_subtitle":"","_links":{"self":[{"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/posts\/6777","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/comments?post=6777"}],"version-history":[{"count":17,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/posts\/6777\/revisions"}],"predecessor-version":[{"id":18363,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/posts\/6777\/revisions\/18363"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/media\/20714"}],"wp:attachment":[{"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/media?parent=6777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/categories?post=6777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techclass.wfjydl.com\/wp-json\/wp\/v2\/tags?post=6777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}