-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnavFollowPath.py
92 lines (76 loc) · 2.59 KB
/
navFollowPath.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import numpy as np
import logging
# Modules
from navMap import Map
# START Class FollowPath --------------------------------------------
class FollowPath:
def __init__(self, reso, gx, gy):
self.gx = gx
self.gy = gy
self.map = None
self.reso = reso
self.limitx = None
self.limity = None
self.limit = True
def set_limit(self, new_gx, new_gy):
self.limitx = new_gx
self.limity = new_gy
self.limit = False
def get_limit(self):
return self.limitx, self.limity
def get_status(self):
return self.limit
def follow(self, xp, yp, curdirx, curdiry):
xs = xp + curdirx * self.reso
ys = yp + curdiry * self.reso
d = np.hypot(self.gx - xs, self.gy - ys)
d_limit = np.hypot(self.limitx - xs, self.limity - ys)
# Llegamos al objetivo?
if d_limit < self.reso:
self.limit = True
# Verificamos no superar el limite
if int(self.limitx) == int(xs):
self.limit = True
if int(self.limity) == int(ys):
self.limit = True
return d, xs, ys, curdirx, curdiry, self.limit
def follow_steps(self, xp, yp, astar_path):
idx = astar_path.index((xp, yp))
if idx == 0:
logging.error("Already reached goal...")
logging.error("\tAstar path: " + str(astar_path))
logging.error("\tCurrent step: " + str((xp,yp)))
else:
newx, newy = astar_path[idx-1]
dirx = newx - xp
diry = newy - yp
d = np.hypot(self.gx - newx, self.gy - newy)
logging.debug("Following Astar steps...")
logging.error("\tAstar path: " + str(astar_path))
logging.debug("\txp,yp: " + str((newx, newy)) + " | curdir: " + str((dirx, diry)) + " | d: " + str(d))
return d, newx, newy, dirx, diry
def decide_status(self, xp, yp, ox, oy):
stuck = False
for obx,oby in np.nditer([ox, oy]):
if obx == xp and oby == yp:
stuck = True
return stuck
def follow_wall(self, xp, yp, curdirx, curdiry, obsx, obsy):
# TODO -- Mantenerme siempre a la distancia actual del
# path_blocked_dir para evitar nuevo
# escenario descripto en WorldBuilder.ods
# VER el siguiente código
# # Bisector angle of two vectors in 2D
# # First we get each angle from original directions
# theta_u = math.atan2(self.trap_dir[0], self.trap_dir[1])
# theta_v = math.atan2(self.dir[-1][0], self.dir[-1][1])
# # Then we create a new vector with the average angle
# middle_theta = (theta_u+theta_v)/2
# m_dir = (math.cos(middle_theta), math.sin(middle_theta))
xs = xp + curdirx * self.reso
ys = yp + curdiry * self.reso
d = np.hypot(self.gx - xs, self.gy - ys)
d_limit = np.hypot(self.limitx - xs, self.limity - ys)
if d_limit < self.reso:
self.limit = True
return d, xs, ys, curdirx, curdiry, self.limit