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

fixed pattern lines

parent e175afe7
No related branches found
No related tags found
No related merge requests found
# python3
import gatt
import threading
import time #not working...
import time
# BLE UUID's
root_identifier_uuid = '48c5d828-ac2a-442d-97a3-0c9822b04979'
......@@ -31,7 +29,6 @@ class BluetoothDeviceManager(gatt.DeviceManager):
print("[%s] Discovered: %s" % (device.mac_address, device.alias()))
self.stop_discovery() # Stop searching
self.robot = RootDevice(mac_address=device.mac_address, manager=self)
print('I HAVE BEEN MADE')
self.robot.print_message()
self.robot.connect()
......@@ -88,11 +85,11 @@ class RootDevice(gatt.Device):
if new_data[0] == DATA_TYPE_LIGHT: type = "Light Sensor"
if new_data[0] == DATA_TYPE_TOUCH: type = "Touch Sensor"
if new_data[0] == DATA_TYPE_CLIFF: type = "Cliff Sensor"
# print("{}: {}".format(type, new_data))
print("{}: {}".format(type, new_data))
## # save to object for future use
## self.last_packet = new_data
## print("{}: {}".format(type, self.last_packet))
# save COLOR INFO to object for future use
self.last_packet = new_data
print("{}: {}".format(type, self.last_packet))
# Perimeter detect, then other color functions
# check if you're at the perimeter every time there is new color data
......@@ -114,6 +111,9 @@ class RootDevice(gatt.Device):
print("{}: {}".format(type, message))
n = 0
adjusted = False
# THERE ARE DRIVE LEFT AND DRIVE RIGHT COMMANDS!
if all(message) in color_black:
drive_backwards()
adjusted = True
......@@ -122,7 +122,7 @@ class RootDevice(gatt.Device):
if message[i] in color_black:
n += 1
if n > 3:
self.turn_rate(-90)
self.turn_rate(-30)
self.drive_forward()
adjusted = True
return adjusted
......@@ -131,40 +131,37 @@ class RootDevice(gatt.Device):
if message[i] in color_black:
n += 1
if n > 3:
self.turn_rate(90)
self.turn_rate(30)
self.drive_forward()
adjusted = True
return adjusted
return adjusted
def pattern_dashes(self, message):
# pen down, pen up, so many times
print("IN PATTERN DASHES")
self.drive_forward()
count = 0
## #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
while count < 3: # number of lines robot will draw
self.pen_down()
t_end = time.time() + 5
while time.time() < t_end:
self.drive_forward()
self.stop()
time.sleep(1)
print("pen-down, driving")
self.pen_up()
t_end = time.time() + 5
while time.time() < t_end:
self.drive_forward()
self.stop()
time.sleep(1)
print("pen up, drive forward")
count += 1
print("out of loop!")
self.stop()
self.patterning_lines_enabled = False
def follow_edge(self, message):
......@@ -251,6 +248,8 @@ class RootDevice(gatt.Device):
def drive_root(command):
angle = 0
last_packet = manager.robot.last_packet
if command == "f":
print ("Drive forward")
manager.robot.drive_forward()
......@@ -289,10 +288,11 @@ def drive_root(command):
if command == "edge":
print ("edge")
manager.robot.edge_following_enabled = True
# manager.robot. #send last packet to function so the robot moves
manager.robot.follow_edge(last_packet)
if command == "pattern lines":
print ("pattern lines")
manager.robot.patterning_lines_enabled = True
manager.robot.pattern_dashes(last_packet)
# start here if run as program / not imported as module
......
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