Skip to content

Commit

Permalink
add script for scale data collection abr
Browse files Browse the repository at this point in the history
  • Loading branch information
rclarke0 committed Nov 30, 2023
1 parent 7258da8 commit 9f7fb5c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions hardware-testing/hardware_testing/scripts/demofile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
2023-11-30 15:51:45.539761 --> b'SI\r\n'
2023-11-30 15:51:45.539761 <-- b'SI ? 35.70741 g \r\n'
2023-11-30 15:52:07.733167 --> b'SI\r\n'
2023-11-30 15:52:07.738527 <-- b'SI 35.70707 g \r\n'
51 changes: 51 additions & 0 deletions hardware-testing/hardware_testing/scripts/scale_data_collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import sys, os, time, datetime
import pandas as pd
from serial.tools.list_ports import comports # type: ignore[import]
sys.path.insert(0, os.path.abspath('../'))
from drivers.radwag import RadwagScale

def find_port(vid: int, pid: int) -> str:
"""Find COM port from provided VIP:PID."""
# print(comports())
for port in comports():
print(port.pid)
print(port.vid)
if port.pid == pid and port.vid == vid:
return port.device
raise RuntimeError(f"Unable to find serial " f"port for VID:PID={vid}:{pid}")


if __name__ == '__main__':

# find port using known VID:PID, then connect
scale = RadwagScale.create(port=find_port(vid=1155, pid=41207))
scale.connect()
# read grams and stability marker
df = pd.DataFrame()
test = 'x'
try:
grams, is_stable = scale.read_mass()
time_now = datetime.datetime.now()
print(bool(is_stable))
robot = input('Robot: ')
labware = input('Labware: ')
while not(is_stable == 'True'):
grams, is_stable = scale.read_mass()
time_now = datetime.datetime.now()
print(f"Scale reading: grams={grams}, is_stable={is_stable}" )
df_reading = pd.DataFrame({'Date': time_now,'Labware': labware, 'Robot': robot, 'Scale Reading': grams, 'Stable': is_stable}, index = [0])
df = pd.concat([df, df_reading])
if bool(is_stable) == 1:
filename = robot + '_' + labware + '.csv'
df.to_csv('C:/Users/Rhyann Clarke/Documents/' + filename)
break

# disconnect from serial port
except Exception:
scale.disconnect()
except KeyboardInterrupt:
scale.disconnect()
print('success')



0 comments on commit 9f7fb5c

Please sign in to comment.