-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.py
85 lines (68 loc) · 2.54 KB
/
state.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
import event
class State():
def __init__(self, robot):
self.name = "Empty State"
self.action = None # Empty Action
self.events = [] # Empty Event
class Initial(State):
def __init__(self, robot):
self.name = "Initial State"
self.action = robot.Move_forward(robot)
self.events = [event.Obsticle(robot)]
# + self.action.events
class Follow_Path(State):
def __init__(self, robot, pointsArray):
self.name = "Following Path"
self.robot = robot
self.pointsArray = pointsArray
self.i = 0
self.setAction()
def nextWaypoint(self):
self.i += 1
if self.i < len(self.pointsArray):
self.setAction()
else:
print 'Maika ti paidjina'
self.robot.stop()
self.robot.state = State(self.robot)
def setAction(self):
(x, y) = self.pointsArray[self.i]
self.action = self.robot.Go_to(self.robot, x, y)
self.events = [event.Reached_Positon(self.robot, x, y)]
class Moving_To_Target(State):
def __init__(self, robot, x, y):
self.name = "Going To Set Coordinates"
self.action = robot.Go_to(robot, x, y)
self.events = [event.Reached_Positon(robot, x, y)]
class Homing(State):
def __init__(self, robot):
self.name = "Homing State"
self.action = robot.GoHome(robot)
self.events = self.action.events + [event.AtHome(robot)]
class Follow_wall(State):
def __init__(self, robot):
self.name = "Following Wall"
# Determine on which side of robot the wall is
sensor_values = robot.readScaledIR()
if sum(sensor_values[0:2]) > sum(sensor_values[3:5]):
print "WALL ON LEFT"
self.wall_position = "left"
else:
print "WALL ON RIGTH"
self.wall_position = "right"
self.action = robot.Adjust_to_wall(robot, self.wall_position)
self.events = self.action.events + [event.Lost_obsticle(robot)]#, event.In_corner(robot)]
# class Escape_corner(State):
# def __init__(self, robot):
# self.name = "Escape Corner"
# self.action = robot.Leave_wall_behind(robot, )
# self.events = self.action.events + [event.Lost_obsticle(robot), event.Tight_corner(robot)]
class Parallel_to_wall(State):
def __init(self,robot):
self.name = "Parallel to wall"
self.action = robot.Rotate_to_wall(robot)
self.events = robot.Rotate_to_wall.events
class Correct_position(State):
pass
class Evade_obstacle(State):
pass