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
Diff: Locate.h
- Revision:
- 3:633ea1e7c681
- Parent:
- 1:2bded5a5f636
- Child:
- 4:93c79c4168c7
--- a/Locate.h Sat Jul 02 02:36:39 2016 +0000 +++ b/Locate.h Thu Aug 11 04:07:42 2016 +0000 @@ -1,29 +1,43 @@ #ifndef Locate_H -#define Locate_H +#define Locate_H + +#define OUTERRING_D 264 //外輪間距離(mm) +#define INNERRING_D 224 //内輪間距離(mm) +#define PI 3.14159 //π +#define RESOLUSION 200 //P/R(分解能) +#define DIAMETER 50.0 //タイヤの直径(mm) +#define LOCATE_STEP (DIAMETER*PI / RESOLUSION) // エンコーダの1ステップあたりの距離(mm) +#define TIRE_DISTANCE ((OUTERRING_D + INNERRING_D) / 2) //タイヤ間距離(mm) +#define ROUND (DIAMETER / (RESOLUSION * TIRE_DISTANCE)) //1回転するためのステップ数の”逆数” + +/* +エンコーダから、現在のステップ数(=タイヤがどれだけ回ったか)を得られる +今回は分解能が200だから、(タイヤ1回転) = (200ステップ) +*/ + -#define OUTERRING_D 264 //外輪間距離 -#define INNERRING_D 224 //内輪間距離 -#define PI 3.14159 -#define RESOLUSION 100 //P/R(分解能) -#define DIAMETER 50.0 //タイヤの直径 (mm) -#define Locate_STEP (DIAMETER*PI / RESOLUSION) // エンコーダの一ステップあたりの距離(mm) -#define TIRE_DISTANCE ((OUTERRING_D + INNERRING_D) / 2) //タイヤ間距離(mm) -#define ROUND (DIAMETER / (RESOLUSION * TIRE_DISTANCE)) //1回転するためのステップ数の”逆数” +class Locate +{ +//引数のr,lはエンコーダから受け取るステップ数で、rは右車輪、lは左車輪 + +private: + short v; //ステップ速度 + int pr, pl; //前回のステップ数 + char dl, dr; //エンコーダの初期ズレ + float x, y; //xy方向に進んだ距離(m換算なし) -//エンコーダから、現在のパルス数を得られるぞ! -//真ん中中心で考える! - -class Locate { -private: - int v; //ステップ速度 - double theta; //機体角度 public: - Locate (); - - double x, y; //機体角度、xy方向に進む距離(m換算なし)(mainに送る) + float theta; //機体角度 + + Locate (int fx, int fy); //fx,fyは初期位置 - void update (short int, short int); //引数は左右のパルス数でエンコーダから受け取る + void setup(int r, int l); //エンコーダの初期のズレ(dr,dl)を出す、最初に一回だけ行う + + void update (int r, int l); //位置情報を更新する + + short getX(); //x, yをmm換算して整数値として返す + short getY(); };