Fixed Error Message output in sensor.py. Added some more Documentation.
This commit is contained in:
parent
0f1b696a20
commit
aca3c3b70f
3 changed files with 28 additions and 24 deletions
|
@ -28,6 +28,9 @@ class Move:
|
||||||
'''
|
'''
|
||||||
uses odometry and the planet object to map edges that are connected to
|
uses odometry and the planet object to map edges that are connected to
|
||||||
current node.
|
current node.
|
||||||
|
|
||||||
|
Use either relative motor pos or timed driving to center on node.
|
||||||
|
Next turn around and detect edges through drops in _sensor.getbrightness()
|
||||||
'''
|
'''
|
||||||
def getstationedges(self):
|
def getstationedges(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -16,56 +16,57 @@ class Direction(IntEnum):
|
||||||
|
|
||||||
# simple alias, no magic here
|
# simple alias, no magic here
|
||||||
Weight = int
|
Weight = int
|
||||||
"""
|
"""
|
||||||
Weight of a given path (received from the server)
|
Weight of a given path (received from the server)
|
||||||
value: -1 if broken path
|
value: -1 if broken path
|
||||||
>0 for all other paths
|
>0 for all other paths
|
||||||
never 0
|
never 0
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class Planet:
|
class Planet:
|
||||||
"""
|
"""
|
||||||
Contains the representation of the map and provides certain functions to manipulate it according to the specifications
|
Contains the representation of the map and provides certain functions to manipulate it according to the specifications
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
""" Initializes the data structure """
|
""" Initializes the data structure """
|
||||||
|
self.planetmap = {((0, 0), Direction.NORTH):((0, 1), Direction.SOUTH), "weight":1}
|
||||||
self.target = None
|
self.target = None
|
||||||
|
|
||||||
def add_path(self, start: Tuple[Tuple[int, int], Direction], target: Tuple[Tuple[int, int], Direction], weight: int):
|
def add_path(self, start: Tuple[Tuple[int, int], Direction], target: Tuple[Tuple[int, int], Direction], weight: int):
|
||||||
"""
|
"""
|
||||||
Adds a bidirectional path defined between the start and end coordinates to the map and assigns the weight to it
|
Adds a bidirectional path defined between the start and end coordinates to the map and assigns the weight to it
|
||||||
|
|
||||||
example:
|
example:
|
||||||
add_path(((0, 3), Direction.NORTH), ((0, 3), Direction.WEST), 1)
|
add_path(((0, 3), Direction.NORTH), ((0, 3), Direction.WEST), 1)
|
||||||
"""
|
"""
|
||||||
pass
|
|
||||||
|
|
||||||
def get_paths(self) -> Dict[Tuple[int, int], Dict[Direction, Tuple[Tuple[int, int], Direction, Weight]]]:
|
def get_paths(self) -> Dict[Tuple[int, int], Dict[Direction, Tuple[Tuple[int, int], Direction, Weight]]]:
|
||||||
"""
|
"""
|
||||||
Returns all paths
|
Returns all paths
|
||||||
|
|
||||||
example:
|
example:
|
||||||
get_paths() returns: {
|
get_paths() returns: {
|
||||||
(0, 3): {
|
(0, 3): {
|
||||||
Direction.NORTH: ((0, 3), Direction.WEST, 1),
|
Direction.NORTH: ((0, 3), Direction.WEST, 1),
|
||||||
Direction.EAST: ((1, 3), Direction.WEST, 2)
|
Direction.EAST: ((1, 3), Direction.WEST, 2)
|
||||||
},
|
},
|
||||||
(1, 3): {
|
(1, 3): {
|
||||||
Direction.WEST: ((0, 3), Direction.EAST, 2),
|
Direction.WEST: ((0, 3), Direction.EAST, 2),
|
||||||
...
|
...
|
||||||
},
|
},
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def shortest_path(self, start: Tuple[int, int], target: Tuple[int, int]) -> Optional[List[Tuple[Tuple[int, int], Direction]]]:
|
def shortest_path(self, start: Tuple[int, int], target: Tuple[int, int]) -> Optional[List[Tuple[Tuple[int, int], Direction]]]:
|
||||||
"""
|
"""
|
||||||
Returns a shortest path between two nodes
|
Returns a shortest path between two nodes
|
||||||
|
|
||||||
examples:
|
examples:
|
||||||
shortest_path((0,0), (2,2)) returns: [((0, 0), Direction.EAST), ((1, 0), Direction.NORTH)]
|
shortest_path((0,0), (2,2)) returns: [((0, 0), Direction.EAST), ((1, 0), Direction.NORTH)]
|
||||||
shortest_path((0,0), (1,2)) returns: None
|
shortest_path((0,0), (1,2)) returns: None
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -5,8 +5,8 @@ import ev3dev.ev3 as ev3
|
||||||
'''
|
'''
|
||||||
add enum for color definitions (type should be tupel of int's).
|
add enum for color definitions (type should be tupel of int's).
|
||||||
later onwards compare the idividual readouts like this to determine the color:
|
later onwards compare the idividual readouts like this to determine the color:
|
||||||
RED(>90, <40, <25)
|
RED = (>90, <40, <25)
|
||||||
BLUE(<25, >75, >90)
|
BLUE = (<25, >75, >90)
|
||||||
still needs to be tested and implemented
|
still needs to be tested and implemented
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -24,13 +24,13 @@ class Sensor:
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
print("ERROR: incorrect sensor mode:" + self._sensor.mode)
|
print("ERROR: incorrect sensor mode:", self._sensor.mode)
|
||||||
|
|
||||||
def getbrightness(self):
|
def getbrightness(self):
|
||||||
if(self._sensor.mode == 'COL-REFLECT'):
|
if(self._sensor.mode == 'COL-REFLECT'):
|
||||||
return self._sensor.value()
|
return self._sensor.value()
|
||||||
else:
|
else:
|
||||||
print("ERROR: incorrect sensor mode:" + self._sensor.mode)
|
print("ERROR: incorrect sensor mode:", self._sensor.mode)
|
||||||
|
|
||||||
def setmode(self, newmode):
|
def setmode(self, newmode):
|
||||||
self._sensor.mode = newmode
|
self._sensor.mode = newmode
|
||||||
|
|
Loading…
Reference in a new issue