Commit 2f692688 authored by Sara Falcone's avatar Sara Falcone

hella added DASHES! wit PERIMETER!

parent e2f2d1a4
......@@ -104,13 +104,16 @@ class RootDevice(gatt.Device):
# save COLOR INFO to object for future use
self.last_packet = new_data
self.adjust_for_perimeter_if_needed(new_data)
return # If you're busy adjusting for perimeter,
# any senor data is used in that function and
# then no longer valid
if type == "Color Sensor" and self.edge_following_enabled:
print("new data - calling edge following")
self.follow_edge(new_data)
if type == "Color Sensor" and self.patterning_lines_enabled:
print("new data - calling patterning")
self.dash_count(self.dash_count)
self.pattern_dashes(new_data, self.dash_count)
## elif type == "Color Sensor" and self.patterning_lines_enabled:
## print("new data - calling patterning")
## self.dash_count(self.dash_count)
## self.pattern_dashes(new_data)
def adjust_for_perimeter_if_needed(self, message):
......@@ -123,9 +126,16 @@ class RootDevice(gatt.Device):
for i in range(3,18):
if message[i] in color_red:
n += 1
if n <= 3:
self.currently_adjusting_for_perimeter = False
self.drive_forward()
return
if not self.currently_adjusting_for_perimeter:
self.pen_up()
self.currently_adjusting_for_perimeter = True
if n > 13: #number of sensors read the color
self.drive_backwards()
self.currently_adjusting_for_perimeter = True
print("in all colors are red - driving backwards")
return
n = 0
......@@ -134,7 +144,6 @@ class RootDevice(gatt.Device):
n += 1
if n > 3:
self.steer(90,10)
self.currently_adjusting_for_perimeter = True
print("steering left")
return
n = 0
......@@ -143,45 +152,24 @@ class RootDevice(gatt.Device):
n += 1
if n > 3:
self.steer(10,90)
self.currently_adjusting_for_perimeter = True
print("steering right")
return
print("OUT OF LOOP")
if self.currently_adjusting_for_perimeter:
self.currently_adjusting_for_perimeter = False
self.drive_forward()
return
# thread for counting time pen down/up
def dash_count(self, count):
print("IN DASH COUNT")
threading.Timer(2.0, pattern_dashes).start()
self.dash_count += self.dash_count
print("incremented dash_count")
def pattern_dashes(self, message, count):
print("IN PATTERN DASHES")
# pen down, pen up, so many times
print("count:", count)
num_dashes_wanted = 4
if count < num_dashes_wanted:
if (self.dash_count % 2 == 0):
print("pen-down, driving")
self.pen_down()
self.drive_forward()
return
else:
print("pen up, drive forward")
self.pen_up()
self.drive_forward()
return
if self.patterning_lines_enabled:
print("!!!!!!!!!!!!!!!!! turning patterning lines to FALSE")
self.patterning_lines_enabled = False
self.drive_forward()
def do_dash_movement(self):
print('doin it')
threading.Timer(1.0, self.do_dash_movement).start()
# if self.total_dash_count >= MAX_TOTAL_DASHES:
# return
if self.currently_adjusting_for_perimeter:
return
if(self.dash_count % 2 == 0):
print("pen-down, driving")
self.pen_down()
# self.total_dash_count += 1
else:
print("pen up, drive forward")
self.pen_up()
self.dash_count += 1
def follow_edge(self, message):
......@@ -268,7 +256,7 @@ class RootDevice(gatt.Device):
def drive_root(command):
angle = 0
last_packet = manager.robot.last_packet
## last_packet = manager.robot.last_packet
if command == "f":
print ("Drive forward")
......@@ -308,20 +296,11 @@ def drive_root(command):
if command == "edge":
print ("edge")
manager.robot.edge_following_enabled = True
manager.robot.follow_edge(last_packet)
manager.robot.follow_edge(manager.robot.last_packet)
if command == "pattern lines":
print ("pattern lines")
## SOMETHING IS WRONG HERE CALLING THESE ATTRIBUTES
## manager.robot.last_packet = 0
## dash_count = self.dash_count(self.dash_count)
last_packet = manager.robot.last_packet
dash_count = manager.robot.dash_count
manager.robot.patterning_lines_enabled = True
manager.robot.pattern_dashes(last_packet, dash_count)
manager.robot.drive_forward()
manager.robot.do_dash_movement()
# start here if run as program / not imported as module
if __name__ == "__main__":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment