-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirectionBoatRotation.py
48 lines (43 loc) · 1.44 KB
/
DirectionBoatRotation.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
import Command
import DirectionNone
CENTER = 0
LEFT = 1
RIGHT = 2
class DirectionBoatRotation(DirectionNone.DirectionNone):
def __init__(self):
self.direction = CENTER
pass
def run(self, rotation_diff):
if rotation_diff > 1.0:
# print("left")
if self.direction != LEFT:
Command.BOAT_STEER_RIGHT(0)
Command.BOAT_STEER_LEFT(0)
Command.start_BOAT_CENTER_RUDDER()
self.direction = LEFT
else:
Command.stop_BOAT_CENTER_RUDDER()
Command.BOAT_STEER_LEFT(100)
elif rotation_diff < -1.0:
# print("right")
if self.direction != RIGHT:
Command.BOAT_STEER_RIGHT(0)
Command.BOAT_STEER_LEFT(0)
Command.start_BOAT_CENTER_RUDDER()
self.direction = RIGHT
else:
Command.stop_BOAT_CENTER_RUDDER()
Command.BOAT_STEER_RIGHT(100)
else:
if self.direction != CENTER:
Command.BOAT_STEER_RIGHT(0)
Command.BOAT_STEER_LEFT(0)
Command.start_BOAT_CENTER_RUDDER()
self.direction = CENTER
else:
Command.stop_BOAT_CENTER_RUDDER()
def reset(self):
self.__init__()
Command.BOAT_STEER_LEFT(0)
Command.BOAT_STEER_RIGHT(0)
Command.stop_BOAT_CENTER_RUDDER()