1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

M5BALAでライントレース (赤外線ライン検出センサー編)

Last updated at Posted at 2018-11-08

概要

M5BALA + M5Stack FIRE に赤外線のライン検出センサーを接続しライントレースをさせてみました。

  • M5Stack FIRE に赤外線のライン検出センサーを接続
  • 線の検出によって左右の回転を制御することでライントレースを行う

環境

  • M5BALA + M5Stack FIRE
  • M5UI.Flow (Firmware 0.8.2 で確認)
  • ライン検出センサー Seeed Studio Grove Line Finder v1.1

ライン検出センサーの実装

ライン検出センサーを PORT B に接続し、輪ゴムで固定。センサーの重みで前のめりになるので後ろにも付属のレゴの部品でバランスを取りました。
IMG_1882.jpeg IMG_1884.jpeg

実行例

バランスを取りながらでは、あまり複雑な線のトレースは難しいので、単純なコースですが。

M5BALA制御用プログラム

以下のプログラムを M5UI.Flow から実行しました。

m5bala_line_trace.py
from m5stack import *
from m5bala import M5Bala
import i2c_bus
import machine

m5bala = M5Bala(i2c_bus.get(i2c_bus.M_BUS))

# ライン検出センサーを PORT B に接続
ir_rx = machine.Pin(36, machine.Pin.IN)

# スレッドを使うと不安定(途中で止まってしまう)だったので
# スレッドを使わずに動かしました。
# m5bala.start(thread=True)

# 左右の動き&前進のためのパラメータは実際の動きに合わせて要調整。
line_trace = [15, 50]

while True:
    # センサーの値が 1 (反射無し=黒線上)
    # センサーの値が 0 (反射有り=黒線から外れた)
    # センサーが黒線上にあれば左へ、黒線から外れたら右へ
    # 黒線の左側に沿って進む仕組みです
    rx = ir_rx.value()
    if rx == 1:
        m5bala.left  = line_trace[0]
        m5bala.right = line_trace[1]
    else:
        m5bala.left  = line_trace[1]
        m5bala.right = line_trace[0]
    
    m5bala.balance()
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?