This commit is contained in:
Cole Deck 2024-05-14 20:29:32 -05:00
parent 32260595a1
commit fa25b2c8b1
3 changed files with 17 additions and 9 deletions

View File

@ -2,16 +2,22 @@ import http.server
import socketserver import socketserver
import os import os
class CORSHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
self.send_header('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type')
http.server.SimpleHTTPRequestHandler.end_headers(self)
def run_server(port, directory): def run_server(port, directory):
""" """
Run a simple HTTP server serving files from the specified directory. Run a simple HTTP server serving files from the specified directory with CORS enabled.
""" """
# Change the working directory to the specified directory # Change the working directory to the specified directory
os.makedirs(directory, exist_ok=True) os.makedirs(directory, exist_ok=True)
os.chdir(directory) os.chdir(directory)
# Create the HTTP server # Create the HTTP server using the CORS-enabled handler
handler = http.server.SimpleHTTPRequestHandler with socketserver.TCPServer(("", port), CORSHTTPRequestHandler) as httpd:
with socketserver.TCPServer(("", port), handler) as httpd: print(f"Serving files at port {port} with CORS enabled")
print(f"Serving cable images & files at port {port}")
httpd.serve_forever() httpd.serve_forever()

8
run.py
View File

@ -483,18 +483,20 @@ def get_sensors():
val = val[0] val = val[0]
if val == 1 and sensors[idx] >= 0: # skip negative values if val == 1 and sensors[idx] >= 0: # skip negative values
sensors[idx] += 1 sensors[idx] += 1
else: elif val == 0:
if sensors[idx] >= 4: if sensors[idx] >= 4:
sensors[idx] -= 4 sensors[idx] -= 4
else:
sensors[idx] += 4
else: else:
out = [0, 0, 0, 0] sensors = [0, 0, 0, 0]
#fprint("Values: " + str(sensors)) #fprint("Values: " + str(sensors))
#mbconn.close() #mbconn.close()
for x in range(len(sensors)): for x in range(len(sensors)):
if sensors[x] >= 180: # 3 sec if sensors[x] >= 180: # 3 sec
# cable newly detected on tray # cable newly detected on tray
sensors[x] = -10000 sensors[x] = -180
fprint("Precense detected: slot " + str(x)) fprint("Precense detected: slot " + str(x))
return x return x

View File

@ -590,7 +590,7 @@ def tray_routine(robot, slot=0, pick_up=True):
] ]
if pick_up: if pick_up:
open_gripper() open_gripper()
rob.movel(slot_position[slot],vel=0.2, acc=1) rob.movel(slot_position[slot], vel=0.2, acc=1)
# Place/Grab the tube # Place/Grab the tube
if pick_up: if pick_up: