-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnavigation.ino
76 lines (63 loc) · 1.71 KB
/
navigation.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "navigation.h"
#include "utils.h"
#include "config.h"
#include "asserv.h"
#include "odometry.h"
// #include "coders.h"
static int isIn8Zone(double x1, double y1, double x2, double y2,double angle)
{
angle=angle+PI/2;
double cos_angle = DIST_WHEEL2CENTER*cos(angle);
double sin_angle = DIST_WHEEL2CENTER*sin(angle);
double right_wheel_x = x1+cos_angle;
double right_wheel_y = y1+sin_angle;
double left_wheel_x = x1-cos_angle;
double left_wheel_y = y1-sin_angle;
if (pythagore(right_wheel_x-x2,right_wheel_y-y2)<DIST_WHEEL2CENTER)
return 1;
if (pythagore(left_wheel_x-x2,left_wheel_y-y2)<DIST_WHEEL2CENTER)
return 1;
return 0;
}
int nav_gotoPoint(double new_x, double new_y, double delta_max)
{
double old_x=odo_X;
double old_y=odo_Y;
double old_angle=odo_angle;
double diff_x = new_x-old_x;
double diff_y = new_y-old_y;
double approx_dist = pythagore(diff_x,diff_y);
// Serial.print("approx_dist=");
// Serial.println(approx_dist);
double n_angle_rad = atan2(diff_y,diff_x);
n_angle_rad=closest_equivalent_angle(old_angle,n_angle_rad);
DUMP_VAR(n_angle_rad);
double diff = n_angle_rad-odo_angle;
DUMP_VAR(diff);
// Serial.println("--");
// Serial.print(approx_dist,3);
// Serial.print(" ");
// Serial.println(delta_max,3);
DUMP_VAR(approx_dist);
DUMP_VAR(delta_max);
if(approx_dist>=delta_max)
{
// Serial.println("Here");
if(isIn8Zone(old_x,old_y,new_x,new_y,old_angle))
{
Serial.println("ZONE 8 ============================");
asserv_setTarget(
0,
odo_rads2ticks(n_angle_rad),
DEST_REL|ANGL_ABS);
approx_dist=0;
}
asserv_setTarget(
odo_meters2ticks(approx_dist),
odo_rads2ticks(diff),
DEST_REL|ANGL_REL);
return 0;
}else{
return 1;
}
}