Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added ScriptManager/.DS_Store
Binary file not shown.
15 changes: 13 additions & 2 deletions ScriptManager/ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,14 @@ def __find_lines(input):

from picamera import PiCamera
from picamera.array import PiRGBArray

from table import Table
import io

table = Table(1)

grip = GripPipeline()


def main (stop_message):

def connection(stop_message):
Expand Down Expand Up @@ -227,13 +230,21 @@ def connection(stop_message):
cv2.rectangle(grip.mask_output,(x1,y1),(x2,y2),(255,255,255),2)
sideX = ((x1-x2)/2)+x2
sideY = ((y1-y2)/2)+y2
width = x2-x1
cv2.circle(grip.mask_output,(int(sideX),int(sideY)),50,(255,255,255),2)
print("Ball found")


table.updateNumber((sideX, sideY))
table.updateNumber(width, key=1)
except Exception as e:
print(e)
print("--------------")
print("Ball not found")
cv2.imshow('frame',grip.mask_output)

table.updateNumber("B")
table.updateNumber("B", key=1)

rawCap.truncate(0)
## xraw.seek(0)

Expand Down
23 changes: 23 additions & 0 deletions ScriptManager/listener.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import time
from networktables import NetworkTables as nt

nt.initialize(server="10.15.12.2")

table = nt.getTable("chooser_data")
table2 = nt.getTable("tape_data")
table3 = nt.getTable("ball_data")

def valueChanged(table, key, value, isNew):
print("Changed:", table, key, value)

def connectionListener(info, connected):
print("Connected:", info, "Connection:", connected[0],"-",connected[1])

nt.addConnectionListener(connectionListener)

table.addEntryListener(valueChanged)
table2.addEntryListener(valueChanged)
table3.addEntryListener(valueChanged)

while True:
time.sleep(5)
6 changes: 3 additions & 3 deletions ScriptManager/scriptmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from networktables import NetworkTables as nt

import tape3
import thread_example
import ball
import thread_example

ip = "10.31.51.43"
ip = "10.15.12.2"

nt.initialize(server=ip)
table = nt.getTable("chooser_data")
Expand Down Expand Up @@ -34,7 +34,7 @@ def valueChanged(table, key, value, isNew):

if value != 0:
time.sleep(1)

print("[*]Starting thread: {}".format(value))
t = threading.Thread(target=target_list[value])
t.start()
Expand Down
21 changes: 21 additions & 0 deletions ScriptManager/table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from networktables import NetworkTables as nt

table_list = ["tape_data", "ball_data"]
key_list = ["midpoint", "width"]

class Table:

def __init__(self, table_number):
nt.initialize(server='10.31.51.43')
self.table = nt.getTable(table_list[table_number])

def updateNumber(self, midpoint, key = 0):
table = self.table

try:
table.putString(key_list[key],str(midpoint))
except Exception as e:
print(e)


#https://robotpy.readthedocs.io/projects/pynetworktables/en/stable/examples.html
26 changes: 18 additions & 8 deletions ScriptManager/tape3.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def __init__(self):

self.__hsv_threshold_input = self.blur_output
self.__hsv_threshold_hue = [0.0, 180.0]
self.__hsv_threshold_saturation = [0.0, 47.0]
self.__hsv_threshold_value = [252.0, 255.0]
self.__hsv_threshold_saturation = [0.0, 255.0]
self.__hsv_threshold_value = [190.0, 255.0]

self.hsv_threshold_output = None

Expand Down Expand Up @@ -113,9 +113,7 @@ def midpoint(box_list):
else:
y += y1

midx, midy = int(x), int(y)

return (midx, midy)
return (round(x,2),round(y2))

#Defines bounding boxes from contours
def find_boxes(contours):
Expand Down Expand Up @@ -149,13 +147,16 @@ def find_boxes(contours):

from picamera.array import PiRGBArray
from picamera import PiCamera
from table import Table

table = Table(0)

BlurType = Enum('BlurType', 'Box_Blur Gaussian_Blur Median_Filter Bilateral_Filter')

g = GripPipeline()

#Minimum area of a bounding box
size_threshold = 4000
size_threshold = 250

def main(stop_message):

Expand All @@ -173,6 +174,7 @@ def connection(stop_message):
cam = PiCamera()
cam.resolution = (640, 480)
cam.framerate = 32
cam.exposure_mode = 'off'
rawCap = PiRGBArray(cam, size=(640, 480))

for frame in cam.capture_continuous(rawCap, format="bgr", use_video_port=True):
Expand Down Expand Up @@ -216,14 +218,22 @@ def connection(stop_message):
#Draws midpoint if one exists
if mid != 0:

cv2.circle(frame, (mid[0], mid[1]), 5, (0, 0, 255), -1)
cv2.circle(frame, (int(mid[0]),int(mid[1])), 5, (0, 0, 255), -1)
table.updateNumber((mid[0], mid[1]))
#table.updateNumber(-box_list[0][1][0], key=1)
table.updateNumber(-50, key=1)

print("Midpoint:", mid)

else:

table.updateNumber("B")
table.updateNumber("B", key=1)


if box_list != []:
print("************************")

cv2.imshow('frame', frame)

rawCap.truncate(0)

Expand Down
Loading