16 FILE* SelfLocalization::fp = fopen(
"traveling_route.txt",
"w");
17 bool SelfLocalization::isSave;
21 : left(left_motor_sl), right(right_motor_sl)
24 between_wheels = 12.7;
25 moving_distance_mean = 0;
27 current_x = current_y = current_angle = 0;
35 left.
update(left_motor_sl);
38 right.
update(right_motor_sl);
45 current_x += (moving_distance_mean * std::cos(current_angle + (turning_angle / 2.0)));
46 current_y += (moving_distance_mean * std::sin(current_angle + (turning_angle / 2.0)));
47 current_angle += turning_angle;
67 fprintf(fp,
"%f %f\n", current_x, current_y);
75 float distance = std::sqrt((target_x - current_x) * (target_x - current_x)
76 + (target_y - current_y) * (target_y - current_y));
77 if(distance < target_radius)
return true;
85 float _goal_x,
float _goal_y,
86 float _current_x,
float _current_y)
90 a = _goal_y - _start_y;
91 b = -(_goal_x - _start_x);
92 c = -b * _start_y - a * _start_x;
94 return (a * _current_x + b * _current_y + c) / std::sqrt(a * a + b * b);
104 return target_x < current_x;
108 return target_y < current_y;
113 return target_x > current_x;
117 return target_y > current_y;
122 float _goal_y,
float _current_x,
float _current_y)
129 is_below_normal_vector = (start_y < goal_y);
135 float k = (start_x - goal_x) / (goal_y - start_y);
136 float border_y = k * _current_x + goal_y - k * goal_x;
138 if(is_below_normal_vector) {
139 return _current_y >= border_y;
141 return _current_y < border_y;
void init_normal_vector(float _start_x, float _start_y, float _goal_x, float _goal_y, float _current_x, float _current_y)
bool approached_target_coordinates(float target_x, float target_y, float target_radius)
void update(std::int32_t left_motor_sl, std::int32_t right_motor_sl)
bool is_below_target_line_of_x(float target_x)
void writing_current_coordinates()
float calculate_between_ev3_and_border(float _start_x, float _start_y, float _goal_x, float _goal_y, float _current_x, float _current_y)
void calculate_current_angle()
bool is_below_target_line_of_y(float target_y)
void update(std::int32_t left_motor, std::int32_t right_motor)
左右モータ角度の過去値を現在値へ更新する
bool is_over_target_line_of_x(float target_x)
bool is_over_normal_vector(float _current_x, float _current_y)
bool is_over_target_line_of_y(float target_y)
SelfLocalization(std::int32_t left_motor_sl, std::int32_t right_motor_sl, bool save=true)