compatibility with Python 2.7
parent
9b73084e09
commit
b1c49f987e
2
map.py
2
map.py
|
@ -1,6 +1,6 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from skimage.morphology import remove_small_holes
|
# from skimage.morphology import remove_small_holes
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import math
|
import math
|
||||||
from map import Map
|
from map import Map
|
||||||
from bresenham import bresenham
|
from skimage.draw import line
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import matplotlib.patches as plt_patches
|
import matplotlib.patches as plt_patches
|
||||||
from scipy.signal import savgol_filter
|
from scipy.signal import savgol_filter
|
||||||
|
@ -297,8 +297,8 @@ class ReferencePath:
|
||||||
# Get Bresenham paths to all possible cells
|
# Get Bresenham paths to all possible cells
|
||||||
paths = []
|
paths = []
|
||||||
for t_x, t_y in zip(tn_x, tn_y):
|
for t_x, t_y in zip(tn_x, tn_y):
|
||||||
path = list(bresenham(wp_x, wp_y, t_x, t_y))
|
x_list, y_list = line(wp_x, wp_y, t_x, t_y)
|
||||||
paths.append(path)
|
paths.append(zip(x_list, y_list))
|
||||||
|
|
||||||
# Compute minimum distance to border cell
|
# Compute minimum distance to border cell
|
||||||
min_width = max_width
|
min_width = max_width
|
||||||
|
@ -340,7 +340,7 @@ class ReferencePath:
|
||||||
lb_p = self.map.w2m(wp.border_cells[1][0], wp.border_cells[1][1])
|
lb_p = self.map.w2m(wp.border_cells[1][0], wp.border_cells[1][1])
|
||||||
|
|
||||||
# Compute path from left border cell to right border cell
|
# Compute path from left border cell to right border cell
|
||||||
path = list(bresenham(ub_p[0], ub_p[1], lb_p[0], lb_p[1]))
|
x_list, y_list = line(ub_p[0], ub_p[1], lb_p[0], lb_p[1])
|
||||||
|
|
||||||
# Initialize upper and lower bound of drivable area to
|
# Initialize upper and lower bound of drivable area to
|
||||||
# upper bound of path
|
# upper bound of path
|
||||||
|
@ -351,7 +351,7 @@ class ReferencePath:
|
||||||
ub_ls, lb_ls = ub_p, ub_p
|
ub_ls, lb_ls = ub_p, ub_p
|
||||||
|
|
||||||
# Iterate over path from left border to right border
|
# Iterate over path from left border to right border
|
||||||
for x, y in path:
|
for x, y in zip(x_list, y_list):
|
||||||
# If cell is free, update lower bound
|
# If cell is free, update lower bound
|
||||||
if self.map.data[y, x] == 1:
|
if self.map.data[y, x] == 1:
|
||||||
lb_o = (x, y)
|
lb_o = (x, y)
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from abc import ABC, abstractmethod
|
from abc import abstractmethod
|
||||||
|
try:
|
||||||
|
from abc import ABC
|
||||||
|
except:
|
||||||
|
# for Python 2.7
|
||||||
|
from abc import ABCMeta
|
||||||
|
class ABC(object):
|
||||||
|
__metaclass__ = ABCMeta
|
||||||
|
pass
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import matplotlib.patches as plt_patches
|
import matplotlib.patches as plt_patches
|
||||||
import math
|
import math
|
||||||
|
@ -26,14 +34,16 @@ class TemporalState:
|
||||||
self.y = y
|
self.y = y
|
||||||
self.psi = psi
|
self.psi = psi
|
||||||
|
|
||||||
|
self.members = ['x', 'y', 'psi']
|
||||||
|
|
||||||
def __iadd__(self, other):
|
def __iadd__(self, other):
|
||||||
"""
|
"""
|
||||||
Overload Sum-Add operator.
|
Overload Sum-Add operator.
|
||||||
:param other: numpy array to be added to state vector
|
:param other: numpy array to be added to state vector
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for state_id, state in enumerate(vars(self).values()):
|
for state_id in range(len(self.members)):
|
||||||
vars(self)[list(vars(self).keys())[state_id]] += other[state_id]
|
vars(self)[self.members[state_id]] += other[state_id]
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,16 +58,21 @@ class SpatialState(ABC):
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.members = None
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item):
|
||||||
return list(vars(self).values())[item]
|
if isinstance(item, int):
|
||||||
|
members = [self.members[item]]
|
||||||
|
else:
|
||||||
|
members = self.members[item]
|
||||||
|
return [vars(self)[key] for key in members]
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
vars(self)[list(vars(self).keys())[key]] = value
|
vars(self)[self.members[key]] = value
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(vars(self))
|
return len(self.members)
|
||||||
|
|
||||||
def __iadd__(self, other):
|
def __iadd__(self, other):
|
||||||
"""
|
"""
|
||||||
|
@ -65,15 +80,15 @@ class SpatialState(ABC):
|
||||||
:param other: numpy array to be added to state vector
|
:param other: numpy array to be added to state vector
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for state_id, state in enumerate(vars(self).values()):
|
for state_id in range(len(self.members)):
|
||||||
vars(self)[list(vars(self).keys())[state_id]] += other[state_id]
|
vars(self)[self.members[state_id]] += other[state_id]
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def list_states(self):
|
def list_states(self):
|
||||||
"""
|
"""
|
||||||
Return list of names of all states.
|
Return list of names of all states.
|
||||||
"""
|
"""
|
||||||
return list(vars(self).keys())
|
return self.members
|
||||||
|
|
||||||
|
|
||||||
class SimpleSpatialState(SpatialState):
|
class SimpleSpatialState(SpatialState):
|
||||||
|
@ -91,6 +106,8 @@ class SimpleSpatialState(SpatialState):
|
||||||
self.e_psi = e_psi
|
self.e_psi = e_psi
|
||||||
self.t = t
|
self.t = t
|
||||||
|
|
||||||
|
self.members = ['e_y', 'e_psi', 't']
|
||||||
|
|
||||||
|
|
||||||
####################################
|
####################################
|
||||||
# Spatial Bicycle Model Base Class #
|
# Spatial Bicycle Model Base Class #
|
||||||
|
|
Loading…
Reference in New Issue