16 FILE* SelfLocalization::fp = fopen(
"traveling_route.txt",
"w");
17 bool SelfLocalization::isSave;
20 left(left_motor_sl), right(right_motor_sl){
22 between_wheels = 12.7;
23 moving_distance_mean = 0;
25 current_x = current_y = current_angle = 0;
33 left.
update(left_motor_sl);
36 right.
update(right_motor_sl);
43 current_x += (moving_distance_mean * std::cos(current_angle + (turning_angle/2.0)));
44 current_y += (moving_distance_mean * std::sin(current_angle + (turning_angle/2.0)));
45 current_angle += turning_angle;
63 fprintf(fp,
"%f %f\n", current_x, current_y);
69 float distance = std::sqrt(
70 (target_x - current_x) * (target_x - current_x) +
71 (target_y - current_y) * (target_y - current_y) );
72 if(distance < target_radius)
81 (
float _start_x,
float _start_y,
float _goal_x,
float _goal_y,
float _current_x,
float _current_y) {
84 a = _goal_y - _start_y;
85 b = -(_goal_x - _start_x);
86 c = -b * _start_y - a * _start_x;
88 return (a*_current_x + b*_current_y + c) / std::sqrt(a*a + b*b);
96 return target_x < current_x;
99 return target_y < current_y;
103 return target_x > current_x;
106 return target_y > current_y;
112 (
float _start_x,
float _start_y,
float _goal_x,
float _goal_y,
float _current_x,
float _current_y) {
113 start_x = _start_x; start_y = _start_y;
114 goal_x = _goal_x; goal_y = _goal_y;
116 is_below_normal_vector = (start_y < goal_y);
121 (
float _current_x,
float _current_y) {
122 float k = (start_x - goal_x) / (goal_y - start_y);
123 float border_y = k * _current_x + goal_y - k * goal_x;
125 if (is_below_normal_vector) {
126 return _current_y >= border_y;
128 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)
void update(std::int32_t update_degree)
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)
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)