Some python2/3 fixes

This commit is contained in:
felipecode 2017-12-22 13:54:21 -02:00
parent 9d61a2e8d5
commit 081db8238f
4 changed files with 19 additions and 37 deletions

View File

@ -285,7 +285,7 @@ class Benchmark(object):
else:
# Ask question, to avoid mistaken override situations
answer = input("The experiment was already found in the files"
+ ", Do you want to continue (y/n) ? \n"
+ ", Do you want to continue (y/n)? \n"
)
if answer == 'Yes' or answer == 'y':
line_on_file = self._get_last_position()

View File

@ -1,8 +1,6 @@
import heapq
class Cell(object):
def __init__(self, x, y, reachable):
"""Initialize new cell.
@ -23,11 +21,12 @@ class Cell(object):
self.f = 0
def __lt__(self, other):
return self.g < other.g
class AStar(object):
def __init__(self):
# open list
self.opened = []
heapq.heapify(self.opened)
@ -38,10 +37,8 @@ class AStar(object):
self.grid_height = None
self.grid_width = None
def init_grid(self, width, height, walls,start, end):
"""
Prepare grid cells, walls.
def init_grid(self, width, height, walls, start, end):
"""Prepare grid cells, walls.
@param width grid's width.
@param height grid's height.
@ -51,7 +48,6 @@ class AStar(object):
"""
self.grid_height = height
self.grid_width = width
#print walls
for x in range(self.grid_width):
for y in range(self.grid_height):
if (x, y) in walls:
@ -59,7 +55,6 @@ class AStar(object):
else:
reachable = True
self.cells.append(Cell(x, y, reachable))
self.start = self.get_cell(*start)
self.end = self.get_cell(*end)
@ -127,8 +122,6 @@ class AStar(object):
@returns path or None if not found.
"""
if self.start == self.end:
return None
# add starting cell to open heap queue
heapq.heappush(self.opened, (self.start.f, self.start))
while len(self.opened):
@ -152,7 +145,4 @@ class AStar(object):
else:
self.update_cell(adj_cell, cell)
# add adj cell to open list
heapq.heappush(self.opened, (adj_cell.f, adj_cell))
heapq.heappush(self.opened, (adj_cell.f, adj_cell))

View File

@ -34,8 +34,8 @@ class CityTrack(object):
node =self._map.convert_to_node(position)
# To change the orientation with respect to the map standards
node_orientation = np.array([node_orientation[0],
node_orientation[1]])
#node_orientation = np.array([node_orientation[0],
# node_orientation[1]])
node = tuple([ int(x) for x in node ])

View File

@ -80,7 +80,8 @@ class CarlaMap(object):
return np.asarray(img, dtype="int32")
return np.fliplr(self.map_image)
def get_map_lanes(self, height=None):
def get_map_lanes(self, size=None):
if size is not None:
img = Image.fromarray(self.map_image_lanes.astype(np.uint8))
img = img.resize((size[1], size[0]), Image.ANTIALIAS)
@ -92,23 +93,14 @@ class CarlaMap(object):
def get_lane_orientation(self, world):
"""Get the lane orientation of a certain world position."""
relative_location = []
pixel = []
rotation = np.array([world[0], world[1], world[2]])
rotation = rotation.dot(self.worldrotation)
relative_location.append(rotation[0] + self.worldoffset[0] - self.mapoffset[0])
relative_location.append(rotation[1] + self.worldoffset[1] - self.mapoffset[1])
relative_location.append(rotation[2] + self.worldoffset[2] - self.mapoffset[2])
pixel.append(math.floor(relative_location[0] / float(self.pixel_density)))
pixel.append(math.floor(relative_location[1] / float(self.pixel_density)))
pixel = self.convert_to_pixel(world)
ori = self.map_image_lanes[int(pixel[1]), int(pixel[0]), 2]
ori = color_to_angle(ori)
return (-math.cos(ori), -math.sin(ori))
def convert_to_node(self,input):
def convert_to_node(self, input):
"""
Receives a data type (Can Be Pixel or World )
:param input: position in some coordinate
@ -116,7 +108,7 @@ class CarlaMap(object):
"""
return self._converter.convert_to_node(input)
def convert_to_pixel(self,input):
def convert_to_pixel(self, input):
"""
Receives a data type (Can Be Pixel or World )
:param input: position in some coordinate
@ -124,7 +116,7 @@ class CarlaMap(object):
"""
return self._converter.convert_to_pixel(input)
def convert_to_world(self,input):
def convert_to_world(self, input):
"""
Receives a data type (Can Be Pixel or World )
:param input: position in some coordinate
@ -134,7 +126,7 @@ class CarlaMap(object):
def get_walls_directed(self,node_source,source_ori,node_target,target_ori):
def get_walls_directed(self, node_source, source_ori, node_target, target_ori):
"""
This is the most hacky function. Instead of planning on two ways,
we basically use a one way road and interrupt the other road by adding
@ -142,7 +134,7 @@ class CarlaMap(object):
"""
final_walls = self._grid.get_wall_source(node_source,source_ori,node_target)
final_walls = self._grid.get_wall_source(node_source, source_ori, node_target)
final_walls = final_walls.union(self._grid.get_wall_target(
node_target, target_ori, node_source))