Skip to content

Commit

Permalink
pre-commit formatting fix
Browse files Browse the repository at this point in the history
  • Loading branch information
brendenpelkie committed Oct 14, 2024
1 parent 9395d0e commit 7b75d41
Show file tree
Hide file tree
Showing 16 changed files with 936 additions and 17 deletions.
757 changes: 757 additions & 0 deletions HTTP_debug.ipynb

Large diffs are not rendered by default.

134 changes: 134 additions & 0 deletions Untitled.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "b656762c-1ca9-4f9c-9ba6-86a3f7190265",
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "1127740c-7620-447b-8204-741dfc8fe3cc",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"\n",
"# ----------- Science Jubilee -------------\n",
"from science_jubilee import Machine as Jub\n",
"from science_jubilee.tools import HTTPSyringe as syringe\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "64788e2b-4060-4b44-8c87-cf6a880ad318",
"metadata": {},
"outputs": [],
"source": [
"url = 'http://192.168.1.5:5000'\n",
"volume = {'volume':5}"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d1be2c94-8669-4bea-b057-a4a3acf035fd",
"metadata": {},
"outputs": [],
"source": [
"r = requests.get(url + '/get_status')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "8228ca74-92e4-4761-b4ef-ef0c50fe7381",
"metadata": {},
"outputs": [],
"source": [
"jubilee = Jub.Machine(address='192.168.1.2', simulated = False) "
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "c3d3bf61-1aed-476b-b36c-e2c5891f4986",
"metadata": {},
"outputs": [],
"source": [
"jubilee.home_all()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "30f0c9b9-98da-46f9-945c-34607d3abaf5",
"metadata": {},
"outputs": [],
"source": [
"deck = jubilee.load_deck('lab_automation_deck.json')"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "8378fc8c-b57c-4f31-8acd-f681403444cc",
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'super' object has no attribute '_HTTPSyringe__init'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[13], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m syringe \u001b[38;5;241m=\u001b[39m \u001b[43msyringe\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mHTTPSyringe\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfrom_config\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m3\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m/home/brendenpelkie/Code/science-jubilee/src/science_jubilee/tools/configs/10cc_syringe.json\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/Code/science-jubilee/src/science_jubilee/tools/HTTPSyringe.py:47\u001b[0m, in \u001b[0;36mHTTPSyringe.from_config\u001b[0;34m(cls, index, fp)\u001b[0m\n\u001b[1;32m 44\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mopen\u001b[39m(fp) \u001b[38;5;28;01mas\u001b[39;00m f:\n\u001b[1;32m 45\u001b[0m kwargs \u001b[38;5;241m=\u001b[39m json\u001b[38;5;241m.\u001b[39mload(f)\n\u001b[0;32m---> 47\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mcls\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mindex\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/Code/science-jubilee/src/science_jubilee/tools/HTTPSyringe.py:31\u001b[0m, in \u001b[0;36mHTTPSyringe.__init__\u001b[0;34m(self, index, url)\u001b[0m\n\u001b[1;32m 27\u001b[0m config_r \u001b[38;5;241m=\u001b[39m requests\u001b[38;5;241m.\u001b[39mget(url\u001b[38;5;241m+\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m/get_config\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 29\u001b[0m config \u001b[38;5;241m=\u001b[39m config_r\u001b[38;5;241m.\u001b[39mjson\n\u001b[0;32m---> 31\u001b[0m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m__init\u001b[49m(index, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mconfig, url \u001b[38;5;241m=\u001b[39m url)\n\u001b[1;32m 33\u001b[0m status_r \u001b[38;5;241m=\u001b[39m requests\u001b[38;5;241m.\u001b[39mget(url \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m/get_status\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 35\u001b[0m status \u001b[38;5;241m=\u001b[39m status_r\u001b[38;5;241m.\u001b[39mjson\n",
"\u001b[0;31mAttributeError\u001b[0m: 'super' object has no attribute '_HTTPSyringe__init'"
]
}
],
"source": [
"syringe = syringe.HTTPSyringe.from_config(3, \"/home/brendenpelkie/Code/science-jubilee/src/science_jubilee/tools/configs/10cc_syringe.json\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4febab10-2592-4ffa-8435-79944923c1f8",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
4 changes: 4 additions & 0 deletions docs/building/_static/center_carriage.jpg:Zone.Identifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=https://photos.google.com/
HostUrl=https://photos.fife.usercontent.google.com/pw/AP1GczNTKqrB6x5tvbBMxMTJFyDbgy_zk3AxiAneT9psVhzxOWMV_G5hJgculg=w1118-h839-s-no?authuser=0
4 changes: 4 additions & 0 deletions docs/building/_static/manual_tool_load.jpg:Zone.Identifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=https://photos.google.com/
HostUrl=https://photos.fife.usercontent.google.com/pw/AP1GczOZskrK77M2lCCHUA6WmsVrBlFzXpJk3F_SxMnI3xSaLL2wpOspwIOUOg=w755-h839-s-no?authuser=0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=https://photos.google.com/
HostUrl=https://photos.fife.usercontent.google.com/pw/AP1GczNdml1rYSJs7I5ePvPf3_soG-_yw-1atLrOcG8NfM-14XQY_JKRHXBVGA=w849-h839-s-no?authuser=0
4 changes: 4 additions & 0 deletions docs/building/_static/pin_alignment.jpg:Zone.Identifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=https://photos.google.com/
HostUrl=https://photos.fife.usercontent.google.com/pw/AP1GczOSgRCBeDBH3jrVPtdYDXOI-K-oUlXqCQRL40T92fFPf5QpQnQQbPcCuA=w629-h839-s-no?authuser=0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=https://photos.google.com/
HostUrl=https://photos.fife.usercontent.google.com/pw/AP1GczM2ekpx6LZXizZWJMpK-hmlVSloet7gAPBww-Umlxy0LoZTn6Q0dlf4rA=w1118-h839-s-no?authuser=0
22 changes: 14 additions & 8 deletions src/science_jubilee/Machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# import websocket # for reading the machine model

import json
import logging
import os
import time
import warnings
from functools import wraps
from pathlib import Path
from typing import Union
import logging

import requests # for issuing commands
from requests.adapters import HTTPAdapter, Retry
Expand Down Expand Up @@ -479,13 +479,17 @@ def gcode(self, cmd: str = "", timeout=None, response_wait: float = 60):
reply_response = self.session.get(
f"http://{self.address}/rr_model?key=seqs"
)
logging.debug(f'MODEL response, status: {reply_response.status_code}, headers:{reply_response.headers}, content:{reply_response.content}')
logging.debug(
f"MODEL response, status: {reply_response.status_code}, headers:{reply_response.headers}, content:{reply_response.content}"
)

reply_count = reply_response.json()["result"]["reply"]
buffer_response = self.session.get(
f"http://{self.address}/rr_gcode?gcode={cmd}", timeout=timeout
)
logging.debug(f'GCODE response, status: {buffer_response.status_code}, headers:{buffer_response.headers}, content:{buffer_response.content}')
logging.debug(
f"GCODE response, status: {buffer_response.status_code}, headers:{buffer_response.headers}, content:{buffer_response.content}"
)
# wait for a response code to be appended
# TODO: Implement retry backoff for managing long-running operations to avoid too many requests error. Right now this is handled by the generic exception catch then sleep. Real fix is some sort of backoff for things running longer than a few seconds.
tic = time.time()
Expand All @@ -496,15 +500,19 @@ def gcode(self, cmd: str = "", timeout=None, response_wait: float = 60):
f"http://{self.address}/rr_model?key=seqs"
)

logging.debug(f'MODEL response, status: {new_reply_response.status_code}, headers:{new_reply_response.headers}, content:{new_reply_response.content}')
logging.debug(
f"MODEL response, status: {new_reply_response.status_code}, headers:{new_reply_response.headers}, content:{new_reply_response.content}"
)
new_reply_count = new_reply_response.json()["result"]["reply"]

if new_reply_count != reply_count:
response = self.session.get(
f"http://{self.address}/rr_reply"
)

logging.debug(f'REPLY response, status: {response.status_code}, headers:{response.headers}, content:{response.content}')
logging.debug(
f"REPLY response, status: {response.status_code}, headers:{response.headers}, content:{response.content}"
)

response = response.text
break
Expand All @@ -515,7 +523,7 @@ def gcode(self, cmd: str = "", timeout=None, response_wait: float = 60):
try_count += 1
except Exception as e:
print(f"Connection error ({e}), sleeping 1 second")
logging.debug(f'Error in gcode reply wait loop: {e}')
logging.debug(f"Error in gcode reply wait loop: {e}")
time.sleep(2)
continue

Expand All @@ -525,7 +533,6 @@ def gcode(self, cmd: str = "", timeout=None, response_wait: float = 60):
# TODO: handle this with logging. Also fix so all output goes to logs
return response


def delay_time(self, n):
"""
Calculate delay time for next request. dumb hard code for now, could be fancy exponential backoff
Expand All @@ -541,7 +548,6 @@ def delay_time(self, n):
else:
return 1


def _set_absolute_positioning(self):
"""Set absolute positioning for all axes except extrusion"""
self.gcode("G90")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
"plate": "Aluminum",
"mask": "Delrin"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
"plate": "Aluminum",
"mask": "Delrin"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
"plate": "Aluminum",
"mask": "Delrin"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -544,4 +544,4 @@
"y": 0,
"z": 0
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -589,4 +589,4 @@
"y": 0,
"z": 0
}
}
}
6 changes: 4 additions & 2 deletions src/science_jubilee/tools/HTTPSyringe.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def mix(
location: Union[Well, Tuple, Location],
t_hold: int = 1,
s_aspirate: int = 100,
s_dispense: int = 100
s_dispense: int = 100,
):
"""
Mixes n times with volume vol
Expand All @@ -226,7 +226,9 @@ def mix(

self._machine.safe_z_movement()
self._machine.move_to(x=x, y=y, wait=True)
self._aspirate(500, s_aspirate) #pre-aspirate 500 uL then blow this out at the end to avoid holding onto extra solution
self._aspirate(
500, s_aspirate
) # pre-aspirate 500 uL then blow this out at the end to avoid holding onto extra solution
self._machine.move_to(z=z, wait=True)

for _ in range(n_mix):
Expand Down
2 changes: 1 addition & 1 deletion src/science_jubilee/tools/configs/10cc_syringe.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"url": "http://192.168.1.5:5000",
"name": "10cc_1"
}
}
2 changes: 1 addition & 1 deletion src/science_jubilee/tools/configs/1cc_1_syringe.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"url": "http://192.168.1.5:5000",
"name": "1cc_1"
}
}

0 comments on commit 7b75d41

Please sign in to comment.