Bayley Wang
/
qonly_controller
derp
Diff: main.cpp
- Revision:
- 9:4812c9e932ea
- Parent:
- 8:314074b56470
- Child:
- 10:7624146c5945
- Child:
- 20:b22bf7e14871
--- a/main.cpp Mon Apr 04 09:02:59 2016 +0000 +++ b/main.cpp Tue Apr 05 04:05:21 2016 +0000 @@ -25,7 +25,7 @@ #define I_SCALE (R_BIAS * R_DOWN * I_SCALE_RAW / (R_DOWN * R_UP + R_BIAS * (R_DOWN + R_UP))) #define K_LOOP 0.02 -#define KI_BASE 0.008 +#define KI_BASE 0.08//0.008 #define BUS_VOLTAGE 20.0 #define KP (K_LOOP / BUS_VOLTAGE) @@ -43,7 +43,7 @@ int adval1, adval2; float ia, ib, ic, alpha, beta, q; -double vq = 0.0, q_integral = 0.0, last_q = 0.0, q_ref = 250.0, q_filtered = 0.0; +double vq = 0.0, q_integral = 0.0, last_q = 0.0, q_ref = 0.0, q_filtered = 0.0; extern "C" void TIM1_UP_TIM10_IRQHandler(void) { if (TIM1->SR & TIM_SR_UIF) { @@ -75,9 +75,9 @@ q = -alpha * sin_p - beta * cos_p; q_filtered = 0.1 * (double) q + 0.9 * q_filtered; - DAC->DHR12R2 = (unsigned int) (q_filtered * 20 + 2048); + DAC->DHR12R2 = (unsigned int) (q * 20 + 2048); - double q_err = q_ref - q_filtered; + double q_err = q_ref - q;//_filtered; q_integral += q_err * KI; if (q_integral > INTEGRAL_MAX) q_integral = INTEGRAL_MAX; @@ -86,7 +86,9 @@ vq = KP * q_err + q_integral; if (vq < -1.0f) vq = -1.0f; if (vq > 1.0f) vq = 1.0f; - + + //DAC->DHR12R2 = (unsigned int) (vq * 2000 + 2048); + *a = 0.5f + 0.5f * vq * sinf(p); *b = 0.5f + 0.5f * vq * sinf(p + 2 * PI / 3); *c = 0.5f + 0.5f * vq * sinf(p - 2 * PI / 3); @@ -161,5 +163,9 @@ en = 1; for (;;) { + q_ref = 0.0f; + wait_ms(2000); + q_ref = 20.0f; + wait_ms(2000); } }