Explorar el Código

转把模式调整;增加gearsensor与uart切换;

Ye Jin hace 1 año
padre
commit
58d4059d35

+ 37 - 25
User project/1.FrameLayer/Source/TimeTask_Event.c

@@ -30,6 +30,7 @@
 #include "display.h"
 #include "bikegearsensor.h"
 #include "adc.h"
+#include "bikespeed.h"
 /******************************
  *
  *  Parameter
@@ -192,19 +193,23 @@ void  Event_1ms(void)
             }
 
             /* Bike Throttle Assist Iqref Ramp */
-            if(Event_pvt_swIqRef< Event_pvt_swIqRefTarget - 100)
+            if(Event_pvt_swIqRef< Event_pvt_swIqRefTarget - 30)
             {
-                if(Event_pvt_swIqRefTarget >= Event_pvt_swIqRefTargetZ1)
-                {
-                    Event_pvt_swIqRef += 100;
-                }               
+//                if(Event_pvt_swIqRefTarget >= Event_pvt_swIqRefTargetZ1)
+//                {
+//                    Event_pvt_swIqRef += 100;
+//                }
+                Event_pvt_swIqRef += 30;
+            }
+            else if(Event_pvt_swIqRef > Event_pvt_swIqRefTarget + 40)
+            {
+                Event_pvt_swIqRef -= 40;
             }
-            else
             {
                 Event_pvt_swIqRef = Event_pvt_swIqRefTarget;
             }
             Event_pvt_swIqRefTargetZ1 = Event_pvt_swIqRefTarget;
-            uart_swTorqRefNm = Event_pvt_swIqRef * ass_stCalIn.swDirection;
+            uart_swTorqRefNm = Event_pvt_swIqRef * ass_stCalIn.swDirection * bike_pvt_stCurLpf.slY.sw.hi >> 12;
         }
         Event_pvt_blBikeThroFlgZ1 = Event_pvt_blBikeThroFlg;
         
@@ -341,7 +346,7 @@ void  Event_20ms(void)
     /* MCU Self Check */
     stl_voDoRunTimeChecks();
 }
-
+UWORD uwThrottlePercent;
 void Event_100ms(void)
 {
     SWORD swIqLowerPu;
@@ -378,27 +383,34 @@ void Event_100ms(void)
 //                Event_pvt_uwBikeSpdRefTarget = (UWORD)BIKESPEED_KMPERH2FREQPU * 6; // Q20
 //            }
 //            else
+            uwThrottlePercent = bikethrottle_stBikeThrottleOut.uwThrottlePercent ;
+            if(uwThrottlePercent > 890)
             {
-                Event_pvt_uwBikeSpdRefTarget = (UWORD)((((ULONG)25 - (ULONG)4) *(bikethrottle_stBikeThrottleOut.uwThrottlePercent - 200)/690 + 4) * BIKESPEED_KMPERH2FREQPU); // Q20   
+                uwThrottlePercent = 890;               
             }
             
-            /* Bike Speed Ref Ramp */
-            if(Event_pvt_uwBikeSpdRef < Event_pvt_uwBikeSpdRefTarget - 80)
-            {   
-                if(Event_pvt_uwBikeSpdRefTarget >= Event_pvt_uwBikeSpdRefTargetZ1)
-                {
-                    Event_pvt_uwBikeSpdRef += 80;
-                }             
-            }
-            else if(Event_pvt_uwBikeSpdRef > Event_pvt_uwBikeSpdRefTarget + 160)
             {
-                Event_pvt_uwBikeSpdRef -= 160;
-            }               
-            else
-            {
-                Event_pvt_uwBikeSpdRef = Event_pvt_uwBikeSpdRefTarget;
-            }           
-            Event_pvt_uwBikeSpdRefTargetZ1 = Event_pvt_uwBikeSpdRefTarget;
+                Event_pvt_uwBikeSpdRefTarget = (UWORD)((((ULONG)25 - (ULONG)4) *(uwThrottlePercent - 200)/690 + 4) * BIKESPEED_KMPERH2FREQPU); // Q20   
+            }
+            
+            /* Bike Speed Ref Ramp */
+//            if(Event_pvt_uwBikeSpdRef < Event_pvt_uwBikeSpdRefTarget - 80)
+//            {   
+//                if(Event_pvt_uwBikeSpdRefTarget >= Event_pvt_uwBikeSpdRefTargetZ1)
+//                {
+//                    Event_pvt_uwBikeSpdRef += 80;
+//                }             
+//            }
+//            else if(Event_pvt_uwBikeSpdRef > Event_pvt_uwBikeSpdRefTarget + 160)
+//            {
+//                Event_pvt_uwBikeSpdRef -= 160;
+//            }               
+//            else
+//            {
+//                Event_pvt_uwBikeSpdRef = Event_pvt_uwBikeSpdRefTarget;
+//            }           
+//            Event_pvt_uwBikeSpdRefTargetZ1 = Event_pvt_uwBikeSpdRefTarget;
+            Event_pvt_uwBikeSpdRef = Event_pvt_uwBikeSpdRefTarget;
             
             /* Bike Speed Closed Loop */
             swIqLowerPu = (SWORD)((flx_stCtrlOut.swIqLimPu < ABS(pwr_stPwrLimOut2.swIqLimPu)) ? flx_stCtrlOut.swIqLimPu : ABS(pwr_stPwrLimOut2.swIqLimPu));  

+ 1 - 1
User project/3.BasicFunction/Include/AssistCurve.h

@@ -70,7 +70,7 @@
 
 #define ASS_LINER_TORQUE_DEFAULT             \
     {                                  \
-        2048, 2867, 4096, 6144, 2867 \
+        2048, 2867, 4096, 10000, 2867 \
     } // Q12
 //#define TORQUE_ASSIST_DEFAULT                                                                                                                      \
 //    {                                                                                                                                              \

+ 2 - 0
User project/3.BasicFunction/Include/bikespeed.h

@@ -16,6 +16,7 @@
 #define BIKESPEED_H
 
 #include "typedefine.h"
+#include "mathtool.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -151,6 +152,7 @@ extern BIKESPEED_COF bikespeed_stFreGetCof;
 extern BIKESPDPI_OUT bikespeed_stPIOut;
 extern BIKESPDPI_IN  bikespeed_stPIIn;
 extern BIKESPEED_OUT bikespeed_stFreGetOut;
+extern LPF_OUT bike_pvt_stCurLpf;
 /***************************************
  *
  *          Function  Definations

+ 3 - 1
User project/3.BasicFunction/Source/bikegearsensor.c

@@ -81,7 +81,9 @@ void bikegearsensor_voBikeGearsensorDetect(void)
             bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt = 0;
         }
     }
-
+#if (GEARSENSOR_ENABLE == 0)
+    bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg = FALSE;
+#endif
 }
 /***************************************************************
  Function: bikegearsensor_blBikeGetState;

+ 112 - 70
User project/3.BasicFunction/Source/bikespeed.c

@@ -14,6 +14,7 @@
  Compiler Directives:
 *************************************************************************/
 #include "syspar.h"
+#include "mathtool.h"
 #include "bikespeed.h"
 #include "CodePara.h"
 #include "api.h"
@@ -30,6 +31,7 @@ BIKESPEED_OUT bikespeed_stFreGetOut = BIKESPEED_OUT_DEFAULT;
 BIKESPDPI_IN bikespeed_stPIIn;
 static BIKESPDPI_COF  bikespeed_stPICof;
 BIKESPDPI_OUT bikespeed_stPIOut;
+LPF_OUT bike_pvt_stCurLpf;
 
 static ULONG bikespeed_pvt_FreqPu = 0;
 /***************************************************************
@@ -302,6 +304,7 @@ void bikespeed_voBikeSpeedInit(void)
     bikespeed_stFreGetOut.uwBikespeedPwrErrorCnt = 0;
     bikespeed_stFreGetOut.uwBikespeedPwrRecoverCnt = 0;
     bikespeed_stFreGetOut.uwCaputureOverflowMinCntTest = 0;
+    mth_voLPFilterCoef(1000000 / 25, EVENT_1MS_HZ/100, &bike_pvt_stCurLpf.uwKx); //100Hz
 }
 
 /***************************************************************
@@ -369,6 +372,7 @@ void bikespeed_voPICoef(void)
  Subroutine Call: N/A
  Reference: N/A
 ****************************************************************/
+UWORD uwBikeSpeedGain;
 void bikespeed_voPI(const BIKESPDPI_IN *in, BIKESPDPI_OUT *out)
 {
     SLONG  slIqMaxPu, slIqMinPu;  // Q30
@@ -405,75 +409,78 @@ void bikespeed_voPI(const BIKESPDPI_IN *in, BIKESPDPI_OUT *out)
     {
     /* Nothing */
     }
-
-    bikespeed_stPICof.uwKpPu = 25000; 
-    if(((SWORD)ABS(out->slErrorZ1) - (SWORD)ABS(slSpdErrPu)) > 20)   //Fast Approach
-    {
-        bikespeed_stPICof.uwKiPu = 0; 
-        
-        if(slSpdErrPu < 0 && slSpdErrPu > (SWORD)-3 * BIKESPEED_KMPERH2FREQPU)
-        {
-            bikespeed_stPICof.uwKpPu = 6250;
-            bikespeed_stPICof.uwKiPu = 200;
-        }
-        else if(slSpdErrPu <= (SWORD)-3 * BIKESPEED_KMPERH2FREQPU)
-        {
-            bikespeed_stPICof.uwKpPu = 6250;
-            bikespeed_stPICof.uwKiPu = 400;
-        }
-        else
-        {
-        	//do nothing
-        }
-    }
-    else if(((SWORD)ABS(out->slErrorZ1) - (SWORD)ABS(slSpdErrPu)) > 0) //Fast Approach
-    {
-        if(in->slSpdFdkPu<500)
-        {
-            bikespeed_stPICof.uwKiPu = 500;
-        }
-        else
-        {
-            bikespeed_stPICof.uwKiPu = 1000; 
-        }
-        
-        if(slSpdErrPu < 0 && slSpdErrPu > (SWORD)-3 * BIKESPEED_KMPERH2FREQPU)
-        {
-            bikespeed_stPICof.uwKpPu = 6250;
-            bikespeed_stPICof.uwKiPu = 200;
-        }
-        else if(slSpdErrPu <= (SWORD)-3 * BIKESPEED_KMPERH2FREQPU)
-        {
-            bikespeed_stPICof.uwKpPu = 6250;
-            bikespeed_stPICof.uwKiPu = 400;
-        }
-        else
-        {
-        	//do nothing
-        }
-    }
-    else  //Away
-    {
-        if(in->slSpdFdkPu<500)
-        {
-            bikespeed_stPICof.uwKiPu = 500;
-        }
-        else
-        {
-            bikespeed_stPICof.uwKiPu = 3000; 
-        }
-            
-        if(slSpdErrPu > (0 * BIKESPEED_KMPERH2FREQPU) && slSpdErrPu <= (3 * BIKESPEED_KMPERH2FREQPU))
-        {
-            bikespeed_stPICof.uwKiPu  = 0;
-        }
-    }
-    
-    if(in->slSpdFdkPu >= (27 * BIKESPEED_KMPERH2FREQPU))
-    {
-        bikespeed_stPICof.uwKiPu  = 6000;
-    }
     
+    bikespeed_stPICof.uwKpPu = 10000; 
+    bikespeed_stPICof.uwKiPu = 20000; 
+
+//    bikespeed_stPICof.uwKpPu = 25000; 
+//    if(((SWORD)ABS(out->slErrorZ1) - (SWORD)ABS(slSpdErrPu)) > 20)   //Fast Approach
+//    {
+//        bikespeed_stPICof.uwKiPu = 0; 
+//        
+//        if(slSpdErrPu < 0 && slSpdErrPu > (SWORD)-3 * BIKESPEED_KMPERH2FREQPU)
+//        {
+//            bikespeed_stPICof.uwKpPu = 6250;
+//            bikespeed_stPICof.uwKiPu = 200;
+//        }
+//        else if(slSpdErrPu <= (SWORD)-3 * BIKESPEED_KMPERH2FREQPU)
+//        {
+//            bikespeed_stPICof.uwKpPu = 6250;
+//            bikespeed_stPICof.uwKiPu = 400;
+//        }
+//        else
+//        {
+//        	//do nothing
+//        }
+//    }
+//    else if(((SWORD)ABS(out->slErrorZ1) - (SWORD)ABS(slSpdErrPu)) > 0) //Fast Approach
+//    {
+//        if(in->slSpdFdkPu<500)
+//        {
+//            bikespeed_stPICof.uwKiPu = 500;
+//        }
+//        else
+//        {
+//            bikespeed_stPICof.uwKiPu = 1000; 
+//        }
+//        
+//        if(slSpdErrPu < 0 && slSpdErrPu > (SWORD)-3 * BIKESPEED_KMPERH2FREQPU)
+//        {
+//            bikespeed_stPICof.uwKpPu = 6250;
+//            bikespeed_stPICof.uwKiPu = 200;
+//        }
+//        else if(slSpdErrPu <= (SWORD)-3 * BIKESPEED_KMPERH2FREQPU)
+//        {
+//            bikespeed_stPICof.uwKpPu = 6250;
+//            bikespeed_stPICof.uwKiPu = 400;
+//        }
+//        else
+//        {
+//        	//do nothing
+//        }
+//    }
+//    else  //Away
+//    {
+//        if(in->slSpdFdkPu<500)
+//        {
+//            bikespeed_stPICof.uwKiPu = 500;
+//        }
+//        else
+//        {
+//            bikespeed_stPICof.uwKiPu = 3000; 
+//        }
+//            
+//        if(slSpdErrPu > (0 * BIKESPEED_KMPERH2FREQPU) && slSpdErrPu <= (3 * BIKESPEED_KMPERH2FREQPU))
+//        {
+//            bikespeed_stPICof.uwKiPu  = 0;
+//        }
+//    }
+//    
+//    if(in->slSpdFdkPu >= (27 * BIKESPEED_KMPERH2FREQPU))
+//    {
+//        bikespeed_stPICof.uwKiPu  = 6000;
+//    }
+//    
     sqIqpPu = ((SQWORD)slDeltaErrPu * bikespeed_stPICof.uwKpPu) << 4; // Q30     
     sqIqiPu = (SQWORD)slSpdErrPu * bikespeed_stPICof.uwKiPu ; // Q30
     sqIqRefPu = sqIqpPu + sqIqiPu + (SQWORD)out->slIqRefPu; // Q30
@@ -490,8 +497,43 @@ void bikespeed_voPI(const BIKESPDPI_IN *in, BIKESPDPI_OUT *out)
     {
         out->slIqRefPu = (SLONG)sqIqRefPu;
     }
-
-    out->swIqRefPu = (SWORD)(out->slIqRefPu >> 16); // Q30-Q16=Q14
+    
+    if (in->slSpdFdkPu <= 33*BIKESPEED_KMPERH2FREQPU)
+    {
+        uwBikeSpeedGain = Q12_1; // Q12
+        
+    }
+    else if (in->slSpdFdkPu > 33*BIKESPEED_KMPERH2FREQPU && in->slSpdFdkPu <= 37*BIKESPEED_KMPERH2FREQPU)
+    {
+        uwBikeSpeedGain  =
+            Q12_1 -
+            ((((SQWORD)in->slSpdFdkPu - (SQWORD)33*BIKESPEED_KMPERH2FREQPU ) * (SQWORD)ass_stCurLimCoef.ulBikeSpdDeltInv) >> 9); // Q12
+    }
+    else
+    {
+        uwBikeSpeedGain  = 0;
+    }
+    mth_voLPFilter(uwBikeSpeedGain, &bike_pvt_stCurLpf); 
+    
+//    if (in->slSpdFdkPu <= 33*BIKESPEED_KMPERH2FREQPU)
+//    {
+//        uwBikeSpeedGain = Q12_1; // Q12
+//        
+//    }
+//    else if (in->slSpdFdkPu > 33*BIKESPEED_KMPERH2FREQPU && in->slSpdFdkPu <= 37*BIKESPEED_KMPERH2FREQPU)
+//    {
+//        uwBikeSpeedGain  =
+//            Q12_1 -
+//            ((((SQWORD)in->slSpdFdkPu - (SQWORD)33*BIKESPEED_KMPERH2FREQPU ) * (SQWORD)ass_CurLimCoef.ulBikeSpdDeltInv) >> 9); // Q12
+//    }
+//    else
+//    {
+//        uwBikeSpeedGain  = 0;
+//    }
+//    mth_voLPFilter(uwBikeSpeedGain, &bike_pvt_stCurLpf); 
+ 
+//    out->swIqRefPu = (SWORD)(out->slIqRefPu >> 16); // Q30-Q16=Q14
+    out->swIqRefPu = ((SLONG)BIKE_ASS_MOTOR_CURRENT_MAX * in->slSpdRefPu /4750 << 14) / IBASE ;
     out->slErrorZ1 = slSpdErrPu;
 }
 /*************************************************************************

+ 2 - 0
User project/3.BasicFunction/Source/canAppl.c

@@ -31,6 +31,7 @@
 #include "fp.def"
 #include "queue.h"
 #include "api.h"
+#include "bikethrottle.h"
 /******************************
  *
  *  Parameter
@@ -619,6 +620,7 @@ void Can_voMC_Run_200ms(void)
         MC_RunInfoToCDL.RS[0] = scm_swIdFdbLpfPu;
         MC_RunInfoToCDL.RS[1] = scm_swIqFdbLpfPu;
         MC_RunInfoToCDL.RS[2] = ass_stCalOut.swTorAss2CurrentTemp;
+        MC_RunInfoToCDL.RS[3] = bikethrottle_stBikeThrottleOut.uwThrottlePercent;
         SendData(ID_MC_TO_CDL, MODE_REPORT, 0xBA20, (UBYTE *)&MC_RunInfoToCDL.SysStatus);
     }
 

+ 6 - 1
User project/4.BasicHardwSoftwLayer/1.BasicHardwLayer/Source/hwsetup.c

@@ -276,10 +276,15 @@ void hw_voInitGPIO(void)
     gpio_pin_remap_config(GPIO_TIMER2_FULL_REMAP,ENABLE);
     gpio_init(GPIOC,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ, GPIO_PIN_9);  /* TIM2_CH3: 70KHz For Torque Sensor*/   
 
+#if GEARSENSOR_ENABLE
+    gpio_init(GPIOC,GPIO_MODE_IPU,GPIO_OSPEED_50MHZ,GPIO_PIN_10); /* Gear sensor*/    
+    
+    gpio_init(GPIOC,GPIO_MODE_IPU,GPIO_OSPEED_50MHZ,GPIO_PIN_11); 
+#else
     gpio_init(GPIOC,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_10); /* UART3_TX*/    
     
     gpio_init(GPIOC,GPIO_MODE_IN_FLOATING,GPIO_OSPEED_50MHZ,GPIO_PIN_11); /* UART3_RX */
-    
+#endif
 //    gpio_init(GPIOC,GPIO_MODE_OUT_PP,GPIO_OSPEED_50MHZ, GPIO_PIN_10);  // test       
 //    
 //    gpio_init(GPIOC,GPIO_MODE_OUT_PP,GPIO_OSPEED_50MHZ, GPIO_PIN_11);  // test   

+ 2 - 1
User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Include/user.h

@@ -47,7 +47,8 @@ Update Time
 #define MOTOR_WELLING_CITY_48V    0x30
 #define MOTOR_WELLING_MTB_48V     0x31
 
-#define MOTOR_ID_SEL              MOTOR_WELLING_MTB_36V   
+#define MOTOR_ID_SEL              MOTOR_WELLING_MTB_36V  
+#define GEARSENSOR_ENABLE         0 //0-Uart,1-GearSensor
 
 //#define TEST  //only use for testing
 

+ 3 - 3
User project/5.Api_rt/profiler.c

@@ -93,7 +93,7 @@ void profiler_bg()
             int32_t delta = ticks - ProfilerBuffer.counter;
             if(delta<0)
             {
-                delta+=72000;
+                delta+=1000;
             }
             ProfilerTime[0] += delta;
             ProfilerBuffer.counter = ticks;
@@ -138,7 +138,7 @@ void  profiler_start(uint8_t lv)
     int32_t delta = ticks - ProfilerBuffer.counter;
     if(delta<0)
     {
-        delta+=72000;
+        delta+=1000;
     }
     ProfilerTime[ProfilerStack[ProfilerSp - 1]] += delta;
     ProfilerCounts[lv] += 1;
@@ -170,7 +170,7 @@ void profiler_end(uint8_t lv)
     int32_t delta = ticks - ProfilerBuffer.counter;
     if(delta<0)
     {
-        delta+=72000;
+        delta+=1000;
     }
     ProfilerTime[ProfilerStack[ProfilerSp - 1]] += delta;
     ProfilerSp -= 1;

+ 1 - 1
WLMCP_PACKED.ewp

@@ -652,7 +652,7 @@
                 <option>
                     <name>OOCOutputFormat</name>
                     <version>3</version>
-                    <state>1</state>
+                    <state>3</state>
                 </option>
                 <option>
                     <name>OCOutputOverride</name>