123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- #include "SingleFootAction.h"
- void SingleFootAction::run(int x, int y, int z,int zupt, int rssi, float pitch)
- {
- report_siganl_listen(last_z);
- pause_signal_listen(pitch);
-
- direction_signal_listen(last_x, last_y, zupt, rssi);
- set_motion_signal(zupt);
- last_zupt = zupt;
- last_x = x; last_y = y; last_z = z;
- }
- int SingleFootAction::get_interation_state()
- {
- return interation_state;
- }
- void SingleFootAction::set_motion_signal(int zupt )
- {
- if (pause_signal_count >= 200)
- {
- if (pause_signal == 1)
- {
- interation_state = MOTION_STOP;
- }
- else
- {
- interation_state = -1;
- }
- }
- else
- {
- if (last_zupt == 0 && zupt == 1 && can_report_motion)
- {
- interation_state = direction_signal;
- can_report_motion = 0;
- }
- else
- {
- interation_state = -1;
- }
-
- }
- }
- void SingleFootAction::direction_signal_listen(int x, int y, int zupt, int rssi)
- {
- float x_offset = x;
- float y_offset = y;
- float len_offset = sqrt(x_offset * x_offset + y_offset * y_offset);
- if (last_zupt == 0 && zupt == 1)
- {
- if (left_or_right == RIGHT_FOOT)
- {
- std::cout << "debug "<<"x: " << x << " y: " << y << endl;
- }
- if (rssi < 30)
- {
- direction_signal = -1;
- }
- else if (len_offset < 15.f)
- {
- return;
- }
- else
- {
- float angle = atan2(y_offset, x_offset);
- if (left_or_right == LEFT_FOOT)
- {
- if (angle > PI * 3 / 4 || angle < -PI * 3 / 4)
- {
- direction_signal = MOTION_LEFT;
- }
- else if (angle < PI * 3 / 4 && angle >PI / 4)
- {
- direction_signal = MOTION_FRONT;
- }
- else if (angle > -PI * 3 / 4 && angle < -PI / 4)
- {
- direction_signal = MOTION_BACK;
- }
- else
- {
- direction_signal = -1;
- }
- }
- else
- {
- if (angle < PI / 4 && angle > -PI / 4)
- {
- direction_signal = MOTION_RIGHT;
- }
- else if (angle < PI * 3 / 4 && angle >PI / 4)
- {
- direction_signal = MOTION_FRONT;
- }
- else if (angle > -PI * 3 / 4 && angle < -PI / 4)
- {
- direction_signal = MOTION_BACK;
- }
- else
- {
- direction_signal = -1;
- }
- }
- }
-
- }
- }
- void SingleFootAction::report_siganl_listen(int z)
- {
- if (z > 1)
- {
- can_report_motion = 1;
- }
- }
- void SingleFootAction::pause_signal_listen(float pitch)
- {
- if (pitch < STOP_ANGLE)
- {
- pause_signal_count++;
- }
- else
- {
- pause_signal_count = 0;
- }
- if (pause_signal_count == 200)
- {
- pause_signal = 1;
- }
- else
- {
- pause_signal = 0;
- }
- }
|