-
Notifications
You must be signed in to change notification settings - Fork 13
ToF(VL53L0X)
距離センサ
コードURL: https://github.com/gfd-dennou-club/iotex-esp32-mrubyc/blob/master/mrblib/models/vl53l0x.rb
サンプルコード1(連続距離測定): https://github.com/gfd-dennou-club/iotex-esp32-mrubyc/blob/master/example/master.rb.vl53l0x-1
サンプルコード2(単発距離測定): https://github.com/gfd-dennou-club/iotex-esp32-mrubyc/blob/master/example/master.rb.vl53l0x-2
VL53L0X.new(i2c)
- i2c : I2Cクラスのオブジェクト
example
i2c = I2C.new(22, 21)
vl53l0x = VL53L0X.new(i2c)
VL53L0X.init()
example
if !vl53l0x.init
puts "Failed to detect and initialize sensor!"
else
...
end
VL53L0X.set_timeout(timeout)
- timeout : タイムアウト期間(センサが準備できていない場合に読み取り動作が中止されるまでの時間)(ms)
example
vl53l0x.set_timeout(500) # タイムアウト期間を設定
VL53L0X.timeout_occurred()
前回のtimeout_occurred()が呼び出された後にタイムアウトが発生したかを取得
タイムアウトが発生していたらtrue、発生していなければfalse
example
puts " TIMEOUT" if vl53l0x.timeout_occurred
VL53L0X.set_signal_rate_limit(limit_mcps = 0.25)
- limit_mcps : レート制限(MCPS)
戻り信号のレート制限を1秒あたりのメガカウント(MCPS)で指定した値に設定
デフォルトでは0.25(MCPS)
example
# vl53l0x.set_signal_rate_limit(0.1) # 戻り信号のレート制限を下げる
VL53L0X.set_vcsel_purse_period(type, period_pclks)
- type : 周期タイプ 0(VcselPeriodPreRange), 1(VcselPeriodFinalRange)
- period_pclks : 設定する周期(PCLK)
指定した同期タイプの垂直共振器面発光レーザー(VCSEL)のパルス周期(PCLK)を指定
デフォルトでは 14, 10 PCLKs
example
# デフォルトでは 14, 10
# 18, 14に変更
vl53l0x.set_vcsel_purse_period(0, 18)
vl53l0x.set_vcsel_purse_period(1, 14)
VL53L0X.set_measurement_timing_budget(budget_us)
- budget_us : 設定する測定タイミングパジェット(μs)
測定タイミングパジェット(1回の距離測定に許容される時間)を指定
値が有効ならtrue、無効ならfalseを返す
example
# 精度を下げてより高い速度を得る
vl53l0x.set_measurement_timing_budget(20_000) # タイミングパジェットを20ミリ秒に減らす
# 速度を落としてより高い精度を得る
vl53l0x.set_measurement_timing_budget(200_000) # タイミングパジェットを200ミリ秒に増やす
VL53L0X.start_continuous(period_ms = 0)
- period_ms : 測定間隔(ms) 0ならできる限り高レートで測定を行う
example
vl53l0x.start_continuous(100) # 100ms間隔で測定
VL53L0X.stop_continuous()
example
vl53l0x.stop_continuous
VL53L0X.read_range_continuous_millimeters()
example
range = vl53l0x.read_range_continuous_millimeters # 距離の取得(mm)
VL53L0X.read_range_single_millimeters()
example
range = vl53l0x.read_range_single_millimeters # 距離の取得(mm)