-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script for scale data collection abr
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
51
hardware-testing/hardware_testing/scripts/scale_data_collection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
|
||
|
||
|