Browse Source

提交实时计步和日常计步最新的代码

wentingwei 2 năm trước cách đây
mục cha
commit
d1c8b86394
2 tập tin đã thay đổi với 34 bổ sung31 xóa
  1. 30 29
      detect_step_by_mag.c
  2. 4 2
      detect_step_by_mag.h

+ 30 - 29
detect_step_by_mag.c

@@ -1,13 +1,14 @@
 #include "detect_step_by_mag.h"
 #include "math.h"
 #include "stdlib.h"
-#include "hal_imu.h"
+//#include "hal_imu.h"
 
 #include "nrf_delay.h"
 
 uint16_t mag_sqrt =0;
 //static int16_t ShoeTouchFlag=1;
 
+
 int16_t Get_ShoeTouchFlag(void)
 {
 	return ShoeTouchFlag;
@@ -57,12 +58,16 @@ int32_t Get_RealBackLiftPoint(void)
 
 uint8_t RealTimeStep(int16_t front[3], int16_t back[3], int16_t acc[3])
 {
-	//static int FrontLiftPoint;
-	//static int FrontDropPoint;
-	//static int BackLiftPoint;
-	//static int BackDropPoint;
+	/*
+	static int16_t FKEY=0;
+  static int16_t BKEY=0;
+	static int FrontLiftPoint;
+	static int FrontDropPoint;
+	static int BackLiftPoint;
+	static int BackDropPoint;
+	*/
 	static int32_t SD;
-	//static int16_t Rcounter;
+	//static int16_t Rcounter=0;
 	int32_t mag_temp_front[3];
 	int32_t mag_temp_back[3];
 	static int16_t accZ_buf[4];
@@ -78,6 +83,9 @@ uint8_t RealTimeStep(int16_t front[3], int16_t back[3], int16_t acc[3])
 	float MV;
 	float D;
 	//static int16_t Ucounter=0;//离地计时器
+	//static int FrontLiftDistance;
+  //static int BackLiftDistance;
+	//static int16_t ShoeTouchFlag=1;
 	
 	//SEGGER_RTT_printf(0,"Enter RealTimeStep!\n");
 	Tcounter++;
@@ -133,6 +141,10 @@ uint8_t RealTimeStep(int16_t front[3], int16_t back[3], int16_t acc[3])
 		SEGGER_RTT_printf(0,"mag_back3==:%d...\n",mag_buf_back[2]);
 		SEGGER_RTT_printf(0,"FrontLiftPoint==:%d...\n",FrontLiftPoint);
 		SEGGER_RTT_printf(0,"BackLiftPoint==:%d...\n",BackLiftPoint);
+		SEGGER_RTT_printf(0,"FrontDropPoint==:%d...\n",FrontDropPoint);
+		SEGGER_RTT_printf(0,"BackDropPoint==:%d...\n",BackDropPoint);
+		SEGGER_RTT_printf(0,"FrontLiftDistance==:%d...\n",FrontLiftDistance);
+		SEGGER_RTT_printf(0,"BackLiftDistance==:%d...\n",BackLiftDistance);
 		
 	  /*不断更新前后脚掌磁力计的上升起始点或下降起始点*/
 	  if(mag_buf_front[2] - mag_buf_front[1]>=0)
@@ -206,16 +218,18 @@ uint8_t RealTimeStep(int16_t front[3], int16_t back[3], int16_t acc[3])
 	  }
 		/*判断是否满足FKEY=0和BKEY=0,即是否满足一个升降波形*/
 		
-		if((mag_buf_front[2] - FrontLiftPoint<=1500)||(FrontDropPoint-mag_buf_front[2]>0.45*FrontLiftDistance)) //当磁力计回降到小于上升起点+1000的数值时,FKEY归零,预示前脚波形结束。
+		if((mag_buf_front[2] - FrontLiftPoint<=1500)||((FrontDropPoint-mag_buf_front[2]>0.45*FrontLiftDistance)&&(abs(mag_buf_front[2]-mag_buf_front[1])<500))) //当磁力计回降到小于上升起点+1000的数值时,FKEY归零,预示前脚波形结束。
 		//if(mag_buf_front[2] - FrontLiftPoint<=1500)
+		//if(FrontDropPoint-mag_buf_front[2]>0.45*FrontLiftDistance)
 		{
 			FKEY=0;
 			FrontLiftDistance = 2200;
 		}
 		
 	  
-		if((mag_buf_back[2] - BackLiftPoint<=1500)||(BackDropPoint-mag_buf_back[2]>0.45*BackLiftDistance))//当磁力计回降到小于上升起点+1000的数值时,BKEY归零,预示后脚波形结束。
+		if((mag_buf_back[2] - BackLiftPoint<=1500)||((BackDropPoint-mag_buf_back[2]>0.45*BackLiftDistance)&&(abs(mag_buf_back[2]-mag_buf_back[1])<500)))//当磁力计回降到小于上升起点+1000的数值时,BKEY归零,预示后脚波形结束。
 		//if(mag_buf_back[2] - BackLiftPoint<=1500)
+		//if(BackDropPoint-mag_buf_back[2]>0.45*BackLiftDistance)
 		{
 			BKEY=0;
 			BackLiftDistance = 2200;
@@ -243,11 +257,11 @@ uint8_t RealTimeStep(int16_t front[3], int16_t back[3], int16_t acc[3])
 			 Ucounter++;
 			}
 			Rcounter=0;		
-			if(((FKEY==1)||(BKEY==1))&&(Ucounter>=6))
+			if(((FKEY==1)||(BKEY==1))&&(Ucounter>=8))
 		  {
 			  step=1;
 			  ShoeTouchFlag=1;
-				SEGGER_RTT_printf(0,"You       have           one             step!\n");
+				//SEGGER_RTT_printf(0,"You       have           one             step!\n");
 		  }
 		  else
 		  {
@@ -263,7 +277,7 @@ uint8_t RealTimeStep(int16_t front[3], int16_t back[3], int16_t acc[3])
 			 Rcounter++;
 			}
 			Ucounter=0;
-			if((Rcounter>=6)&&(FKEY==0)&&((abs(accZ_buf[0]-2000)>250)||(abs(accZ_buf[1]-2000)>250)||(abs(accZ_buf[2]-2000)>250))&&(BKEY==0))
+			if((Rcounter>=6)&&(FKEY==0)&&((abs(accZ_buf[0]-2000)>300)||(abs(accZ_buf[1]-2000)>300)||(abs(accZ_buf[2]-2000)>300))&&(BKEY==0))
 		  {
 			  ShoeTouchFlag=0;
 		  }
@@ -271,21 +285,8 @@ uint8_t RealTimeStep(int16_t front[3], int16_t back[3], int16_t acc[3])
 		  {
 			  ShoeTouchFlag=1;
 		  }
-      /*
-      if(Rcounter==300)//防止卡死
-			{
-				if(FrontDropPoint-mag_buf_front[2]>0.45*FrontLiftDistance)
-				{
-					FKEY=0;
-				}
-				if(BackDropPoint-mag_buf_back[2]>0.45*BackLiftDistance)
-				{
-					BKEY=0;
-				}				
-			}		
-      */			
 	  }
-		SEGGER_RTT_printf(0,"Rcounter==:%d...\n",Rcounter);
+		//SEGGER_RTT_printf(0,"Rcounter==:%d...\n",Rcounter);
 	  /*计算加速度的方差*/
 		/*
 	  MV = (accZ_buf[0]+accZ_buf[1]+accZ_buf[2])/3;
@@ -306,15 +307,15 @@ uint8_t RealTimeStep(int16_t front[3], int16_t back[3], int16_t acc[3])
 		FrontDropPoint = mag_buf_front[2];
 		BackLiftPoint = mag_buf_back[2];
 		BackDropPoint = mag_buf_back[2];
-		SEGGER_RTT_printf(0,"Just Enter The Game! FrontLiftPoint==:%d...\n",FrontLiftPoint);
-		SEGGER_RTT_printf(0,"Just Enter The Game! BackLiftPoint==:%d...\n",BackLiftPoint);
+		//SEGGER_RTT_printf(0,"Just Enter The Game! FrontLiftPoint==:%d...\n",FrontLiftPoint);
+		//SEGGER_RTT_printf(0,"Just Enter The Game! BackLiftPoint==:%d...\n",BackLiftPoint);
   }
 	
 	RealFrontLiftPoint = FrontLiftPoint;
 	RealBackLiftPoint = BackLiftPoint;
 	return step;
 }
-
+/*
 void ClearRealTimeStep()
 {
   FrontLiftPoint=30000;
@@ -334,7 +335,7 @@ void ClearRealTimeStep()
 	BackLiftDistance = 2200;
 	Lock = 0;
 }
-
+*/
 
 uint8_t detect_step_by_mag(int16_t *mag, int16_t acc_z)
 {

+ 4 - 2
detect_step_by_mag.h

@@ -14,6 +14,7 @@
 //uint8_t detect_step_by_mag(int16_t *mag);
 uint8_t detect_step_by_mag(int16_t *mag, int16_t acc_z);
 uint8_t RealTimeStep(int16_t front[3], int16_t back[3], int16_t acc[3]);
+
 int16_t Get_ShoeTouchFlag(void);
 int16_t Get_Rcounter(void);
 int16_t Get_Tcounter(void);
@@ -21,7 +22,9 @@ int16_t Get_FKEY(void);
 int16_t Get_BKEY(void);
 int32_t Get_RealFrontLiftPoint(void);
 int32_t Get_RealBackLiftPoint(void);
-void ClearRealTimeStep();
+
+//void ClearRealTimeStep();
+
 static int FrontLiftPoint;
 static int FrontDropPoint;
 static int BackLiftPoint;
@@ -37,7 +40,6 @@ static uint8_t mag_index_front;
 static uint8_t mag_index_back;
 static int FrontLiftDistance;
 static int BackLiftDistance;
-static int Lock=0;
 
 
 #endif