Skip to content
Snippets Groups Projects
Commit 8c62d78f authored by Sara Falcone's avatar Sara Falcone
Browse files

add pattern dashes function

parent 9ce5ad00
No related branches found
No related tags found
No related merge requests found
...@@ -30,8 +30,8 @@ class BluetoothDeviceManager(gatt.DeviceManager): ...@@ -30,8 +30,8 @@ class BluetoothDeviceManager(gatt.DeviceManager):
self.robot.connect() self.robot.connect()
class RootDevice(gatt.Device): class RootDevice(gatt.Device):
message = "no message"
edge_following_enabled = False edge_following_enabled = False
patterning_lines_enabled = False
def print_message(self): def print_message(self):
print(self.message) print(self.message)
...@@ -82,12 +82,13 @@ class RootDevice(gatt.Device): ...@@ -82,12 +82,13 @@ class RootDevice(gatt.Device):
# Do the thing! # Do the thing!
if new_data[0] == DATA_TYPE_COLOR_SENSOR: if new_data[0] == DATA_TYPE_COLOR_SENSOR:
did_adjust = adjust_for_perimeter_if_needed(new_data) did_adjust = self.adjust_for_perimeter_if_needed(new_data)
if did_adjust: if did_adjust:
return return
if type == "Color Sensor" and self.edge_following_enabled: if type == "Color Sensor" and self.edge_following_enabled:
self.follow_edge(new_data) self.follow_edge(new_data)
if type == "Color Sensor" and self.patterning_lines_enabled:
self.pattern_dashes(new_data)
def adjust_for_perimeter_if_needed(self, data): def adjust_for_perimeter_if_needed(self, data):
adjusted = False adjusted = False
...@@ -96,34 +97,60 @@ class RootDevice(gatt.Device): ...@@ -96,34 +97,60 @@ class RootDevice(gatt.Device):
# adjusted = True # adjusted = True
return adjusted return adjusted
def pattern_dashes(self, message):
#pen down, pen up, so many times...
count = 0
while count < 3: # number of lines robot will draw
print(count)
t0 = time.time() #FIX TIME
t1 = time.time()
delta_t = t1 - t0
print(delta_t)
self.pen_down()
self.drive_forward()
while delta_t < 5000: # ms pen down
self.drive_forward()
t1 = time.time()
delta_t = t1 - t0
t0 = time.time()
print(count)
self.pen_up()
while delta_t < 3000: # ms pen up
t1 = time.time()
delta_t = t1 - t0
count += 1
self.pen_up()
self.patterning_lines_enabled = False
def follow_edge(self, message): def follow_edge(self, message):
if message[3] != 0 or message[4] != 0: if message[3] != 0 or message[4] != 0:
#drive_root("l") #drive_root("l")
manager.robot.turn_rate(-45) self.turn_rate(-45)
#manager.robot.drive_left_slow() #manager.robot.drive_left_slow()
#drive_root("z") #drive_root("z")
turn_state = 1 turn_state = 1
elif message[5] != 0 or message[6] != 0: elif message[5] != 0 or message[6] != 0:
#drive_root("l") #drive_root("l")
manager.robot.turn_rate(-30) self.turn_rate(-30)
#manager.robot.drive_left_slow_slow() #manager.robot.drive_left_slow_slow()
#drive_root("x") #drive_root("x")
turn_state = 1 turn_state = 1
#drive_root("f") #drive_root("f")
#print("test1") #print("test1")
elif message[7] != 0 or message[8] != 0: elif message[7] != 0 or message[8] != 0:
drive_root("f") #drive_root("f") # calling the member function versus out into global space
self.drive_forward()
elif message[9] != 0 or message[10] != 0: elif message[9] != 0 or message[10] != 0:
manager.robot.turn_rate(30) self.turn_rate(30)
elif message[12] != 0 or message[11] != 0: elif message[12] != 0 or message[11] != 0:
manager.robot.turn_rate(45) self.turn_rate(45)
elif message[14] != 0 or message[13] != 0: elif message[14] != 0 or message[13] != 0:
#drive_root("r") #drive_root("r")
manager.robot.turn_rate(60) self.turn_rate(60)
#manager.robot.drive_right_slow_slow() #manager.robot.drive_right_slow_slow()
#drive_root("c") #drive_root("c")
turn_state = 2 turn_state = 2
...@@ -131,7 +158,7 @@ class RootDevice(gatt.Device): ...@@ -131,7 +158,7 @@ class RootDevice(gatt.Device):
#print("test2") #print("test2")
elif message[16] != 0 or message[15] != 0: elif message[16] != 0 or message[15] != 0:
#drive_root("r") #drive_root("r")
manager.robot.turn_rate(60) self.turn_rate(60)
#manager.robot.drive_right_slow() #manager.robot.drive_right_slow()
#drive_root("v") #drive_root("v")
turn_state = 2 turn_state = 2
...@@ -160,12 +187,6 @@ class RootDevice(gatt.Device): ...@@ -160,12 +187,6 @@ class RootDevice(gatt.Device):
def pen_down(self): def pen_down(self):
self.tx_characteristic.write_value([0x02, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]) self.tx_characteristic.write_value([0x02, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
# def pattern_fill_straight(self):
# pen_down(self)
# Timer(30, drive_forward(self))
def turn_rate(self, rate): def turn_rate(self, rate):
...@@ -221,10 +242,16 @@ def drive_root(command): ...@@ -221,10 +242,16 @@ def drive_root(command):
manager.robot.steer(30,40) manager.robot.steer(30,40)
if command == "clear": if command == "clear":
print ("clear all") print ("clear all")
manager.robot.stop()
manager.robot.edge_following_enabled = False manager.robot.edge_following_enabled = False
manager.robot.patterning_lines_enabled = False
if command == "edge": if command == "edge":
print ("edge") print ("edge")
manager.robot.edge_following_enabled = True manager.robot.edge_following_enabled = True
if command == "pattern lines":
print ("pattern lines")
manager.robot.patterning_lines_enabled = True
# start here if run as program / not imported as module # start here if run as program / not imported as module
if __name__ == "__main__": if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment