From 0f40efa46e7bad526cc7c94deb6e46cfaf1a5af2 Mon Sep 17 00:00:00 2001
From: Sara Falcone <sara.falcone@cba.mit.edu>
Date: Tue, 4 Dec 2018 11:30:36 -0500
Subject: [PATCH] fixed pattern lines

---
 run-solleroot.py | 72 ++++++++++++++++++++++++------------------------
 1 file changed, 36 insertions(+), 36 deletions(-)

diff --git a/run-solleroot.py b/run-solleroot.py
index d55001b..1aad0c7 100644
--- a/run-solleroot.py
+++ b/run-solleroot.py
@@ -1,9 +1,7 @@
 # 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
-- 
GitLab