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

added color bank in global name space

parent 8c62d78f
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3 # python3
import gatt import gatt
import threading import threading
import time import time #not working...
# BLE UUID's # BLE UUID's
...@@ -11,13 +11,18 @@ uart_service_uuid = '6e400001-b5a3-f393-e0a9-e50e24dcca9e' ...@@ -11,13 +11,18 @@ uart_service_uuid = '6e400001-b5a3-f393-e0a9-e50e24dcca9e'
tx_characteristic_uuid = '6e400002-b5a3-f393-e0a9-e50e24dcca9e' # Write tx_characteristic_uuid = '6e400002-b5a3-f393-e0a9-e50e24dcca9e' # Write
rx_characteristic_uuid = '6e400003-b5a3-f393-e0a9-e50e24dcca9e' # Notify rx_characteristic_uuid = '6e400003-b5a3-f393-e0a9-e50e24dcca9e' # Notify
# message types
DATA_TYPE_COLOR_SENSOR = 4 DATA_TYPE_COLOR_SENSOR = 4
DATA_TYPE_BUMPER = 12 DATA_TYPE_BUMPER = 12
DATA_TYPE_LIGHT = 13 DATA_TYPE_LIGHT = 13
DATA_TYPE_TOUCH = 17 DATA_TYPE_TOUCH = 17
DATA_TYPE_CLIFF = 20 DATA_TYPE_CLIFF = 20
# color classifications
color_black = [17, 68]
color_red = [34]
color_green = [51]
class BluetoothDeviceManager(gatt.DeviceManager): class BluetoothDeviceManager(gatt.DeviceManager):
robot = None # root robot device robot = None # root robot device
...@@ -30,9 +35,12 @@ class BluetoothDeviceManager(gatt.DeviceManager): ...@@ -30,9 +35,12 @@ class BluetoothDeviceManager(gatt.DeviceManager):
self.robot.connect() self.robot.connect()
class RootDevice(gatt.Device): class RootDevice(gatt.Device):
# states for our robot primatives
edge_following_enabled = False edge_following_enabled = False
patterning_lines_enabled = False patterning_lines_enabled = False
# "message" allows last sensor readings to be stored in the robot object for each robot
message = "no message yet"
def print_message(self): def print_message(self):
print(self.message) print(self.message)
...@@ -80,25 +88,43 @@ class RootDevice(gatt.Device): ...@@ -80,25 +88,43 @@ class RootDevice(gatt.Device):
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))
# Do the thing! # Perimeter detect, then other color functions
if new_data[0] == DATA_TYPE_COLOR_SENSOR: if new_data[0] == DATA_TYPE_COLOR_SENSOR:
print("new data - calling perimeter")
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")
self.follow_edge(new_data) self.follow_edge(new_data)
if type == "Color Sensor" and self.patterning_lines_enabled: if type == "Color Sensor" and self.patterning_lines_enabled:
self.pattern_dashes(new_data) self.pattern_dashes(new_data)
def adjust_for_perimeter_if_needed(self, data): def adjust_for_perimeter_if_needed(self, message):
adjusted = False # Check to see if you're at perimeter! If you are, turn and update your state
print("IN ADJUST PERIMETER")
# TODO: Check to see if you're at perimeter! If you are, update your state and set n = 0
# adjusted = True for i in range(3,5):
if message[i] in color_black:
n += 1
if n > 1:
self.turn_rate(-45)
adjusted = True
else:
adjusted = False
n = 0
for i in range(16,18):
if message[i] in color_black:
n += 1
if n > 1:
self.turn_rate(45)
adjusted = True
else:
adjusted = False
return adjusted return adjusted
def pattern_dashes(self, message): def pattern_dashes(self, message):
print("IN PATTERN DASHES")
#pen down, pen up, so many times... #pen down, pen up, so many times...
count = 0 count = 0
while count < 3: # number of lines robot will draw while count < 3: # number of lines robot will draw
...@@ -126,6 +152,7 @@ class RootDevice(gatt.Device): ...@@ -126,6 +152,7 @@ class RootDevice(gatt.Device):
def follow_edge(self, message): def follow_edge(self, message):
print("IN FOLLOW EDGE")
if message[3] != 0 or message[4] != 0: if message[3] != 0 or message[4] != 0:
#drive_root("l") #drive_root("l")
self.turn_rate(-45) self.turn_rate(-45)
...@@ -163,9 +190,7 @@ class RootDevice(gatt.Device): ...@@ -163,9 +190,7 @@ class RootDevice(gatt.Device):
#drive_root("v") #drive_root("v")
turn_state = 2 turn_state = 2
else: else:
drive_root("f") self.drive_forward()
#manager.robot.drive_forward_slow()
#drive_root("a")
def drive_forward(self): def drive_forward(self):
self.tx_characteristic.write_value([0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD1]) self.tx_characteristic.write_value([0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD1])
......
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