![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
2011
Diff: main.cpp
- Revision:
- 62:b5452adfb2cd
- Parent:
- 61:bc8c8270f0ab
- Child:
- 63:3c6869477483
diff -r bc8c8270f0ab -r b5452adfb2cd main.cpp --- a/main.cpp Fri Apr 03 01:55:08 2020 +0000 +++ b/main.cpp Fri Apr 03 11:44:01 2020 +0000 @@ -81,7 +81,7 @@ extern int CID_TX_VOUT; extern int CID_TX_VALVE_POSITION; -MatrixXd Input = MatrixXd::Zero(1,22); //input +MatrixXd Input = MatrixXd::Zero(1,6); //input MatrixXd h1 = MatrixXd::Zero(22,32); MatrixXd h2 = MatrixXd::Zero(32,32); MatrixXd h3 = MatrixXd::Zero(32,32); @@ -96,7 +96,8 @@ ArrayXf Y; //ArrayXf NNoutput = ArrayXf::Zero(1,1); float NNoutput; - +float input_array[4] ={0.0f}; +float position_array[10] = {0.0f}; // ============================================================================= @@ -239,7 +240,7 @@ Input << - 0.052414,0.066907,0.085407,0.109023,0.139169,0.177651,0.226773,0.289478,0.369522,0.471698,0.052414,0.066907,0.085407,0.109023,0.139169,0.177651,0.226773,0.289478,0.369522,0.471698,0.369522,0.471698; + 0.052414,0.066907,0.085407,0.109023,0.139169,0.177651; h1 << @@ -494,6 +495,11 @@ t.reset(); t.start(); + + + Input << + input_array[0],input_array[1],input_array[2],input_array[3],input_array[4]; + X = Input*h1+b1.transpose(); for(int i=0; i<32; i++){ if(X(i)<0) @@ -513,12 +519,27 @@ NNoutput=1.0f/(1.0f+exp(-X(0,0))); t.stop(); + printf("NNoutput : %f\n", NNoutput); + printf("time : %f\n", t.read()); + wait(1); - printf("NNoutput : %f\n", NNoutput); - printf("time : %f\n", t.read()); + PWM_out = NNoutput * 24000.0f - 12000.0f; + - wait(1); + if (PWM_out>0.0f) { + dtc_v=0.0f; + dtc_w=PWM_out; + } else { + dtc_v=-PWM_out; + dtc_w=0.0f; + } + + //pwm + TIM4->CCR2 = (PWM_ARR)*(1.0f-dtc_v); + TIM4->CCR1 = (PWM_ARR)*(1.0f-dtc_w); + + } } @@ -654,6 +675,15 @@ if (CNT_TMR4 % (int) ((int) FREQ_TMR4/TMR4_FREQ_10k) == 0) { ENC_UPDATE(); } + + for(int i=0; i<10; i++){ + position_array[i] = position_array[i+1]; + } + position_array[10] = (pos.ref/(float)(ENC_PULSE_PER_POSITION)+10.0f)/90.0f; + + for(int i=0; i<5; i++){ + input_array[i] = position_array[2*i+2] - (pos.ref/(float)(ENC_PULSE_PER_POSITION)+10.0f)/90.0f; + } ADC1->CR2 |= 0x40000000; if (SENSING_MODE == 0) { @@ -1719,12 +1749,6 @@ //pwm TIM4->CCR2 = (PWM_ARR)*(1.0f-dtc_v); TIM4->CCR1 = (PWM_ARR)*(1.0f-dtc_w); - - - - - //anotherMatrix = Matrix1 * Matrix2 * Matrix3 * Matrix3 * Matrix4; - if (TMR2_COUNT_CAN_TX % (int) ((int) TMR_FREQ_5k/CAN_FREQ) == 0) { @@ -1778,10 +1802,6 @@ //PWM CAN_TX_PWM((int16_t) cur.sen); //1500 } - if (flag_data_request[3] == LOW) { - //PWM - CAN_TX_PWM((int16_t) 77); //1500 - } //for (i = 0; i < 10000; i++) { // ; // }