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.
readme.txt
- Committer:
- DaichiArai
- Date:
- 2019-04-30
- Revision:
- 9:a3a2fb1a3ba7
- Parent:
- 8:f62e19b0c76e
- Child:
- 10:1bbe0d41813e
File content as of revision 9:a3a2fb1a3ba7:
1.インスタンス生成方法
class motor motorname(int address);
2.モータの駆動方法
int move(float pwm);
・-1 ~ -0.01 :モータ逆回転
・0.01 ~ 1 :モータ正回転
・0 :モータ停止(ブレーキ)
・引数無し(空白):モータフリー(何もしない)
返り値:通信結果(0:成功,1:失敗)
3.エンコーダの角度と角速度の読み取り(単位はrad基準)
float spd(); 角速度を読み取る.返り値:角速度(rad/s)
float angle(); 角度を読み取る.オーバーフロー注意.返り値:角度(rad)
float position(); 1周のうちの自己位置を求める。正の値しか返さない。返り値:角度(rad)
int count; angle_e()関数が最後に呼び出された時点での回転数。返り値:回転数
//サンプル----------------------------------------------------------------------
#include "mbed.h"
#include "mdc.h"
Serial pc(USBTX,USBRX,115200);
I2C i2c_encoder(D4,D5);
class motor motor1(i2c_encoder,0x20);
class motor motor2(i2c_encoder,0x22);
int main(void){
while(1){
motor1.move(0.6);
motor2.move();
pc.printf("motor1.spd = %.3f\t",motor1.spd());
pc.printf("motor1.angle = %.3f\t",motor1.angle());
pc.printf("motor1.position = %.3f\t",motor1.position());
pc.printf("\n");
}
}