UVW 3 phases Brushless DC motor control
Dependencies: QEI mbed-rtos mbed
Fork of BLDCmotor by
Revision 14:8e205264baa8, committed 2013-06-13
- Comitter:
- kosakaLab
- Date:
- Thu Jun 13 06:41:16 2013 +0000
- Parent:
- 13:791e20f1af43
- Child:
- 15:427f5ae8e957
- Commit message:
- BLDCmotor;
Changed in this revision
--- a/controller.cpp Sun Mar 03 09:09:34 2013 +0000
+++ b/controller.cpp Thu Jun 13 06:41:16 2013 +0000
@@ -145,7 +145,8 @@
void current_loop(){ // 電流制御マイナーループ
float th, c, s, Cdq[2][2], iu, iv, iab[2], idq_act[2], vab_ref[2], tmp, prev[2];
if( f_find_origin==1 ){
- th = 0;
+// th = 0;
+ th = debug[2];
}else{
th = p.th[0];
}
@@ -287,6 +288,7 @@
duty_u = p.vuvw[0]/vdqMAX+0.5; // dutyを計算
duty_v = p.vuvw[1]/vdqMAX+0.5; // dutyを計算
duty_w = p.vuvw[2]/vdqMAX+0.5; // dutyを計算
+duty_u*=5;duty_v*=5;duty_w*=5;//koko
uvw[0].duty = duty_u; // dutyをPWM発生関数に渡す
uvw[1].duty = duty_v; // dutyをPWM発生関数に渡す
uvw[2].duty = duty_w; // dutyをPWM発生関数に渡す
@@ -419,14 +421,15 @@
// モータシミュレータ
sim_motor(); // IPM, dq座標
#else
-//koko p.th[0] = (float)encoder.getPulses()/(float)N_ENC*2.0*PI; // get angle [rad] from encoder
- // 位置θをセンサで検出
#ifdef DOUKI
led1=1;
p.th[0] += 2*PI*TS0 * 1; if(p.th[0]>4*PI){ p.th[0]-=4*PI;}
debug[0]=p.th[0]/PI*180;
analog_out=debug[0]/180*PI/4/PI;
led1=0;
+#else
+ // 位置θをセンサで検出
+ p.th[0] = (float)encoder.getPulses()/(float)N_ENC*2.0*PI; // get angle [rad] from encoder
#endif
#endif
current_loop(); // 電流制御マイナーループ(idq_ref to vuvw)
--- a/controller.h Sun Mar 03 09:09:34 2013 +0000
+++ b/controller.h Thu Jun 13 06:41:16 2013 +0000
@@ -4,7 +4,7 @@
//#define PI 3.14159265358979 // def. of PI
/*********** User setting for control parameters (begin) ***************/
#define SIMULATION // Comment this line if not simulation
-#define USE_CURRENT_CONTROL // Current control on. Comment if current control off.
+//#define USE_CURRENT_CONTROL // Current control on. Comment if current control off.
#define DEADZONE_PLUS 1. // deadzone of plus side
#define DEADZONE_MINUS -1.5 // deadzone of minus side
// encoder
@@ -26,7 +26,7 @@
// Thread ThreadTimerTS3(CallTimerTS3,NULL,osPriorityBelowNormal);
// Thread ThreadTimerTS4(CallTimerTS4,NULL,osPriorityLow);
#define TMAX 3.0 // [s], experiment starts from 0[s] to TMAX[s]
-#define TMAX_FIND_ORIGIN 0.1//1.0 // [s], finding th origin starts from 0[s] to TMAX[s]
+#define TMAX_FIND_ORIGIN 30//0.1//1.0 // [s], finding th origin starts from 0[s] to TMAX[s]
// 電流制御マイナーループ
#define iKPd 10./2 // 電流制御d軸PIDのPゲイン (d-axis)
@@ -36,7 +36,7 @@
#define iKIq 100./2 // 電流制御q軸PIDのIゲイン (q-axis)
#define iKDq 0 // 電流制御q軸PIDのDゲイン (q-axis)
-#define vdqMAX 300.
+#define vdqMAX 3.3 // Vcc
#define SQRvdqMAX (vdqMAX*vdqMAX) // [V^2] vdqの大きさの最大値の二乗
// 速度制御メインループ
@@ -51,7 +51,7 @@
#endif
#define iLPF 0.9 // 0-1, 速度に対する1次LPF; Low Pass Filter, G(z)=(1-a)/(z-a)
-#define iqMAX 100 // [A], q軸電流指令のMAX制限(異常に大きい指令値を制限する)
+#define iqMAX 4//100 // [A], q軸電流指令のMAX制限(異常に大きい指令値を制限する)
/*********** User setting for control parameters (end) ***************/
@@ -117,6 +117,6 @@
extern velocity_loop_parameters vl; // 速度制御メインループの定数、変数
extern float data[][5]; // memory to save data offline instead of "online fprintf".
-extern unsigned short _count_data; // counter for data[1000][5]
-
+extern unsigned short _count_data; // counter for data[1000][5]
+extern float debug[20]; // for debug
#endif
\ No newline at end of file
--- a/main.cpp Sun Mar 03 09:09:34 2013 +0000
+++ b/main.cpp Thu Jun 13 06:41:16 2013 +0000
@@ -79,7 +79,8 @@
// osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority
// 指令速度
- float w_ref_req[2] = {20* 2*PI, 40* 2*PI}; // [rad/s](第2要素は指令速度急変後の指令速度)
+// float w_ref_req[2] = {20* 2*PI, 40* 2*PI}; // [rad/s](第2要素は指令速度急変後の指令速度)
+ float w_ref_req[2] = {0.5* 2*PI, 0.5* 2*PI}; // [rad/s](第2要素は指令速度急変後の指令速度)
// 指令dq電流位相
float beta_ref = 30*PI/180; // [rad], 電流位相指令βを30度に
float tan_beta_ref1;
@@ -117,6 +118,8 @@
il.idq_ref[0] = iqMAX/1.0; // idをプラス、iqをゼロにして、
il.idq_ref[1] = 0; // 無負荷のときにθ=0とさせる。
+//pc2.scanf("%f",&debug[2]);
+debug[2]=3*2*PI*t*1;
#ifdef OLD
timerTS0();
//current_loop(); // 電流制御マイナーループ(idq_ref to vuvw)
--- a/mbed-rtos.lib Sun Mar 03 09:09:34 2013 +0000 +++ b/mbed-rtos.lib Thu Jun 13 06:41:16 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#9654a71f5a90 +http://mbed.org/users/mbed_official/code/mbed-rtos/#58b30ac3f00e
