Skip to content
Snippets Groups Projects
Commit 450fd3f4 authored by mosesafr's avatar mosesafr
Browse files

Restructured repo, modified venv

parent 9ff5a3b8
No related branches found
No related tags found
No related merge requests found
Showing
with 80 additions and 187 deletions
File added
from enum import Enum
class BluetoothStatusEnum(Enum):
Disconnected = 1
Connected = 2
Failed_To_Connect = 3
\ No newline at end of file
from enum import Enum
class DroneStatusEnum(Enum):
Uninitialized = 1
Location_Unknown_Idle = 2
Location_Known_Idle = 3
Moving = 4
Stopped = 5
\ No newline at end of file
No preview for this file type
File added
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -16,7 +16,7 @@ def main():
grid_array = np.array(grid_matrix)
np.save('Application/Core/grid.npy', grid_array)
np.save('Mothership/Application/Core/grid.npy', grid_array)
if __name__ == "__main__":
main()
\ No newline at end of file
from bluedot.btcomm import BluetoothServer
from time import sleep
from signal import pause
from droneStatusEnum import DroneStatusEnum
from bluetoothStatusEnum import BluetoothStatusEnum
class BLEClientPi:
_instance = None
def __new__(cls):
if cls._instance is None:
cls._instance = super(BLEServicePi, cls).__new__(cls)
cls._instance.coordinate_queue = None
cls._instance.command_queue = None
cls._instance.drone_status = DroneStatusEnum.Uninitialized
cls._instance.bluetooth_status = BluetoothStatusEnum.Disconnected
cls._instance.bluetoothClient = None
return cls._instance
def data_received(data):
print("recv - {}".format(data))
def connect():
try:
cls.bluetoothClient = BluetoothClient("pi4", data_received)
cls.bluetoothClient.send("Connectedddd")
finally:
cls.bluetoothClient.disconnect()
from enum import Enum
class BluetoothStatusEnum(Enum):
Disconnected = 1
Connected = 2
Failed_To_Connect = 3
\ No newline at end of file
from enum import Enum
class DroneStatusEnum(Enum):
Uninitialized = 1
Location_Unknown_Idle = 2
Location_Known_Idle = 3
Moving = 4
Stopped = 5
\ No newline at end of file
......@@ -19,8 +19,8 @@ class DroneTracker:
cls.difference_image = None
cls.base_image = None
with PiCamera() as camera:
camera.capture('base_image.jpg')
cls.base_image = cv2.imread('base_image.jpg', cv2.IMREAD_GRAYSCALE)
camera.capture('Mothership/Images/base_image.jpg')
cls.base_image = cv2.imread('Mothership/Images/base_image.jpg', cv2.IMREAD_GRAYSCALE)
def get_grid_feed(cls):
if cls.base_image is None:
......@@ -32,8 +32,8 @@ class DroneTracker:
def detect_drone(cls):
with PiCamera() as camera:
camera.capture("captured_image.jpg")
cls.captured_image = cv2.imread("captured_image.jpg", cv2.IMREAD_GRAYSCALE)
camera.capture("Mothership/Images/captured_image.jpg")
cls.captured_image = cv2.imread("Mothership/Images/captured_image.jpg", cv2.IMREAD_GRAYSCALE)
# Detect the drone by determing difference from base image
difference_image = cv2.absdiff(cls.base_image, cls.captured_image)
......@@ -73,8 +73,8 @@ class DroneTracker:
drone_y = int(y_avg / (cls.base_image.shape[1]/ grid_y_dim))
cls.difference_image = difference_image
cv2.imwrite("difference_image.jpg",difference_image)
cv2.imwrite("segmentation.jpg",thresholded_image)
cv2.imwrite("Mothership/Images/difference_image.jpg",difference_image)
cv2.imwrite("Mothership/Images/segmentation.jpg",thresholded_image)
return (drone_x, drone_y)
else:
print("Unable to detect drone")
\ No newline at end of file
import argparse
import serial
import sys
import time
# TODO: Make sure teensy_port matches the port for Teensy
# given in the Arduino IDE, and bt_port matches the output
# of the Bluetooth manager when opening a serial connection
# to the HC-05
teensy_port = '/dev/ttyACM0' # Teensy Serial port
bt_port = '/dev/rfcomm0' # HC-05 port
bt_baud = 38400
def fft_bin_to_motor():
''' Control servo motors via bluetooth based on FFT of signal
fed into the Teensy '''
serbt = serial.Serial(bt_port, bt_baud)
# initialize Serial port for Teensy connection
ser = serial.Serial()
ser.port = teensy_port # Teensy Serial port
ser.baudrate = 9600
ser.timeout = None # specify timeout when using readline()
ser.open()
if ser.is_open:
print('Serial port now open. Configuration:\n')
print(ser, '\n') # print serial parameters
while True:
# Acquire and parse data from Serial port
try:
line = ser.readline() # ascii
except serial.SerialException:
ser = serial.Serial()
ser.port = teensy_port # Teensy Serial port
ser.baudrate = 9600
ser.timeout = None # specify timeout when using readline()
try:
ser.open()
except serial.SerialException:
continue
if ser.is_open:
continue
# split incoming CSV by commas and store in a list
line_as_list = line.strip().split(b' ')
map_object = map(float, line_as_list)
list_of_int = list(map_object)
# print(list_of_int)
# find FFT bin with max coefficient, skip if its 0
max_bin = list_of_int.index(max(list_of_int))
if max_bin == 0:
continue
print(max_bin) # uncomment to see the index
# TODO: Write 'L' to move the left servo, and 'R' to move the right servo.
# Create your own logic that will move one of the servos at a time
# based on the maximum FFT bin form the Teensy
# if ?????:
# command = 'L'
# elif ?????:
# command = 'R'
serbt.write(command.encode('utf-8')) # write to the HC-05
print(command)
def latency():
''' Measure the latency in a round-trip bluetooth packet
to the HC-05 unit '''
ser = serial.Serial(bt_port, bt_baud)
print('Sending data...')
temp = ""
start = False
start_time = time.time()
ser.write('From RasPi'.encode('ascii'))
# Define start_char and end_char
start_char = 60
end_char = 62
while (True):
if (ser.inWaiting() > 0):
# Grab single character and find its ASCII code
character = ser.read()
latency = time.time() - start_time
asciiOrd = ord(character)
if (asciiOrd == start_char and start is True):
temp = "" # start over
elif (asciiOrd == start_char and start is False):
start = True
elif (asciiOrd != start_char and asciiOrd != end_char and start is True):
temp += character.decode('ascii')
elif (asciiOrd == end_char and start is True):
# Print our message + latency
if len(temp) > 0:
try:
print('Receiving new reading:', temp, '\n')
# Acknowledge receipt of data
print(latency)
break
except Exception as e:
print(e)
start = False
temp = ""
def rate():
''' Measure data rate of bluetooth connection to HC-05 '''
ser = serial.Serial(bt_port, bt_baud)
print('Sending data...')
# Sleep for a second for a chance to connect
time.sleep(1)
for i in range(100):
ser.write((str(i) + '\n').encode('ascii'))
print('End')
def size():
''' Output size of message sent in 'rate' '''
s = ""
for i in range(100):
s += str(i) + '\n'
print(sys.getsizeof(s), "bytes")
def main():
global bt_baud, bt_port, teensy_port
parser = argparse.ArgumentParser(description='EECS 452 Bluetooth Driver')
parser.add_argument('function', metavar='function', type=str,
choices=['bt_fft', 'latency', 'rate', 'size'],
help='The name of the function to run: "bt_fft", "latency", "rate", or "size"')
parser.add_argument('-b', '--bt-baud', type=int, dest='bt_baud', default=bt_baud,
help='Baud Rate for HC-05 Module')
parser.add_argument('-p', '--bt-port', type=str, dest='bt_port', default=bt_port,
help='/dev/<port> for HC-05 Module')
parser.add_argument('--teensy-port', type=str, dest='teensy_port', default=teensy_port,
help='/dev/<port> for Teensy')
parser.add_argument('-d', '--debug', action='store_true', default=False,
help='Print out serial port information for HC-05 and Teensy')
args = parser.parse_args()
if args.bt_baud is not None:
bt_baud = args.bt_baud
if args.bt_port is not None:
bt_port = args.bt_port
if args.teensy_port is not None:
teensy_port = args.teensy_port
if args.debug:
print("Debug:")
print("bt_baud: ", bt_baud)
print("bt_port: ", bt_port)
print("teensy_port: ", teensy_port)
print()
if args.function == 'bt_fft':
fft_bin_to_motor()
elif args.function == 'latency':
latency()
elif args.function == 'rate':
rate()
elif args.function == 'size':
size()
if __name__ == '__main__':
main()
import numpy as np
from Common.gridDestinationEnum import GridDestinationEnum
from Core.gridDestinationEnum import GridDestinationEnum
import heapq
import math
import time
from Core.pathfinder import Pathfinder, Node
from Core.bleService import BLEService
from Core.droneTracker import DroneTracker
from Core.bleServicePi import BLEServicePi
""" Since Dash doesn't support global variables we'll keep this as a singleton"""
class Mothership:
_instance = None
......@@ -54,7 +56,9 @@ class Mothership:
cls.drone_location = (node[0], node[1])
def subscribe_to_drone(cls):
cls.ble_service = BLEService("TeensyBLE","E2:16:D3:7E:29:03")
# We're not using teensy anymore
#cls.ble_service = BLEService("TeensyBLE","E2:16:D3:7E:29:03")
cls.ble_service = BLEServicePi()
cls.ble_service.connect()
cls.drone_location = (0,0)
......
......@@ -5,8 +5,9 @@ from dash.dependencies import Input, Output, State
import os
# Set working directory
script_dir = os.path.dirname(os.path.realpath(__file__))
os.chdir(script_dir)
#script_dir = os.path.dirname(os.path.realpath(__file__))
#print(script_dir)
#os.chdir(script_dir)
app = Dash(__name__, use_pages = True, external_stylesheets = [dbc.themes.BOOTSTRAP])
......
No preview for this file type
......@@ -5,9 +5,10 @@ from dash.dependencies import Input, Output, State
import dash_bootstrap_components as dbc
import plotly.express as px
import pandas as pandas
from Common.gridDestinationEnum import GridDestinationEnum
import plotly.graph_objs as go
from Core.mothership import Mothership
from Core.gridDestinationEnum import GridDestinationEnum
import plotly.graph_objs as go
mothership = Mothership("/")
""" UI Components """
......
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