{"id":8160,"date":"2026-09-23T11:25:52","date_gmt":"2026-09-23T02:25:52","guid":{"rendered":"https:\/\/robot.e-nat.org\/?p=8160"},"modified":"2026-09-23T11:30:36","modified_gmt":"2026-09-23T02:30:36","slug":"pybricks%e3%81%a8vscodeblocklypy-commander","status":"publish","type":"post","link":"https:\/\/robot.e-nat.org\/?p=8160","title":{"rendered":"Pybricks\u3068VSCode+BlocklyPy Commander"},"content":{"rendered":"\n<p>\u91d1\u5b8f\u548c\u5be6\u3067\u3059\u3002\u512a\u79c0\u306a\u5c0f\u5b66\u751f\u30d7\u30ed\u30b0\u30e9\u30de\u30fc\u306b\u6559\u3048\u3066\u3082\u3089\u3063\u3066\u3001PyBricks\u3068BlocklyPy Commander\u3092\u4f7f\u3063\u3066\u307f\u307e\u3057\u305f\u3002Pybricks\u306fMicroPython\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u74b0\u5883\u3067BlocklyPy Commander\u306fVSCode\u306e\u62e1\u5f35\u6a5f\u80fd\u3067\u3059\u3002<br>(VSCode\u3067Pybricks\u3092\u4f7f\u3048\u308b\u3088\u3046\u306b\u3059\u308b\u306b\u306fPython\u305d\u306e\u3082\u306e\u3084pybricks\u30e9\u30a4\u30d6\u30e9\u30ea\u306a\u3069\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u5fc5\u8981\u3067\u3059\u304c\u3001\u305d\u3053\u306f\u60c5\u5831\u304c\u591a\u3044\u306e\u3067\u5272\u611b\u3057\u307e\u3059\u3002\u6b21\u306e<a href=\"https:\/\/note.com\/brico_school\/n\/nbeece507cc04\" target=\"_blank\" rel=\"noreferrer noopener\">\u30b5\u30a4\u30c8<\/a>\u306a\u3069\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\uff09<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"450\" src=\"https:\/\/robot.e-nat.org\/wp-content\/uploads\/2026\/09\/blokly_01-1024x450.png\" alt=\"\" class=\"wp-image-8162\" srcset=\"https:\/\/robot.e-nat.org\/wp-content\/uploads\/2026\/09\/blokly_01-1024x450.png 1024w, https:\/\/robot.e-nat.org\/wp-content\/uploads\/2026\/09\/blokly_01-300x132.png 300w, https:\/\/robot.e-nat.org\/wp-content\/uploads\/2026\/09\/blokly_01-768x338.png 768w, https:\/\/robot.e-nat.org\/wp-content\/uploads\/2026\/09\/blokly_01-1536x675.png 1536w, https:\/\/robot.e-nat.org\/wp-content\/uploads\/2026\/09\/blokly_01-137x60.png 137w, https:\/\/robot.e-nat.org\/wp-content\/uploads\/2026\/09\/blokly_01.png 1645w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u30ed\u30dc\u30c3\u30c8\u3092Bluetooth\u63a5\u7d9a\u3057\u305f\u72b6\u614b\u3067\u65b0\u898f\u306b\u30d7\u30ed\u30b0\u30e9\u30e0\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308c\u3070\u3001\u4e0a\u306e\u753b\u50cf\u306e\u3088\u3046\u306b\u5404\u30dd\u30fc\u30c8\u306b\u63a5\u7d9a\u3055\u308c\u3066\u3044\u308b\u30c7\u30d0\u30a4\u30b9\u3092\u691c\u77e5\u3057\u3066\u30b3\u30fc\u30c9\u3092\u633f\u5165\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"595\" src=\"https:\/\/robot.e-nat.org\/wp-content\/uploads\/2026\/09\/blokly_02-1024x595.png\" alt=\"\" class=\"wp-image-8165\" srcset=\"https:\/\/robot.e-nat.org\/wp-content\/uploads\/2026\/09\/blokly_02-1024x595.png 1024w, https:\/\/robot.e-nat.org\/wp-content\/uploads\/2026\/09\/blokly_02-300x174.png 300w, https:\/\/robot.e-nat.org\/wp-content\/uploads\/2026\/09\/blokly_02-768x446.png 768w, https:\/\/robot.e-nat.org\/wp-content\/uploads\/2026\/09\/blokly_02-1536x892.png 1536w, https:\/\/robot.e-nat.org\/wp-content\/uploads\/2026\/09\/blokly_02-103x60.png 103w, https:\/\/robot.e-nat.org\/wp-content\/uploads\/2026\/09\/blokly_02.png 1648w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>BlocklyPy\u3092\u4f7f\u3048\u3070\u3001\u305f\u3068\u3048\u3070Gyro\u30bb\u30f3\u30b5\u30fc\u306e\u5024\u3092\u4e0a\u306e\u753b\u50cf\u306e\u3088\u3046\u306b\u30bf\u30fc\u30df\u30ca\u30eb\u306b\u51fa\u529b\u3055\u305b\u305f\u4e0a\u3067\u53ef\u8996\u5316\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\uff08\u30b3\u30fc\u30c9\u306e\u66f8\u304d\u65b9\u304c\u72ec\u81ea\u306e\u5236\u7d04\u304c\u3042\u308b\u306e\u3067\u3061\u3087\u3063\u3068\u6238\u60d1\u3044\u8ff7\u3044\u307e\u3057\u305f\u304c\uff09<\/p>\n\n\n\n<p>\u6b21\u306f\u30e9\u30a4\u30f3\u30c8\u30ec\u30fc\u30b9\u3092\u3059\u308bMicroPython\u306e\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>from pybricks.hubs import PrimeHub\nfrom pybricks.pupdevices import Motor, ColorSensor, UltrasonicSensor, ForceSensor\nfrom pybricks.parameters import Button, Color, Direction, Port, Side, Stop\nfrom pybricks.robotics import DriveBase\nfrom pybricks.tools import wait, StopWatch\n\nhub = PrimeHub()                                                       # SPIKE Prime Hub\nforce_a = ForceSensor(Port.A)                                          # SPIKE\/Technic Force Sensor\ncolor_b = ColorSensor(Port.B)                                          # SPIKE\/Technic Color Sensor\nmotor_c = Motor(Port.C, positive_direction=Direction.COUNTERCLOCKWISE) # SPIKE Prime Medium Motor\nmotor_d = Motor(Port.D)                                                # SPIKE Prime Medium Motor\nmotor_e = Motor(Port.E)                                                # SPIKE Prime Large Motor\nusensor_f = UltrasonicSensor(Port.F)                                   # SPIKE\/Technic Ultrasonic Sensor\nrobot = DriveBase(motor_c, motor_d, wheel_diameter=56, axle_track=112) # DriveBase based on detected motors\n\n# \u30e9\u30a4\u30f3\u30c8\u30ec\u30fc\u30b9\u7528\u306e\u5b9a\u6570\u8a2d\u5b9a\nDRIVE_SPEED = 100      # \u8d70\u884c\u901f\u5ea6 (mm\/s)\nTHRESHOLD = 50         # \u767d\u3068\u9ed2\u306e\u5883\u754c\u306e\u53cd\u5c04\u5149\u5f37\u5ea6 (\u4e2d\u9593\u5024)\nPROPORTIONAL_GAIN = 1.5 # \u88dc\u6b63\u306e\u5f37\u3055\uff08P\u30b2\u30a4\u30f3\uff09\n\ndef line_trace(distance):\n    # \u6307\u5b9a\u3057\u305f\u8ddd\u96e2\u306b\u9054\u3059\u308b\u307e\u3067\u30eb\u30fc\u30d7\u3092\u56de\u3059\n    while robot.distance() &lt; distance:\n        # \u30bb\u30f3\u30b5\u30fc\u304b\u3089\u73fe\u5728\u306e\u53cd\u5c04\u5149\u306e\u660e\u308b\u3055\u3092\u53d6\u5f97 (0\u301c100)\n        current_reflection = color_b.reflection()\n        \n        # \u5883\u754c\u5024\u3068\u306e\u300c\u30ba\u30ec\u300d\u3092\u8a08\u7b97\n        deviation = current_reflection - THRESHOLD\n        \n        # \u30ba\u30ec\u306b\u30b2\u30a4\u30f3\u3092\u639b\u3051\u3066\u3001\u66f2\u304c\u308b\u52e2\u3044\uff08\u65cb\u56de\u901f\u5ea6\uff09\u3092\u8a08\u7b97\n        turn_rate = deviation * PROPORTIONAL_GAIN\n        \n        # \u8a08\u7b97\u3057\u305f\u901f\u5ea6\u3068\u65cb\u56de\u901f\u5ea6\u3067\u30ed\u30dc\u30c3\u30c8\u3092\u52d5\u304b\u3059\uff08\u30ce\u30f3\u30d6\u30ed\u30c3\u30ad\u30f3\u30b0\uff09\n        robot.drive(DRIVE_SPEED, turn_rate)\n        \n        # \u30eb\u30fc\u30d7\u304c\u65e9\u3059\u304e\u3066\u51e6\u7406\u304c\u8a70\u307e\u308b\u306e\u3092\u9632\u3050\u305f\u3081\u306e\u77ed\u3044\u30a6\u30a7\u30a4\u30c8\n        wait(10)\n\n    # \u6307\u5b9a\u8ddd\u96e2\u3092\u8d70\u308a\u7d42\u3048\u305f\u3089\u3001\u30d4\u30bf\u30c3\u3068\u505c\u6b62\u3059\u308b\n    robot.stop()\n\ndef main():\n    print(\"Starting line trace...\")\n    # \u8d70\u884c\u8ddd\u96e2\u30e1\u30fc\u30bf\u30fc\u30920\u306b\u30ea\u30bb\u30c3\u30c8\n    robot.reset()\n    line_trace(1000)\n    print(\"Line trace completed.\")  \n\nif __name__ == \"__main__\":\n    main()<\/code><\/pre>\n\n\n\n<p>\u6307\u5b9a\u3057\u305f\u8ddd\u96e2\u307e\u3067\u30e9\u30a4\u30f3\u30c8\u30ec\u30fc\u30b9\u3092\u3059\u308b\u95a2\u6570\u3092\u3072\u3068\u3064\u6301\u3064\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002\u3068\u8a00\u3063\u3066\u3082AI\uff08Gemini\uff09\u304c\u4f5c\u3063\u3066\u304f\u308c\u305f\u30b3\u30fc\u30c9\u306b\u5c11\u3057\u624b\u3092\u52a0\u3048\u305f\u3060\u3051\u3067\u3059\u3002MicroPython\u306f\u5e83\u304f\u4f7f\u308f\u308c\u3066\u3044\u308b\u306e\u3067AI\u304c\u304b\u306a\u308a\u6b63\u78ba\u306a\u30b3\u30fc\u30c9\u3092\u63d0\u793a\u3057\u3066\u304f\u308c\u308b\u3088\u3046\u3067\u3059\u3002<br>Pybricks\u3092\u59cb\u3081\u3088\u3046\u3068\u3057\u3066\u3044\u308b\u4eba\u306f\u53c2\u8003\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p>\u307e\u305f\u3001\u5c0f\u4e2d\u5b66\u751f\u304cAI \u3092\u5229\u7528\u3059\u308b\u3053\u3068\u306b\u3064\u3044\u3066\u3044\u308d\u3044\u308d\u306a\u8b70\u8ad6\u304c\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u5834\u5408\u3001AI\u304c\u4f5c\u6210\u3057\u305f\u30b3\u30fc\u30c9\u3092\u8aad\u3081\u306a\u3044\u3068\u5148\u306b\u9032\u3081\u306a\u3044\u306e\u3067\u3001\u79c1\u8ad6\u3068\u3057\u3066\u306fAI\u3068\u30da\u30a2\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3082\u826f\u3044\u3093\u3058\u3083\u306a\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u91d1\u5b8f\u548c\u5be6\u3067\u3059\u3002\u512a\u79c0\u306a\u5c0f\u5b66\u751f\u30d7\u30ed\u30b0\u30e9\u30de\u30fc\u306b\u6559\u3048\u3066\u3082\u3089\u3063\u3066\u3001PyBricks\u3068BlocklyPy Commande &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":[],"class_list":["post-8160","post","type-post","status-publish","format-standard","hentry","category-python","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\/8160","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=8160"}],"version-history":[{"count":13,"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=\/wp\/v2\/posts\/8160\/revisions"}],"predecessor-version":[{"id":8175,"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=\/wp\/v2\/posts\/8160\/revisions\/8175"}],"wp:attachment":[{"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}