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.
Diff: EC.h
- Revision:
- 31:05e37fea072b
- Parent:
- 30:087ad7703445
- Child:
- 32:297384f9d261
--- a/EC.h Thu Aug 17 04:27:00 2017 +0000
+++ b/EC.h Thu Aug 17 07:49:21 2017 +0000
@@ -153,7 +153,97 @@
/**速度制御用ライブラリ
*
* サンプルプログラム
+ * @code
+ * //サンプルプログラム 差動二輪駆動ロボットを想定
+ * //直進・後退・右旋回・左旋回が可能
+ * #include "mbed.h"
+ * #include "EC.h"
*
+ * #define BASIC_SPEED 20 //モーターはこの角速度で駆動させる
+ *
+ * SpeedControl motorR(PF_0,PB_1,NC,1048,0.05,PA_8,PB_5); //右輪
+ * SpeedControl motorL(PF_1,PA_11,NC,1048,0.05,PA_9,PA_10); //左輪
+ * Ticker motor_tick; //角速度計算用ticker
+ * Serial pc(USBTX,USBRX);
+ *
+ * void calOmega() //角速度計算関数
+ * {
+ * motorR.CalOmega();
+ * motorL.CalOmega();
+ * }
+ *
+ * int main(void){
+ * motor_tick.attach(&calOmega,0.05);
+ * //Cの値を設定
+ * motorR.setDOconstant(46.3);
+ * motorL.setDOconstant(47.2);
+ * //pd係数を設定
+ * motorR.setPDparam(0.1,0);
+ * motorR.setPDparam(0.12,0);
+ *
+ * int kai=0;
+ * double target_R=0,target_L=0;
+ * char status[5][10]={"STOP","FORWARD","BACKWARD","RIGHT","LEFT"};
+ * int status_num=0; //初期状態は停止
+ *
+ * while(1) {
+ * motorR.Sc(target_R);
+ * motorL.Sc(target_L); //target_R,target_Lの値を変えることで直進・後退・右回転・左回転を行う
+ *
+ * if(kai>=500) {
+ * pc.printf("status=%s omega_R=%f omega_L=%f \r\n",status[status_num],motorR.getOmega(),motorL.getOmega());
+ * //機体の進む方向、右モーターの角速度、左モーターの角速度を表示
+ * kai=0;
+ * }
+ *
+ * if(pc.readable()) {
+ * char sel=pc.getc();
+ *
+ * switch (sel) {
+ * case 's': //停止
+ * motorR.stop();
+ * motorL.stop();
+ * target_R=0;
+ * target_L=0;
+ * status_num=0;
+ * break;
+ * case 'i': //前進
+ * target_R=BASIC_SPEED;
+ * target_L=BASIC_SPEED;
+ * status_num=1;
+ * break;
+ * case 'm': //後退
+ * target_R=(-1)*BASIC_SPEED;
+ * target_L=(-1)*BASIC_SPEED;
+ * status_num=2;
+ * break;
+ * case 'k': //右旋回
+ * motorR.stop();
+ * target_R=0;
+ * target_L=BASIC_SPEED;
+ * status_num=3;
+ * break;
+ * case 'j': //左旋回
+ * motorL.stop();
+ * target_R=BASIC_SPEED;
+ * target_L=0;
+ * status_num=4;
+ * break;
+ * default:
+ * break;
+ * }
+ * if(sel=='q'){
+ * break; //qを押したら左右のモーターを停止
+ * }
+ * }
+ * kai++;
+ * }
+ * motorR.stop();
+ * motorL.stop();
+ *
+ * return 0;
+ * }
+ * @endcode
* @section 基本的な速度制御の実用までの流れ
*
* 1. モーター・エンコーダ・モータードライバ・マイコン・バッテリーを適切につなげる