浏览代码

优化跑酷脚环--左跳右跳改为用翻滚角判断

liang 1 年之前
父节点
当前提交
101f6aa931
共有 3 个文件被更改,包括 45 次插入99 次删除
  1. 6 0
      footRing_sdk_1.0/include/RunGame.h
  2. 1 1
      footRing_sdk_1.0/include/pub.h
  3. 38 98
      footRing_sdk_1.0/src/RunGame.cpp

+ 6 - 0
footRing_sdk_1.0/include/RunGame.h

@@ -18,6 +18,12 @@ public:
 	int getResultDown(int down);
 
 private:
+
+
+	deque<int> left_roll_vec;
+	deque<int> right_roll_vec;
+
+
 	deque<shoes_data_cell> left_shoes_data_vector;
 	deque<shoes_data_cell> right_shoes_data_vector;
 

+ 1 - 1
footRing_sdk_1.0/include/pub.h

@@ -44,7 +44,7 @@ using namespace std;
 
 #define PRESS_MIN 41000
 
-#define GAME_VERSION "0.6.11"
+#define GAME_VERSION "0.6.12"
 
 enum CMD_MOTION
 {

+ 38 - 98
footRing_sdk_1.0/src/RunGame.cpp

@@ -22,106 +22,70 @@ void RunGame::Process(int time_stamp, int* right_pos, int* right_att, int* right
 	int jump, int down, int rssi)
 {
 
-	// 额外处理蹲
-	/*down = 0;
-	int online_down = extract_motion.online_detect_down(right_front_press, left_front_press, right_back_press, left_back_press,
-		right_acc, left_acc);
-	if (online_down)
-	{
-		down = online_down;
-	}
-
-	int online_jump = extract_motion.online_detect_jump(right_front_press, left_front_press, right_back_press, left_back_press,
-		right_acc, left_acc);
-	if (online_jump)
-	{
-		jump = online_jump;
-	}*/
-
-	//存放一步的空中数据到shoes_data_vector 队列中, 头必须是触地时刻信息
-	setData(right_shoes_data_vector, time_stamp, right_pos[0] * 0.001f, right_pos[1] * 0.001f, right_pos[2] * 0.001f,
-		right_att[0] * 0.0001f, right_att[1] * 0.0001f, right_att[2] * 0.0001f, right_zupt, rssi);
-
-	setData(left_shoes_data_vector, time_stamp, left_pos[0] * 0.001f, left_pos[1] * 0.001f, left_pos[2] * 0.001f,
-		left_att[0] * 0.0001f, left_att[1] * 0.0001f, left_att[2] * 0.0001f, left_zupt, rssi);
 
-	//计算全局位置,选择当前的旋转量为这一步即将离地时候的方向,额外的旋转量为10度
-	//hoes_data_vector存的是鞋子上传的数据,它的方向是鞋子烧录时候的方向,并不是玩游戏时候的方向,需要旋转至玩游戏的方向
-	//step_data_vector 的位置已经选择到游戏的方向了,位置是相对位移,即相对于left_step_data_vector[0]的位置偏移
-	calGlobalPos(right_shoes_data_vector, right_step_data_vector, right_global_pos, right_shoes_data_vector[0].heading, 10.0f / 180 * PI, RIGHT_FOOT);
-	calGlobalPos(left_shoes_data_vector, left_step_data_vector, left_global_pos, left_shoes_data_vector[0].heading, -10.0f / 180 * PI, LEFT_FOOT);
+	//判断命令触发
+	int left_cmd = -1;
 
-	//这里为了脚本容易观测,设置全局位置为0
-	if (left_step_data_vector.front().zupt == 0)
+	if (left_roll_vec.size() == 0)
 	{
-		memset(left_global_pos, 0, 3 * sizeof(float));
+		left_roll_vec.push_back(left_att[2]);
 	}
-
-	if (right_step_data_vector.front().zupt == 0)
+	else
 	{
-		memset(right_global_pos, 0, 3 * sizeof(float));
-	}
-
-
-	//判断命令触发
-	int left_cmd = -1;
-	if (left_step_data_vector.size() > 1 && left_step_data_vector.front().zupt == 1)
-	{
-		std::cout << left_step_data_vector.back().pos_x << ", " << left_step_data_vector.back().pos_y << endl;
-		//跑酷游戏只要有空中的数据(不想其他游戏一样需要落地时候判断就好),就需要进行游戏
-		if (left_step_data_vector.back().zupt || left_step_data_vector.back().pitch < 0.3f)
+		if (left_roll_vec.back() < left_att[2])
 		{
-			//垫脚跑不触发命令。如果硬要垫脚跑,那么就等到他触地的时候再判断了
-			float max_val = left_step_data_vector.front().pos_x;
+			left_roll_vec.push_back(left_att[2]);
 
-			for (int i = 0; i < left_step_data_vector.size(); i++)
+			if (left_roll_vec.back() > left_roll_vec.front() + 3000)
 			{
-				if (left_step_data_vector[i].pos_x > max_val)
-				{
-					max_val = left_step_data_vector[i].pos_x;
-				}
-			}
-			//有效距离为0.23m
-			if (max_val - left_step_data_vector.back().pos_x > 0.23f)
-			{
-				left_cmd = MOTION_LEFT;
-				std::cout << "motion: left_side" << std::endl;
 
-				left_step_data_vector.pop_front();
+				left_cmd = MOTION_LEFT;
+				std::cout << "left side" << endl;
+				right_roll_vec.clear();
+				left_roll_vec.clear();
 			}
 		}
+		else
+		{
+			left_roll_vec.clear();
+		}
+	
 	}
 
 	int right_cmd = -1;
-	if (right_step_data_vector.size() > 1 && right_step_data_vector.front().zupt == 1)
-	{
 
-		if (right_step_data_vector.back().zupt || right_step_data_vector.back().pitch < 0.3f)
+	if (right_roll_vec.size() == 0 )
+	{
+		right_roll_vec.push_back(right_att[2]);
+	}
+	else
+	{
+		if (right_roll_vec.back() < right_att[2])
 		{
+			right_roll_vec.push_back(right_att[2]);
 
-			float min_val = right_step_data_vector.front().pos_x;
-
-			for (int i = 0; i < right_step_data_vector.size(); i++)
-			{
-				if (right_step_data_vector[i].pos_x < min_val)
-				{
-					min_val = right_step_data_vector[i].pos_x;
-				}
-			}
-
-			if (right_step_data_vector.back().pos_x - min_val > 0.23f)
+			if (right_roll_vec.back() > right_roll_vec.front() + 3000)
 			{
 				right_cmd = MOTION_RIGHT;
 
-				std::cout << "motion: right_side" << std::endl;
-
-				right_step_data_vector.pop_front();
+				std::cout << "right side" << endl;
+				left_roll_vec.clear();
+				right_roll_vec.clear();
 			}
 		}
+		else
+		{
+			right_roll_vec.clear();
+		}
+
 	}
 
 
 
+	result[0] = left_cmd;
+
+	result[1] = right_cmd;
+
 	result[2] = getResultJump(jump);
 
 	result[3] = getResultDown(down);
@@ -153,30 +117,6 @@ void RunGame::Process(int time_stamp, int* right_pos, int* right_att, int* right
 	}
 
 
-	//std::cout << "test_down" << endl;
-	//if (wait_down == 1  && acc_valid == 1)
-	//if (wait_down == 10)
-	//if(down)
-	//{
-
-	//	addMotionCount(DOWN_COUNT);
-
-	//	down_wait_after_jump = 20;
-
-	//	result[3] = MOTION_DOWN;
-
-	//	wait_down = 0;
-	//}
-
-
-	if (wait_down > 0)
-	{
-		wait_down--;
-	}
-
-	result[0] = left_cmd;
-	result[1] = right_cmd;
-
 	//续一个空中不能触发蹲的命令
 	/*if (left_zupt == 0 && right_zupt == 0 && down_wait_after_jump > 0)
 	{