Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Encoder by
Homepage
使い方
まず、"Locate.h"をインクルードする。 次に、Locate machine(x, y)で宣言する。(xとyは初期位置。でも(0,0)推奨) 続いて位置情報を得る。 位置情報を更新する関数は、machine.update()だが、位置情報を得る方法は2つある
(1)machine.update()を直接使う場合
一連の処理は、
machine.update((エンコーダの右), (エンコーダの左));
x = machine.getX();
y = machine.getY();
こんな感じ。
(2)machine.update()を直接使わない場合
一連の処理は、
x = machine.getX((エンコーダの右), (エンコーダの左));
y = machine.getY((エンコーダの右), (エンコーダの左));
こんな感じ。 あるいは、
x = machine.getX((エンコーダの右), (エンコーダの左));
y = machine.getY();
でも同じ結果を得られる。
まとめると、位置情報を得るときは、最初の関数にエンコーダで読み取った値を渡す必要がある。
ちなみにエンコーダの値を得るためには、"QEI.h"(https://developer.mbed.org/users/aberk/code/QEI/) を別途インクルードしたうえで、
QEI right (PA_7, PA_5, NC, lPR, QEI::X2_ENCODING); 右側のエンコーダ
QEI left (PA_13, PA_15, NC, lPR, QEI::X2_ENCODING); 左側のエンコーダ
のように宣言する必要がある。 その後、例えば右側のエンコーダの値を得たいときには、right.getPulses() を使う これを使うと、(1)は
machine.update(right.getPulses(), left.getPulses());
x = machine.getX();
y = machine.getX();
となる
