Mechatro5 / Motor

Dependents:   Programs LINE_TRACE_CAR

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers motor.h Source File

motor.h

00001 #ifndef _MOTOR_H_
00002 #define _MOTOR_H_
00003 
00004 #include "mbed.h"
00005 
00006 class Motor //モータクラス
00007 {
00008     public:
00009     const float PWM_FREQ;               //PWM周波数
00010     const float MEASUREMENT_INTERVAL;   //計測周期
00011     const int   SLIT;                   //PGセンサスリット数
00012     const float KP;                     //フィードバックパラメータ(比例)
00013     const float KI;                     //フィードバックパラメータ(積分)
00014     const float KD;                     //フィードバックパラメータ(微分)
00015     
00016     private:
00017     PwmOut     pwm;         //PWM出力
00018     DigitalOut phase;       //モータ回転方向(正転=1)
00019     int        counter;     //RPMカウンタ
00020     float      target;      //目標回転数
00021     float      target_pre;  //ひとつ前の目標回転数
00022     float      rpm;         //現在の回転数
00023     float      error_pre1;  //ひとつ前の偏差
00024     float      error_pre2;  //ふたつ前の偏差
00025     float      duty;        //設定duty比
00026     float      MV;          //操作量
00027     void       calc_rpm();  //回転数計測
00028     
00029     public:
00030     Motor(PinName pwm_pin, PinName phase_pin);
00031     void  Set_phase(const int _phase);
00032     void  Set_target(const float _target);
00033     float Get_rpm();
00034     float Get_estimated_duty(float target_rpm);
00035     void  count();
00036     void  drive();
00037 };
00038 
00039 #endif