-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOutputLegoRiceRocket.py
70 lines (58 loc) · 2.49 KB
/
OutputLegoRiceRocket.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
from OutputLegoMindstormsNXT import *
class RiceRocket(LegoNXT):
def __init__(self, bluetooth_address):
super(RiceRocket,self).__init__(bluetooth_address)
self._name = 'THE RICE ROCKET'
self._hardware_motion_type = MTYPE_TANKSTEER
# overriding the output motion method as the rice rocket has reverse motors
def output_motion(self, object_motion, speed=None):
# if object_motion.motion_type != MTYPE_TANKSTEER:
# raise RobotBadMotionInstruction("")
direction = object_motion.direction
if speed is None:
speed = LegoNXT.speed_default
# some kind of percentage speed thing needed here
motor_speed_a = 0
motor_speed_b = 0
if direction == DDIR_AHEADLEFT:
motor_speed_a = -50
motor_speed_b = -100
elif direction == DDIR_AHEADRIGHT:
motor_speed_a = -100
motor_speed_b = -50
elif direction == DDIR_AHEAD:
motor_speed_a = -100
motor_speed_b = -100
elif direction == DDIR_LEFT:
motor_speed_a = 100
motor_speed_b = -100
elif direction == DDIR_RIGHT:
motor_speed_a = -100
motor_speed_b = 100
elif direction == DDIR_REVERSELEFT:
motor_speed_a = 50
motor_speed_b = 100
elif direction == DDIR_REVERSERIGHT:
motor_speed_a = 100
motor_speed_b = 50
elif direction == DDIR_REVERSE:
motor_speed_a = 100
motor_speed_b = 100
elif direction == DDIR_STATIONARY:
motor_speed_a = 0
motor_speed_b = 0
if (self._motor_a_speed_last != motor_speed_a) or (self._motor_b_speed_last != motor_speed_b):
logging.debug(self.name + " Motor A change:" + str(motor_speed_a) + " Motor B change:" + str(motor_speed_b))
degrees = 45
if motor_speed_a != 0:
if self._motor_a_speed_last != motor_speed_a:
self.__turn_motor(self._motor_a, motor_speed_a, degrees)
else:
self.__stop_motor(self._motor_a, None)
if motor_speed_b != 0:
if self._motor_b_speed_last != motor_speed_b:
self.__turn_motor(self._motor_b, motor_speed_b, degrees)
else:
self.__stop_motor(self._motor_b, None)
self._motor_a_speed_last = motor_speed_a
self._motor_b_speed_last = motor_speed_b