tr

Dependencies:   mbed CANMsg

Revision:
10:d85ed006056e
Parent:
9:503e2aba047c
Child:
11:21e990eb31d0
--- a/main.cpp	Tue Oct 02 07:05:52 2018 +0000
+++ b/main.cpp	Thu Dec 27 13:43:31 2018 +0000
@@ -209,7 +209,7 @@
     double TBper=0.0f;
     if (aspettaStart==0){
         if (perio<250.0f){perio=500.0f;}
-        double scala =0.0f;
+        double scala =1.0f;
         if (lowSpeed==1){
             scala =2.0f;
         }else{
@@ -331,38 +331,43 @@
     // 1    0   1       1/128
     // 0    1   1       1/10
     // 1    1   1       1/20
-    if (TBmotorSteps==400){
+    if (TBmotorSteps==400.0f){
+        TBmotor_M1=0;
+        TBmotor_M2=0;
+        TBmotor_M3=0;
+    }else if (TBmotorSteps==1600.0f){
+        TBmotor_M1=0;
+        TBmotor_M2=0;
+        TBmotor_M3=1;
+    }else if (TBmotorSteps==3200.0f){
+        TBmotor_M1=0;
+        TBmotor_M2=1;
+        TBmotor_M3=0;
+    }else if (TBmotorSteps==6400.0f){
         TBmotor_M1=1;
         TBmotor_M2=1;
-        TBmotor_M3=1;
-    }else if (TBmotorSteps==1600){
+        TBmotor_M3=0;
+    }else if (TBmotorSteps==12800.0f){
         TBmotor_M1=0;
-        TBmotor_M2=1;
+        TBmotor_M2=0;
         TBmotor_M3=1;
-    }else if (TBmotorSteps==3200){
+    }else if (TBmotorSteps==25600.0f){
         TBmotor_M1=1;
         TBmotor_M2=0;
         TBmotor_M3=1;
-    }else if (TBmotorSteps==6400){
+    }else if (TBmotorSteps==2000.0f){
         TBmotor_M1=0;
-        TBmotor_M2=0;
+        TBmotor_M2=1;
         TBmotor_M3=1;
-    }else if (TBmotorSteps==12800){
+    }else if (TBmotorSteps==4000.0f){
         TBmotor_M1=1;
         TBmotor_M2=1;
-        TBmotor_M3=0;
-    }else if (TBmotorSteps==25600){
-        TBmotor_M1=0;
-        TBmotor_M2=1;
-        TBmotor_M3=0;
-    }else if (TBmotorSteps==2000){
+        TBmotor_M3=1;
+    }else{
+        // set dei 1600 passi
         TBmotor_M1=1;
         TBmotor_M2=0;
         TBmotor_M3=0;
-    }else if (TBmotorSteps==4000){
-        TBmotor_M1=0;
-        TBmotor_M2=0;
-        TBmotor_M3=0;
     }
     TBmotorRst=0;
 }
@@ -441,10 +446,10 @@
 #if defined(speedMaster)
     void upDateSincro(){
         char val1[8]={0,0,0,0,0,0,0,0};
-        val1[3]=(posForQuinc /0x00FF0000)&0x000000FF;
-        val1[2]=(posForQuinc /0x0000FF00)&0x000000FF;
-        val1[1]=(posForQuinc /0x000000FF)&0x000000FF;
-        val1[0]=posForQuinc & 0x000000FF;
+        val1[0]=(posForQuinc /0x00FF0000)&0x000000FF;
+        val1[1]=(posForQuinc /0x0000FF00)&0x000000FF;
+        val1[2]=(posForQuinc /0x000000FF)&0x000000FF;
+        val1[3]=posForQuinc & 0x000000FF;
         //double pass = tractorSpeed_MtS_timed*100.0f;
         double pass = speedOfSeedWheel*100.0f;
         val1[4]=(uint8_t)(pass)&0x000000FF;
@@ -721,9 +726,10 @@
             }
             if (rxMsg.id==RX_Configure){
                 uint8_t flags = rxMsg.data[0];
-                uint16_t steps = (uint32_t) rxMsg.data[1]*0xFF00;
+                uint16_t steps = (uint32_t) rxMsg.data[1]*0x000000FF;
                 steps = steps + ((uint32_t)rxMsg.data[2]);
-                stepSetting();
+                TBmotorSteps =steps;
+                //stepSetting();
                 cellsCountSet = rxMsg.data[3];
                 if ((flags&0x01)==0x01){
                     if (encoder==false){
@@ -995,6 +1001,7 @@
                 #if !defined(speedMaster)
                     if (quincCnt>=3){
                             if (speedFromMaster>0.0f){
+                                //Questo 
                                 if (enableSimula==0){
                                     tractorSpeed_MtS_timed = speedFromMaster + percento;
                                 }
@@ -1092,7 +1099,7 @@
 
     #if defined(provaStepper)
        TBmotorRst=0;
-       TBticker.attach_us(&step_TBPulseOut,1000.0f);  // clock time are seconds and attach seed motor stepper controls
+       TBticker.attach_us(&step_TBPulseOut,500.0f);  // clock time are seconds and attach seed motor stepper controls
     #endif // end prova stepper
     
     #if defined(canbusActive)
@@ -1916,6 +1923,9 @@
                     TBzeroed=0;
                     timeOutZeroSD.stop();
                     timeOutZeroSD.reset();
+                    DC_brake=1;
+                    DC_prepare();
+                    SDzeroed=1;
                 }
             }