-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobot.py
33 lines (25 loc) · 1.21 KB
/
robot.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
class Robot(object):
def __init__(self):
self.left_motor_speed = 0
self.right_motor_speed = 0
self.formatted_serial_data = []
def set_motor_speed(self, left_motor_speed=None, right_motor_speed=None):
if left_motor_speed is not None:
if -1028 < left_motor_speed < 1028:
self.left_motor_speed = left_motor_speed
else:
raise(Exception('left motor ({}) is out of motor speed bounds. It has to be between -1028 and 1028'.format(left_motor_speed)))
if right_motor_speed is not None:
if -1028 < right_motor_speed < 1028:
self.right_motor_speed = right_motor_speed
else:
raise(Exception('right motor ({}) is out of motor speed bounds. It has to be between -1028 and 1028'.format(right_motor_speed)))
if left_motor_speed is None and right_motor_speed is None:
raise(Exception('No speed was set for either motor'))
def send_data(self):
self._format_data()
self._send_to_arduino()
def _format_data(self):
self.formatted_serial_data = [self.left_motor_speed, self.right_motor_speed]
def _send_to_arduino(self):
pass