distribution-201229

Dependencies:   mbed FastPWM

Revision:
63:3c6869477483
Parent:
62:b5452adfb2cd
Child:
64:6f1caa0993d0
--- a/main.cpp	Fri Apr 03 11:44:01 2020 +0000
+++ b/main.cpp	Fri Apr 03 12:48:42 2020 +0000
@@ -81,7 +81,7 @@
 extern int CID_TX_VOUT;
 extern int CID_TX_VALVE_POSITION;
 
-MatrixXd Input = MatrixXd::Zero(1,6);     //input
+MatrixXd Input = MatrixXd::Zero(1,22);     //input
 MatrixXd h1 = MatrixXd::Zero(22,32);
 MatrixXd h2 = MatrixXd::Zero(32,32);
 MatrixXd h3 = MatrixXd::Zero(32,32);
@@ -94,9 +94,8 @@
 
 MatrixXd X;
 ArrayXf Y;
-//ArrayXf NNoutput = ArrayXf::Zero(1,1);
 float NNoutput;
-float input_array[4] ={0.0f};
+float input_array[6] ={0.0f};
 float position_array[10] = {0.0f};
 
 
@@ -235,12 +234,9 @@
         else
             ID_index_array[i] =  (i+1) * 0.5f;
     }
-
-
     
-
     Input <<
-       0.052414,0.066907,0.085407,0.109023,0.139169,0.177651;
+       0.052414,0.066907,0.085407,0.109023,0.139169,0.177651,0.052414,0.066907,0.085407,0.109023,0.139169,0.177651,0.052414,0.066907,0.085407,0.109023,0.139169,0.177651,0.052414,0.066907,0.085407,0.109023;
 
 
     h1 <<
@@ -492,13 +488,13 @@
         }
         timer_while ++;
         
-        t.reset();
-        t.start();
+        //t.reset();
+        //t.start();
         
         
         
-        Input <<
-        input_array[0],input_array[1],input_array[2],input_array[3],input_array[4];
+//        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++){
@@ -518,26 +514,29 @@
         X = X*hout+bout.transpose();
         NNoutput=1.0f/(1.0f+exp(-X(0,0)));
         
-        t.stop();
+        //t.stop();
+        
         printf("NNoutput : %f\n", NNoutput);
         printf("time : %f\n", t.read());
-        wait(1);
         
+        //wait(1);
+        
+        CAN_TX_PWM((int16_t) 78); //1500
         
-        PWM_out = NNoutput * 24000.0f - 12000.0f;
-
-
-        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);
+//        PWM_out = NNoutput * 24000.0f - 12000.0f;
+//
+//
+//        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);
         
         
         
@@ -676,14 +675,14 @@
             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;
-        } 
+//        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) {