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

still stuck in perimeter

parent 0f40efa4
No related branches found
No related tags found
No related merge requests found
...@@ -86,18 +86,23 @@ class RootDevice(gatt.Device): ...@@ -86,18 +86,23 @@ class RootDevice(gatt.Device):
if new_data[0] == DATA_TYPE_TOUCH: type = "Touch Sensor" if new_data[0] == DATA_TYPE_TOUCH: type = "Touch Sensor"
if new_data[0] == DATA_TYPE_CLIFF: type = "Cliff Sensor" if new_data[0] == DATA_TYPE_CLIFF: type = "Cliff Sensor"
print("{}: {}".format(type, new_data)) print("{}: {}".format(type, new_data))
# save COLOR INFO to object for future use ## #attempt to back out of cliff even
self.last_packet = new_data ## if new_data[0] == DATA_TYPE_CLIFF:
print("{}: {}".format(type, self.last_packet)) ## t_end = time.time() + 2
## while time.time() < t_end:
## self.drive_backwards()
## self.stop()
## print("end cliff event")
# Perimeter detect, then other color functions # Perimeter detect, then other color functions
# check if you're at the perimeter every time there is new color data # check if you're at the perimeter every time there is new color data
if new_data[0] == DATA_TYPE_COLOR_SENSOR: if new_data[0] == DATA_TYPE_COLOR_SENSOR:
print("new data - calling perimeter") # save COLOR INFO to object for future use
self.last_packet = new_data
did_adjust = self.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:
print("new data - calling edge following") print("new data - calling edge following")
self.follow_edge(new_data) self.follow_edge(new_data)
...@@ -110,32 +115,35 @@ class RootDevice(gatt.Device): ...@@ -110,32 +115,35 @@ class RootDevice(gatt.Device):
print("IN ADJUST PERIMETER") print("IN ADJUST PERIMETER")
print("{}: {}".format(type, message)) print("{}: {}".format(type, message))
n = 0
adjusted = False
# THERE ARE DRIVE LEFT AND DRIVE RIGHT COMMANDS! # THERE ARE DRIVE LEFT AND DRIVE RIGHT COMMANDS!
if all(message) in color_black: if all(message) in color_red:
drive_backwards() print("in all colors are red")
adjusted = True t_end = time.time() + 3
return adjusted while time.time() < t_end:
for i in range(3,7): drive_backwards()
if message[i] in color_black: self.stop()
time.sleep(1)
n = 0
for i in range(3,8):
if message[i] in color_red:
n += 1 n += 1
if n > 3: if n > 3:
self.turn_rate(-30) t_end = time.time() + 3
self.drive_forward() while time.time() < t_end:
adjusted = True self.steer(60,20)
return adjusted self.stop()
time.sleep(1)
n = 0 n = 0
for i in range(14,18): for i in range(13,18):
if message[i] in color_black: if message[i] in color_red:
n += 1 n += 1
if n > 3: if n > 3:
self.turn_rate(30) t_end = time.time() + 3
self.drive_forward() while time.time() < t_end:
adjusted = True self.steer(20,60)
return adjusted self.stop()
return adjusted time.sleep(1)
def pattern_dashes(self, message): def pattern_dashes(self, message):
# pen down, pen up, so many times # pen down, pen up, so many times
......
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