{"id":6914,"date":"2015-03-04T16:20:07","date_gmt":"2015-03-03T22:20:07","guid":{"rendered":"http:\/\/www.moonmile.net\/blog\/?p=6914"},"modified":"2015-03-04T16:21:09","modified_gmt":"2015-03-04T07:21:09","slug":"raspberry-pi-%e3%81%a7%e6%88%a6%e8%bb%8a%e3%82%92%e4%bd%9c%e3%82%8b%ef%bc%88%e3%83%aa%e3%83%a2%e3%82%b3%e3%83%b3%e7%b7%a8%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.moonmile.net\/blog\/archives\/6914","title":{"rendered":"Raspberry Pi \u3067\u6226\u8eca\u3092\u4f5c\u308b\uff08\u30ea\u30e2\u30b3\u30f3\u7de8\uff09"},"content":{"rendered":"<p>\n\u30b2\u30fc\u30e0\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3067\u6226\u8eca\u306e\u30e2\u30fc\u30bf\u30fc\u3092\u5236\u5fa1\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4ee5\u4e0b\u306e2\u3064\u3092\u304f\u3063\u3064\u3051\u307e\u3059\u3002\n<\/p>\n<p>\nRaspberry Pi \u3067\u6226\u8eca\u3092\u4f5c\u308b\uff08Bluetooth\/PS3 Dualshock3\u7de8\uff09<br \/>\n<a href=\"http:\/\/www.moonmile.net\/blog\/archives\/6898\">http:\/\/www.moonmile.net\/blog\/archives\/6898<\/a><br \/>\nRaspberry Pi \u3067\u6226\u8eca\u3092\u4f5c\u308b\uff08\u30e2\u30fc\u30bf\u30fc\u30b7\u30fc\u30eb\u30c9\u7de8\uff09<br \/>\n<a href=\"http:\/\/www.moonmile.net\/blog\/archives\/6910\">http:\/\/www.moonmile.net\/blog\/archives\/6910<\/a>\n<\/p>\n<p><h2>\u30b8\u30e7\u30a4\u30b9\u30c6\u30a3\u30c3\u30af\u3092\u30a4\u30d9\u30f3\u30c8\u5316\u3059\u308b<\/h2>\n<\/p>\n<p><a href=\"https:\/\/github.com\/moonmile\/RaspiTank\/blob\/master\/RaspiRobot\/BPiJoystick.cs\">https:\/\/github.com\/moonmile\/RaspiTank\/blob\/master\/RaspiRobot\/BPiJoystick.cs<\/a><\/p>\n<p>\n&#8211; \u30b8\u30e7\u30a4\u30b9\u30c6\u30a3\u30c3\u30af\u306e\u5909\u66f4\u30a4\u30d9\u30f3\u30c8 OnChangedJoystick<br \/>\n&#8211; \u30dc\u30bf\u30f3\u72b6\u614b\u306e\u5909\u66f4\u30a4\u30d9\u30f3\u30c8 OnChangedButton\n<\/p>\n<p>\n\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u30b8\u30e7\u30a4\u30b9\u30c6\u30a3\u30c3\u30af\u306e\u5834\u5408\u306f\u3001XY\u8ef8\u304c\u3061\u3087\u3063\u3068\u305a\u308c\u305f\u3060\u3051\u3067\u30a4\u30d9\u30f3\u30c8\u304c\u767a\u751f\u3059\u308b\u306e\u3067\u3001\u30dc\u30bf\u30f3\u306eON\/OFF\u3068\u306f\u5225\u306b\u30a4\u30d9\u30f3\u30c8\u3092\u767a\u751f\u3055\u305b\u307e\u3059\u3002\n<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nprotected void OnLoop()\r\n{\r\n    while (this.IsLoop)\r\n    {\r\n        js_event js;\r\n        js.time = _br.ReadUInt32();\r\n        js.value = _br.ReadInt16();\r\n        js.type = _br.ReadByte();\r\n        js.number = _br.ReadByte();\r\n        \/\/ Console.WriteLine(js.ToString());\r\n\r\n\t\tbool changedJoystick = false;\r\n\t\tbool changedButton = false;\r\n        if (BPiJoystickData.IsAxis(js.type))\r\n        {\r\n            if (this.Joystick.GetAxisValue(js.number) != js.value)\r\n            {\r\n                Joystick.SetValue(js.type, js.number, js.value);\r\n\t\t\t\tchangedJoystick = true;\r\n            }\r\n        }\r\n        else if (BPiJoystickData.IsButton(js.type))\r\n        {\r\n            if (Joystick.GetButtonValue(js.number) != (js.value != 0))\r\n            {\r\n                Joystick.SetValue(js.type, js.number, js.value);\r\n\t\t\t\tchangedButton = true;\r\n            }\r\n        }\r\n        \/\/ filter\r\n        if (BPiJoystickData.IsAxis(js.type) &amp;&amp; js.number &gt;= 6) changedJoystick = false;\r\n        if (BPiJoystickData.IsButton(js.type) &amp;&amp; js.number &gt;= 16) changedButton = false;\r\n\r\n        \/\/ raise value change event\r\n\t\tif (changedJoystick)\r\n        {\r\n            if (OnChangedJoystick != null)\r\n            {\r\n\t\t\t\tOnChangedJoystick(this, new JoystickEventArgs()\r\n                {\r\n                    Joystick = this.Joystick,\r\n                    Raw = js\r\n                });\r\n            }\r\n            \/\/ Console.Write(&quot;{0} {1} {2} &quot;, js.type, js.number, js.value );\r\n            \/\/ Console.WriteLine(j.ToString());\r\n        }\r\n\t\tif (changedButton)\r\n\t\t{\r\n\t\t\tif (OnChangedButton != null)\r\n\t\t\t{\r\n\t\t\t\tOnChangedButton(this, new JoystickEventArgs()\r\n\t\t\t\t{\r\n\t\t\t\t\tJoystick = this.Joystick,\r\n\t\t\t\t\tRaw = js\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t\t\/\/ Console.Write(&quot;{0} {1} {2} &quot;, js.type, js.number, js.value );\r\n\t\t\t\/\/ Console.WriteLine(j.ToString());\r\n\t\t}\r\n    }\r\n    this._br.Close();\r\n}\r\n<\/pre>\n<p><h2>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306e\u52d5\u304d\u3067\u30e2\u30fc\u30bf\u30fc\u3092\u5236\u5fa1\u3059\u308b<\/h2>\n<\/p>\n<p>\n\u30a2\u30ca\u30ed\u30b0\u30b8\u30e7\u30a4\u30b9\u30c6\u30a3\u30c3\u30af\u3084\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u305f\u3068\u304d\u306e\u30e2\u30fc\u30bf\u30fc\u5236\u5fa1\u3084LED\u70b9\u706f\u3092\u884c\u3044\u307e\u3059\u3002\n<\/p>\n<p><a href=\"https:\/\/github.com\/moonmile\/RaspiTank\/blob\/master\/RaspiRobot\/Program.cs\">https:\/\/github.com\/moonmile\/RaspiTank\/blob\/master\/RaspiRobot\/Program.cs<\/a><\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nclass Program\r\n{\r\n\tstatic void Main(string&#x5B;] args)\r\n\t{\r\n\t\tnew Program().main();\r\n\t}\r\n\r\n\tBPiJoystick js;\r\n\tRaspiRobotNet.RaspiRobot robot;\r\n\t\t\r\n\tpublic void main()\r\n\t{\r\n\t\trobot = new RaspiRobotNet.RaspiRobot();\r\n\r\n\t\tjs = new BPiJoystick();\r\n\t\tjs.OnChangedJoystick += js_OnChangedJoystick;\r\n\t\tjs.OnChangedButton += js_OnChangedButton;\r\n\t\tjs.Setup();\r\n\t\tConsole.WriteLine(&quot;any key is stop.&quot;);\r\n\t\tvar key = Console.ReadKey();\r\n\t}\r\n\r\n\t\/\/\/ &lt;summary&gt;\r\n\t\/\/\/ \u30dc\u30bf\u30f3\u304c\u5909\u66f4\u3055\u308c\u305f\r\n\t\/\/\/ &lt;\/summary&gt;\r\n\t\/\/\/ &lt;param name=&quot;arg1&quot;&gt;&lt;\/param&gt;\r\n\t\/\/\/ &lt;param name=&quot;arg2&quot;&gt;&lt;\/param&gt;\r\n\tvoid js_OnChangedButton(object sender, JoystickEventArgs e)\r\n\t{\r\n\t\tif (e.Joystick.Up == true) robot.Forward();\r\n\t\telse if (e.Joystick.Down == true) robot.Back();\r\n\t\telse if (e.Joystick.Left == true) robot.Left();\r\n\t\telse if (e.Joystick.Right == true) robot.Right();\r\n\t\telse\r\n\t\t{\r\n\t\t\tif (e.Joystick.Up == false &amp;&amp; e.Joystick.Down == false &amp;&amp;\r\n\t\t\t\te.Joystick.Left == false &amp;&amp; e.Joystick.Right == false)\r\n\t\t\t\trobot.Stop();\r\n\t\t}\r\n\r\n\t\t\/\/\/ LED1,2 \u3092\u70b9\u706f\u3059\u308b\r\n\t\trobot.SetLED1( e.Joystick.Circle );\r\n\t\trobot.SetLED2( e.Joystick.Cross );\r\n\t}\r\n\t\/\/\/ &lt;summary&gt;\r\n\t\/\/\/ \u30b8\u30e7\u30a4\u30b9\u30c6\u30a3\u30c3\u30af\u3092\u5909\u66f4\r\n\t\/\/\/ &lt;\/summary&gt;\r\n\t\/\/\/ &lt;param name=&quot;sender&quot;&gt;&lt;\/param&gt;\r\n\t\/\/\/ &lt;param name=&quot;e&quot;&gt;&lt;\/param&gt;\r\n\tvoid js_OnChangedJoystick(object sender, JoystickEventArgs e)\r\n\t{\r\n\t\tint ly = e.Joystick.LeftAxisY;\r\n\t\tint ry = e.Joystick.RightAxisY;\r\n\t\tConsole.WriteLine(&quot;joystick {0} {1}&quot;, ly, ry);\r\n\t\tint sp1 = ly \/ (32767 \/ 200);\r\n\t\tint sp2 = ry \/ (32767 \/ 200);\r\n\t\tif (e.Joystick.Up == false &amp;&amp; e.Joystick.Down == false &amp;&amp;\r\n\t\t\te.Joystick.Left == false &amp;&amp; e.Joystick.Right == false)\r\n\t\t{\r\n\t\t\tmove_bot(sp1, sp2);\r\n\t\t}\r\n\t}\r\n\tvoid move_bot(int sp1, int sp2)\r\n\t{\r\n\t\tif (sp1 &gt; 0 &amp;&amp; sp2 &gt; 0) { robot.Forward(); }\r\n\t\tif (sp1 &lt; 0 &amp;&amp; sp2 &gt; 0) { robot.Right(); }\r\n\t\tif (sp1 &gt; 0 &amp;&amp; sp2 &lt; 0) { robot.Left(); }\r\n\t\tif (sp1 &lt; 0 &amp;&amp; sp2 &lt; 0) { robot.Reverse(); }\r\n\t\t\/\/ \u505c\u6b62\r\n\t\tif (sp1 == 0 &amp;&amp; sp2 == 0) { \r\n\t\t\trobot.Stop(); \r\n\t\t}\r\n\t\t\/\/ \u53f3\u3060\u3051\u52d5\u304b\u3059\r\n\t\tif (sp1 == 0)\r\n\t\t{\r\n\t\t\tif ( sp2 &gt; 0 )\r\n\t\t\t\trobot.SetMotors(false, false, true, false);\r\n\t\t\tif (sp2 &lt; 0)\r\n\t\t\t\trobot.SetMotors(false, false, true, true);\r\n\t\t}\r\n\t\t\/\/ \u5de6\u3060\u3051\u52d5\u304b\u3059\r\n\t\tif (sp2 == 0)\r\n\t\t{\r\n\t\t\tif (sp1 &gt; 0)\r\n\t\t\t\trobot.SetMotors(true, false, false, false);\r\n\t\t\tif (sp1 &lt; 0)\r\n\t\t\t\trobot.SetMotors(true, true, false, false);\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>\n\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u81ea\u4f53\u306f\u30bf\u30fc\u30df\u30ca\u30eb\u3067\u8d77\u52d5\u3059\u308b\u3053\u3068\u3092\u60f3\u5b9a\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u6700\u7d42\u7684\u306b\u306f \/etc\/ini.d \u3092\u5229\u7528\u3057\u3066\u521d\u671f\u8d77\u52d5\u3055\u305b\u307e\u3059\u3002WiFi \u306e\u30c9\u30f3\u30b0\u30eb\u304c\u7d50\u69cb\u306a\u96fb\u529b\u3092\u98df\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u3053\u308c\u3092\u5916\u3059\u3060\u3051\u3067\u3082\u304b\u306a\u308a RasPi \u306e\u52d5\u4f5c\u304c\u5b89\u5b9a\u3057\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u5916\u5074\u304b\u3089 RasPi \u306e\u72b6\u614b\u304c\u898b\u3048\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u4f55\u3089\u304b\u306e\u30e2\u30cb\u30bf\u30ea\u30f3\u30b0\u304c\u5fc5\u8981\u3067\u3059\u3088\u306d\u3002\u3042\u3068\u3067\u3001RasPi \u306b\u30df\u30cb\u6db2\u6676\u3092\u4ed8\u3051\u3066\u72b6\u614b\u3092\u76e3\u8996\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002\n<\/p>\n<p>\n\u4e0a\u8a18\u3067\u306f\u30b8\u30e7\u30a4\u30b9\u30c6\u30a3\u30c3\u30af\u3068\u3044\u304f\u3064\u304b\u306e\u25cb\u00d7\u30dc\u30bf\u30f3\u3092\u5358\u72ec\u3067\u611f\u77e5\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u540c\u6642\u62bc\u3057\u3068\u304bR\/L\u30dc\u30bf\u30f3\u3082\u53d6\u5f97\u304c\u3067\u304d\u307e\u3059\u3002\u3061\u306a\u307f\u306b\u3001\u30b8\u30e7\u30a4\u30b9\u30c6\u30a3\u30c3\u30af\u306e\u50be\u304d\u3082\u53d6\u308c\u308b\u306e\u3067\u3001\u30b9\u30de\u30fc\u30c8\u30d5\u30a9\u30f3\u3092\u50be\u3051\u305f\u3068\u304d\u306e\u3088\u3046\u306a\u52d5\u4f5c\u3082\u53ef\u80fd\u3067\u3059\u3002\u3053\u306e\u3042\u305f\u308a\u306f\u3001RasPi \u6226\u8eca\u306b\u9650\u3089\u305a\u3001RasPi \u81ea\u4f53\u3092\u5a92\u4ecb\u3055\u305b\u308b\u3053\u3068\u3067\u3001\u30b2\u30fc\u30e0\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc -&gt; RasPi -&gt; Windows PC \u3068\u3044\u3046\u30d1\u30bf\u30fc\u30f3\u304c\u7d44\u3081\u307e\u3059\u3002Windows \u81ea\u4f53\u306f\u30b2\u30fc\u30e0\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u8a8d\u8b58\u3059\u308b\u306e\u3067\u3059\u304c\u3001\u306a\u305c\u304b 8.1 \u304b\u3089 PS3 Dualshock3 \u306f\u8a8d\u8b58\u3057\u306a\u3044\u3093\u3067\u3059\u3088\u306d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30b2\u30fc\u30e0\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3067\u6226\u8eca\u306e\u30e2\u30fc\u30bf\u30fc\u3092\u5236\u5fa1\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4ee5\u4e0b\u306e2\u3064\u3092\u304f\u3063\u3064\u3051\u307e\u3059\u3002 Raspberry Pi \u3067\u6226\u8eca\u3092\u4f5c\u308b\uff08Bluetooth\/PS3 Dualshock3\u7de8\uff09 http:\/\/www.moonmile &hellip; <a href=\"https:\/\/www.moonmile.net\/blog\/archives\/6914\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":5999,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[23,67],"tags":[],"class_list":["post-6914","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","category-raspberrypi"],"jetpack_featured_media_url":"https:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2014\/06\/title-raspi.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/6914","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/comments?post=6914"}],"version-history":[{"count":2,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/6914\/revisions"}],"predecessor-version":[{"id":6916,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/6914\/revisions\/6916"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media\/5999"}],"wp:attachment":[{"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=6914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=6914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=6914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}