|
@@ -22,113 +22,227 @@ 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)
|
|
|
+
|
|
|
+ int left_cmd = -1;
|
|
|
+ int right_cmd = -1;
|
|
|
+
|
|
|
+ if (left_roll_vec.size() == 0)
|
|
|
{
|
|
|
- down = online_down;
|
|
|
+ left_roll_vec.push_back(left_att[2]);
|
|
|
}
|
|
|
-
|
|
|
- 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)
|
|
|
+ else
|
|
|
{
|
|
|
- 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);
|
|
|
+ if (left_att[2] >= left_roll_vec.back())
|
|
|
+ {
|
|
|
+ left_roll_vec.push_back(left_att[2]);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ left_roll_vec.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- //这里为了脚本容易观测,设置全局位置为0
|
|
|
- if (left_step_data_vector.front().zupt == 0)
|
|
|
+ if (right_roll_vec.size() == 0)
|
|
|
{
|
|
|
- memset(left_global_pos, 0, 3 * sizeof(float));
|
|
|
+ right_roll_vec.push_back(right_att[2]);
|
|
|
}
|
|
|
-
|
|
|
- if (right_step_data_vector.front().zupt == 0)
|
|
|
+ else
|
|
|
{
|
|
|
- memset(right_global_pos, 0, 3 * sizeof(float));
|
|
|
+ if (right_att[2] >= right_roll_vec.back())
|
|
|
+ {
|
|
|
+ right_roll_vec.push_back(right_att[2]);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ right_roll_vec.clear();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- //判断命令触发
|
|
|
- int left_cmd = -1;
|
|
|
- if (left_step_data_vector.size() > 1 && left_step_data_vector.front().zupt == 1)
|
|
|
+ if (right_roll_vec.size() > 1 && left_roll_vec.size() > 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)
|
|
|
- {
|
|
|
- //垫脚跑不触发命令。如果硬要垫脚跑,那么就等到他触地的时候再判断了
|
|
|
- float max_val = left_step_data_vector.front().pos_x;
|
|
|
+ int right_dist = right_roll_vec.back() - right_roll_vec.front();
|
|
|
+
|
|
|
+ int left_dist = left_roll_vec.back() - left_roll_vec.front();
|
|
|
|
|
|
- for (int i = 0; i < left_step_data_vector.size(); i++)
|
|
|
+ if (right_dist > 800 && left_dist > 800)
|
|
|
+ {
|
|
|
+ if (right_dist > 2000 || left_dist > 2000)
|
|
|
{
|
|
|
- if (left_step_data_vector[i].pos_x > max_val)
|
|
|
+ std::cout << "right_dist : " << right_dist << " left_dist :" << left_dist << endl;
|
|
|
+ if (right_dist > left_dist)
|
|
|
{
|
|
|
- max_val = left_step_data_vector[i].pos_x;
|
|
|
+ right_cmd = MOTION_RIGHT;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ left_cmd = MOTION_LEFT;
|
|
|
}
|
|
|
- }
|
|
|
- //有效距离为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();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- int right_cmd = -1;
|
|
|
- if (right_step_data_vector.size() > 1 && right_step_data_vector.front().zupt == 1)
|
|
|
+ result[0] = -1;
|
|
|
+
|
|
|
+ if (left_cmd != last_left_cmd && left_cmd == MOTION_LEFT)
|
|
|
{
|
|
|
+ result[0] = MOTION_LEFT;
|
|
|
+ std::cout << " result[0] = MOTION_LEFT;" << endl;
|
|
|
+ }
|
|
|
|
|
|
- if (right_step_data_vector.back().zupt || right_step_data_vector.back().pitch < 0.3f)
|
|
|
- {
|
|
|
+ result[1] = -1;
|
|
|
+ if (right_cmd != last_right_cmd && right_cmd == MOTION_RIGHT)
|
|
|
+ {
|
|
|
+ result[1] = MOTION_RIGHT;
|
|
|
+ std::cout << " result[1] = MOTION_RIGHT;" << endl;
|
|
|
+ }
|
|
|
|
|
|
- float min_val = right_step_data_vector.front().pos_x;
|
|
|
+ last_left_cmd = left_cmd;
|
|
|
+
|
|
|
+ last_right_cmd = right_cmd;
|
|
|
|
|
|
- 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)
|
|
|
- {
|
|
|
- right_cmd = MOTION_RIGHT;
|
|
|
+ ////存放一步的空中数据到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);
|
|
|
|
|
|
- std::cout << "motion: right_side" << std::endl;
|
|
|
+ //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);
|
|
|
|
|
|
- right_step_data_vector.pop_front();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ ////计算全局位置,选择当前的旋转量为这一步即将离地时候的方向,额外的旋转量为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 jump_cmd = -1;
|
|
|
+ ////这里为了脚本容易观测,设置全局位置为0
|
|
|
+ //if (left_step_data_vector.front().zupt == 0)
|
|
|
+ //{
|
|
|
+ // memset(left_global_pos, 0, 3 * sizeof(float));
|
|
|
+ //}
|
|
|
+
|
|
|
+ //if (right_step_data_vector.front().zupt == 0)
|
|
|
+ //{
|
|
|
+ // memset(right_global_pos, 0, 3 * sizeof(float));
|
|
|
+ //}
|
|
|
+
|
|
|
+ //if (left_step_data_vector.size() > 100)
|
|
|
+ //{
|
|
|
+ // left_step_data_vector.pop_front();
|
|
|
+ //}
|
|
|
+
|
|
|
+ //if (right_step_data_vector.size() > 100)
|
|
|
+ //{
|
|
|
+ // right_step_data_vector.pop_front();
|
|
|
+ //}
|
|
|
|
|
|
- jump_cmd = getResultJump(jump);
|
|
|
|
|
|
- int down_cmd = -1;
|
|
|
+ ////判断命令触发
|
|
|
+ //int left_cmd = -1;
|
|
|
+ //if (left_step_data_vector.size() > 1 && left_step_data_vector.front().zupt == 1)
|
|
|
+ //{
|
|
|
+ // //跑酷游戏只要有空中的数据(不想其他游戏一样需要落地时候判断就好),就需要进行游戏
|
|
|
+ // if (left_step_data_vector.back().zupt || left_step_data_vector.back().pitch < 0.3f)
|
|
|
+ // {
|
|
|
+ // //垫脚跑不触发命令。如果硬要垫脚跑,那么就等到他触地的时候再判断了
|
|
|
+
|
|
|
+ // float max_val = left_step_data_vector.front().pos_x;
|
|
|
+
|
|
|
+ // for (int i = 0; i < left_step_data_vector.size(); i++)
|
|
|
+ // {
|
|
|
+ // if (left_step_data_vector[i].pos_x > max_val)
|
|
|
+ // {
|
|
|
+ // max_val = left_step_data_vector[i].pos_x;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // int roll_valid = 0;
|
|
|
+ // float front_roll = left_step_data_vector.front().roll;
|
|
|
+ // for (int i = 1; i < left_step_data_vector.size(); i++)
|
|
|
+ // {
|
|
|
+ // if (left_step_data_vector[i].roll > left_step_data_vector[i - 1].roll - 0.000001f)
|
|
|
+ // {
|
|
|
+ // if (left_step_data_vector[i].roll - front_roll > 0.3f)
|
|
|
+ // {
|
|
|
+ // roll_valid = 1;
|
|
|
+ // }
|
|
|
+ // continue;
|
|
|
+ // }
|
|
|
+ // front_roll = left_step_data_vector[i].roll;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+
|
|
|
+ // //有效距离为0.23m
|
|
|
+ // if (max_val - left_step_data_vector.back().pos_x > 0.23f && roll_valid)
|
|
|
+ // {
|
|
|
+ // if (!(rssi_delay.size() > 0 && rssi < 25 && rssi_delay.front() > 32))
|
|
|
+ // {
|
|
|
+ // left_cmd = MOTION_LEFT;
|
|
|
+ // std::cout << "motion: left_side, " << left_step_data_vector.back().pitch << std::endl;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // left_step_data_vector.pop_front();
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //}
|
|
|
|
|
|
- result[3] = -1;
|
|
|
+ //int right_cmd = -1;
|
|
|
+ //if (right_step_data_vector.size() > 1 && right_step_data_vector.front().zupt == 1)
|
|
|
+ //{
|
|
|
|
|
|
- down_cmd = getResultDown(down);
|
|
|
+ // if (right_step_data_vector.back().zupt || right_step_data_vector.back().pitch < 0.3f)
|
|
|
+ // {
|
|
|
+
|
|
|
+ // 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;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // int roll_valid = 0;
|
|
|
+ // float front_roll = right_step_data_vector.front().roll;
|
|
|
+ // for (int i = 1; i < right_step_data_vector.size(); i++)
|
|
|
+ // {
|
|
|
+ // if (right_step_data_vector[i].roll > right_step_data_vector[i - 1].roll - 0.000001f)
|
|
|
+ // {
|
|
|
+ // if (right_step_data_vector[i].roll - front_roll > 0.3f)
|
|
|
+ // {
|
|
|
+ // roll_valid = 1;
|
|
|
+ // }
|
|
|
+ // continue;
|
|
|
+ // }
|
|
|
+ // front_roll = right_step_data_vector[i].roll;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // if (right_step_data_vector.back().pos_x - min_val > 0.23f && roll_valid)
|
|
|
+ // {
|
|
|
+ // if (!(rssi_delay.size() > 0 && rssi < 25 && rssi_delay.front() > 32))
|
|
|
+ // {
|
|
|
+ // right_cmd = MOTION_RIGHT;
|
|
|
+
|
|
|
+ // std::cout << "motion: right_side, " << left_step_data_vector.back().pitch << std::endl;
|
|
|
+ // }
|
|
|
+ // right_step_data_vector.pop_front();
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //result[0] = left_cmd;
|
|
|
+
|
|
|
+ //result[1] = right_cmd;
|
|
|
+
|
|
|
+ result[2] = getResultJump(jump);
|
|
|
+
|
|
|
+ result[3] = getResultDown(down);
|
|
|
+
|
|
|
+ //result[2] = left_zupt;
|
|
|
+
|
|
|
+ //result[3] = right_zupt;
|
|
|
|
|
|
|
|
|
left_acc_deque.push_back(left_acc[2]);
|
|
@@ -156,42 +270,6 @@ void RunGame::Process(int time_stamp, int* right_pos, int* right_att, int* right
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (down_cmd == 1)
|
|
|
- {
|
|
|
- wait_down = 10;
|
|
|
- }
|
|
|
- if (down_cmd == MOTION_DOWN)
|
|
|
- {
|
|
|
- addMotionCount(DOWN_COUNT);
|
|
|
-
|
|
|
- result[3] = MOTION_DOWN;
|
|
|
-
|
|
|
- }
|
|
|
- //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;
|
|
|
- result[2] = jump_cmd;
|
|
|
- //result[3] = down_cmd;
|
|
|
|
|
|
//续一个空中不能触发蹲的命令
|
|
|
/*if (left_zupt == 0 && right_zupt == 0 && down_wait_after_jump > 0)
|
|
@@ -222,8 +300,6 @@ int RunGame::getResultDown(int down)
|
|
|
{
|
|
|
int isDown = -1;
|
|
|
|
|
|
- int canva_down = ((down & 0x04) > 0 ? 1 : 0);
|
|
|
-
|
|
|
if (last_down == 0 && down > 0)
|
|
|
{
|
|
|
isDown = MOTION_DOWN;
|
|
@@ -234,28 +310,16 @@ int RunGame::getResultDown(int down)
|
|
|
|
|
|
//down_count++;
|
|
|
}
|
|
|
- /*
|
|
|
- * down_wait_after_jump:避免前脚蹲后,接着后脚压下来的情况,当down_wait_after_jump == -1时候,判断蹲生效
|
|
|
- * 当一直处于蹲的时候,额外加拖延时间,在这个时间不允许触发蹲。
|
|
|
- */
|
|
|
-
|
|
|
- if (down == 0 && down_wait_after_jump >=0)
|
|
|
- {
|
|
|
- down_wait_after_jump--;
|
|
|
- }
|
|
|
|
|
|
last_down = down;
|
|
|
|
|
|
- last_canva_down = canva_down;
|
|
|
-
|
|
|
-
|
|
|
return isDown;
|
|
|
|
|
|
}
|
|
|
|
|
|
int RunGame::getResultJump(int jump)
|
|
|
{
|
|
|
- int isJump = 0;
|
|
|
+ int isJump = -1;
|
|
|
|
|
|
if (last_jump == 0 && jump == 1)
|
|
|
{
|
|
@@ -267,13 +331,6 @@ int RunGame::getResultJump(int jump)
|
|
|
|
|
|
jump_count++;
|
|
|
}
|
|
|
- /*
|
|
|
- * 跳之后不能立即接着蹲,用down_wait_after_jump来避免
|
|
|
- */
|
|
|
- if (jump)
|
|
|
- {
|
|
|
- down_wait_after_jump = 20;
|
|
|
- }
|
|
|
|
|
|
last_jump = jump;
|
|
|
|