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.
SCforMatlab.h
- Committer:
- mrtkhmbed
- Date:
- 2021-02-17
- Revision:
- 4:40c5308a8d0d
- Parent:
- 0:0b57d295ca56
File content as of revision 4:40c5308a8d0d:
#ifndef _INCLUDE_MOTORMEASURE_H_
#define _INCLUDE_MOTORMEASURE_H_
#define MEASURE_CW 0
#define MEASURE_CCW 1
#define GEER 1.0 //回転を制御したい軸とエンコーダーの付いてる軸が異なる場合に
class SCforMatlab //制御周期が0.01s以上を想定。それ以上細かい制御周期では使えない
{
private:
////////////////////////////////
int size;
float duty;
float delta_t;
int save_count;
int duty_count;
float turn_time;
// float *omega; //Matlab用に出力を記録。fが正転の測定分でbが逆転の測定分
// float *input_duty; //Matlab用に入力を記録
float omega[3500]; //Matlab用に出力を記録
float input_duty[3500]; //Matlab用に入力を記録
float least_squares[18][2]; //最小二乗法用に測定(データは0~0.8取得しているが計算では指定した範囲(デフォルト0.1~0.7)を使う)
int measure_mode; //正転計測時0で逆転計測時1
Ec *ec_;
////////////////////////////////速度制御のC値,D値計算周り。
float start_cal;
float end_cal;
float cf_;
float df_;
float cb_;
float db_;
public:
PwmOut forward;
PwmOut back;
Ticker ticker_;
SCforMatlab(PinName pwm_F,PinName pwm_B,float period_us,Ec &ec,float dt);//dtには速度制御(Sc)を実際に使うときに繰り返す周期を入れる(0.05とか0.01とか)
void saveOmega();
void motorTurn(float out);
void measureTurn();
void showOmega();
////////////////////////////////////////////////////////////////C,D値計算周りの関数
void setCDRange(float start,float end);//最小二乗法に使う範囲を0.05刻みで決める
void calC_Dvalue();//速度制御のC値,D値を計算して表示してくれる。
////////////////////////////////////////////////////////////////////
void measureMotor();/////測定し、結果がprintfされる。
//////////////////////////使い方///////////////////////////////////////
//1:まずエンコーダーとモーターの向きを合わせる。pwm_Fピンから入力したときにエンコーダーが増えてく方向推奨。
//2:measureMotor()を一回処理するとモーターが回って、測定が始まる
//3:出てきたデータを全部エクセルなどにコピペ(Matlabに取り込むときにエクセルファイルである必要があるので)
//////出てきたデータについて
//////まずMatlab用の入出力データが表示される。最後にSpeedControllerライブラリで必要なC,D値が出力される。
//////記録の意味もあるのでエクセルに全部コピペ推奨ですが、最後のSC用の部分はMatlabでは使わないです。
//4:MatlabでPIDの係数を算出する。
//5:以上でSC用のC,D値とPIDの係数が算出される。
};
#endif