{"id":7555,"date":"2025-04-26T17:31:34","date_gmt":"2025-04-26T08:31:34","guid":{"rendered":"https:\/\/robot.e-nat.org\/?p=7555"},"modified":"2025-04-26T17:31:35","modified_gmt":"2025-04-26T08:31:35","slug":"python%e5%85%a5%e9%96%80%e7%ac%ac4%e5%9b%9e%e3%80%8cp%e5%88%b6%e5%be%a1%e3%81%ae%e3%83%a9%e3%82%a4%e3%83%b3%e3%83%88%e3%83%ac%e3%83%bc%e3%82%b9%e3%80%8d","status":"publish","type":"post","link":"https:\/\/robot.e-nat.org\/?p=7555","title":{"rendered":"Python\u5165\u9580\u7b2c4\u56de\u300cP\u5236\u5fa1\u306e\u30e9\u30a4\u30f3\u30c8\u30ec\u30fc\u30b9\u300d"},"content":{"rendered":"\n<p>\u3000\u91d1\u5b8f\u548c\u5be6\u3067\u3059\u3002Python\u5165\u9580\u306e\u7b2c4\u56de\u3067\u3059\u3002\u4eca\u56de\u306fP\u5236\u5fa1\u306e\u30e9\u30a4\u30f3\u30c8\u30ec\u30fc\u30b9\u3067\u3059\u3002P\u306fProportional\uff08\u6bd4\u4f8b\uff09\u306e\u982d\u6587\u5b57\u3067\u3059\u3002<br>\u3000\u7b2c3\u56de\u306e\u57fa\u672c\u306e\u30e9\u30a4\u30f3\u30c8\u30ec\u30fc\u30b9\u3067\u306f\u6b21\u306e\u3088\u3046\u306aif\u6587\u3067\u30b9\u30c6\u30a2\u30ea\u30f3\u30b0\u306e\u5024\u3092\u5909\u3048\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        if (color_sensor.reflection(port.B) &lt; 50): # \u9ed2\u3044\u7dda\u306e\u4e0a\n            # \u30b9\u30c6\u30a2\u30ea\u30f3\u30b030\u3067\u53f3\u306b\u3002\n            motor_pair.move(motor_pair.PAIR_1, 30, velocity = 300)  \n        else: # \u767d\u3044\u3068\u3053\u308d\u306e\u4e0a\n            # \u30b9\u30c6\u30a2\u30ea\u30f3\u30b0-30\u3067\u53f3\u306b\u3002\n            motor_pair.move(motor_pair.PAIR_1, -30, velocity = 300)<\/code><\/pre>\n\n\n\n<p>\u3000\u5149\u30bb\u30f3\u30b5\u30fc\u306e\u8fd4\u3059\u5024\u306850\u3092\u6bd4\u8f03\u3057\u3066\u5927\u304d\u3051\u308c\u3070\u3001\u9ed2\u3044\u7dda\u5074\u3092\u5411\u304f\u3088\u3046\u306b\u30b9\u30c6\u30a2\u30ea\u30f3\u30b0\u309230\u306b\u3057\u3066\u3001\u5c0f\u3055\u3051\u308c\u3070\u767d\u3044\u3068\u3053\u308d\u3092\u5411\u304f\u3088\u3046\u306b\u30b9\u30c6\u30a2\u30ea\u30f3\u30b0\u3092-30\u306b\u3057\u307e\u3057\u305f\u3002<br><br>\u3000P\u5236\u5fa1\u3001\u6bd4\u4f8b\u5236\u5fa1\u3068\u3044\u3046\u3068\u96e3\u3057\u305d\u3046\u306b\u805e\u3053\u3048\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u6697\u3044\u304b\u660e\u308b\u3044\u304b\u3092\u5224\u65ad\u3059\u308b\u3057\u304d\u3044\u5024\u3067\u3042\u308b50\u3068\u5149\u30bb\u30f3\u30b5\u30fc\u306e\u8fd4\u3059\u5024\u3092\u5f15\u304d\u7b97\u3057\u3066\u3001\u9069\u5f53\u306a\u4fc2\u6570\u3092\u639b\u3051\u3066\u3084\u308c\u3070\u3001\u30b9\u30c6\u30a2\u30ea\u30f3\u30b0\u306e\u5024\u3068\u3057\u3066\u4f7f\u3048\u308b\u3093\u3058\u3083\u306a\u3044\u306e\u3068\u3044\u3046\u767a\u60f3\u3067\u3059\u3002\u3067\u3059\u304b\u3089\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u3088\u308a\u30b7\u30f3\u30d7\u30eb\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from hub import port\nimport motor_pair, color_sensor, runloop\n\nmotor_pair.pair(motor_pair.PAIR_1, port.C, port.D)\n\nasync def line_follow_forever():\n    while (True):\n        err = 50 - color_sensor.reflection(port.B)\n        corr = int(err * 0.5)\n        motor_pair.move(motor_pair.PAIR_1, corr, velocity = 300)\n\nasync def main():\n    await line_follow_forever()\n\nrunloop.run(main())\n<\/code><\/pre>\n\n\n\n<p>\u3000\u5909\u6570err\u306b50\u3068\u5149\u30bb\u30f3\u30b5\u30fc\u304c\u8fd4\u3059\u5024\u306e\u5dee\u3092\u4ee3\u5165\u3057\u307e\u3059\u3002\u9ed2\u3044\u7dda\u306e\u4e0a\u306b\u3044\u308c\u3070\u3001err\u306e\u5024\u306f\u6b63\u306e\u5024\u306b\u306a\u308a\u3001\u767d\u3044\u3068\u3053\u308d\u306b\u3044\u308c\u3070\u8ca0\u306e\u5024\u306b\u306a\u308a\u307e\u3059\u3002\u305d\u308c\u306b\u4fc2\u65700.5\u3092\u639b\u3051\u305f\u5024\u3092\u30b9\u30c6\u30a2\u30ea\u30f3\u30b0\u306e\u5024\uff08corr\uff09\u306b\u3057\u307e\u3059\u3002\u4fc2\u65700.5\u306b\u610f\u5473\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u3061\u3087\u3046\u3069\u826f\u3044\u611f\u3058\u306b\u30e9\u30a4\u30f3\u30c8\u30ec\u30fc\u30b9\u3057\u3066\u304f\u308c\u308b\u3088\u3046\u306b\u5024\u3092\u8abf\u6574\u3059\u308c\u3070\u826f\u3044\u3060\u3051\u3067\u3059\u3002int(err * 0.5)\u306eint()\u306f\u8a08\u7b97\u7d50\u679c\u3092\u6574\u6570\u5024\u306b\u5909\u63db\u3059\u308b\u95a2\u6570\u3067\u3059\u3002<br>\u3000if\u6587\u3092\u4f7f\u3046\u3088\u308a\u3001\u7c21\u5358\u306a\u30b3\u30fc\u30c9\u306b\u306a\u308b\u3068\u3053\u308d\u304c\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u300c\u304a\u3082\u3057\u308d\u307f\u300d\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u91d1\u5b8f\u548c\u5be6\u3067\u3059\u3002Python\u5165\u9580\u306e\u7b2c4\u56de\u3067\u3059\u3002\u4eca\u56de\u306fP\u5236\u5fa1\u306e\u30e9\u30a4\u30f3\u30c8\u30ec\u30fc\u30b9\u3067\u3059\u3002P\u306fProportional\uff08 &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[41],"tags":[21,15,14],"class_list":["post-7555","post","type-post","status-publish","format-standard","hentry","category-python","tag-mindstorms","tag-15","tag-14","latest_post"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=\/wp\/v2\/posts\/7555","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7555"}],"version-history":[{"count":1,"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=\/wp\/v2\/posts\/7555\/revisions"}],"predecessor-version":[{"id":7556,"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=\/wp\/v2\/posts\/7555\/revisions\/7556"}],"wp:attachment":[{"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7555"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}