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

patterning lines, something is still wrong calling method from drive_root

parent 3a2db5ae
No related branches found
No related tags found
No related merge requests found
......@@ -104,12 +104,13 @@ 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)
## 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:
## self.pattern_dashes(new_data, self.dash_count)
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)
def adjust_for_perimeter_if_needed(self, message):
......@@ -122,17 +123,15 @@ class RootDevice(gatt.Device):
for i in range(3,18):
if message[i] in color_red:
n += 1
print("all - red", n)
if n > 13: #number of sensors read the color
print("in all colors are red")
self.drive_backwards()
self.currently_adjusting_for_perimeter = True
print("in all colors are red - driving backwards")
return
n = 0
for i in range(3,8):
if message[i] in color_red:
n += 1
print("all - left", n)
if n > 3:
self.steer(90,10)
self.currently_adjusting_for_perimeter = True
......@@ -142,9 +141,7 @@ class RootDevice(gatt.Device):
for i in range(13,18):
if message[i] in color_red:
n += 1
print("all - right", n)
if n > 3:
print("in n > 3")
self.steer(10,90)
self.currently_adjusting_for_perimeter = True
print("steering right")
......@@ -152,33 +149,39 @@ class RootDevice(gatt.Device):
print("OUT OF LOOP")
if self.currently_adjusting_for_perimeter:
self.currently_adjusting_for_perimeter = False
## self.stop()
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:
self.pen_down()
t_end = time.time() + 2
while time.time() < t_end:
if (self.dash_count % 2 == 0):
print("pen-down, driving")
self.pen_down()
self.drive_forward()
self.stop()
print("pen-down, driving")
self.pen_up()
t_end = time.time() + 2
while time.time() < t_end:
return
else:
print("pen up, drive forward")
self.pen_up()
self.drive_forward()
self.stop()
print("pen up, drive forward")
self.stop()
else:
return
if self.patterning_lines_enabled:
print("!!!!!!!!!!!!!!!!! turning patterning lines to FALSE")
self.patterning_lines_enabled = False
self.dash_count += self.dash_count
self.drive_forward()
return
def follow_edge(self, message):
......@@ -308,8 +311,14 @@ def drive_root(command):
manager.robot.follow_edge(last_packet)
if command == "pattern lines":
print ("pattern lines")
manager.robot.last_packet = 0
dash_count = manager.robot.last_packet
## 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)
......
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