-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- Thanks for taking the time to open a pull request! Please make sure you've read the "Opening Pull Requests" section of our Contributing Guide: https://github.com/Opentrons/opentrons/blob/edge/CONTRIBUTING.md#opening-pull-requests To ensure your code is reviewed quickly and thoroughly, please fill out the sections below to the best of your ability! --> # Overview This PR adds a script to the hardware-testing folder that will allow the robot to connect to an asair temperature and humidity sensor and record continuously to a google spread sheet. # Test Plan I tested this script on robot DVT10 on software v7.1.1. It successfully measured the temperature and humidity and uploaded to the google sheet. # Changelog Added abr-asair-sensor script Script: 1. Asks user for robot name 2. Asks user for duration of recording (min) 3. Asks user for frequency of recording (min) 4. Robot reads ports and connects to asair sensor 5. robot collects data and appends to a list at the given frequency 6. At the end of the duration the robot saves a .csv file of the data to the testing-data folder within the robot and to the google sheet I also updated the analyze-abr script to improve ease of analysis. IMPORTANT: MAKE SURE ANY BREAKING CHANGES ARE PROPERLY COMMUNICATED --> # Review requests <!-- Describe any requests for your reviewers here. --> # Risk assessment - for the script to run successfully on the robot, google_sheets_tool.py and a google sheets credentials file needs to be uploaded manually onto the robot's jupyter notebook. - for google_sheets_tool.py to run successfully within the script python libraries: httplib2, oauth2client, gspread, and pprintpp need to be installed onto the robots
- Loading branch information
Showing
3 changed files
with
135 additions
and
7 deletions.
There are no files selected for viewing
129 changes: 126 additions & 3 deletions
129
hardware-testing/hardware_testing/scripts/abr_asair_sensor.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 |
---|---|---|
@@ -1,6 +1,129 @@ | ||
"""ABR Temperature Humidity Sensors.""" | ||
# from hardware_testing import data | ||
# from hardware_testing.drivers import asair_sensor | ||
|
||
from hardware_testing import data | ||
from hardware_testing.drivers import asair_sensor | ||
import datetime | ||
import sys | ||
import time as t | ||
from typing import List | ||
import os | ||
|
||
# if __name__ == "__main__": | ||
|
||
def _get_user_input(lst: List[str], some_string: str) -> str: | ||
variable = input(some_string) | ||
while variable not in lst: | ||
print( | ||
f"Your input was {variable}. Expected input is one of the following: {lst}" | ||
) | ||
variable = input(some_string) | ||
return variable | ||
|
||
|
||
class _ABRAsairSensor: | ||
def __init__(self, robot: str, duration: int, frequency: int) -> None: | ||
try: | ||
sys.path.insert(0, "/var/lib/jupyter/notebooks") | ||
import google_sheets_tool # type: ignore[import] | ||
|
||
credentials_path = "/var/lib/jupyter/notebooks/abr.json" | ||
except ImportError: | ||
raise ImportError( | ||
"Run on robot. Make sure google_sheets_tool.py is in jupyter notebook." | ||
) | ||
print(os.path.exists(credentials_path)) | ||
test_name = "ABR-Environment-Monitoring" | ||
run_id = data.create_run_id() | ||
file_name = data.create_file_name(test_name, run_id, robot) | ||
sensor = asair_sensor.BuildAsairSensor(False, True) | ||
print(sensor) | ||
env_data = sensor.get_reading() | ||
header = [ | ||
"Robot", | ||
"Timestamp", | ||
"Date", | ||
"Time", | ||
"Temp (oC)", | ||
"Relative Humidity (%)", | ||
] | ||
header_str = ",".join(header) + "\n" | ||
data.append_data_to_file(test_name, run_id, file_name, header_str) | ||
# Upload to google has passed | ||
try: | ||
google_sheet = google_sheets_tool.google_sheet( | ||
credentials_path, "ABR Ambient Conditions", tab_number=0 | ||
) | ||
print("Connected to the google sheet.") | ||
except FileNotFoundError: | ||
print( | ||
"There is no google sheets credentials. Make sure credentials in jupyter notebook." | ||
) | ||
results_list = [] # type: List | ||
start_time = datetime.datetime.now() | ||
while True: | ||
env_data = sensor.get_reading() | ||
timestamp = datetime.datetime.now() | ||
# Time adjustment for ABR robot timezone | ||
new_timestamp = timestamp - datetime.timedelta(hours=5) | ||
date = new_timestamp.date() | ||
time = new_timestamp.time() | ||
temp = env_data.temperature | ||
print(temp) | ||
rh = env_data.relative_humidity | ||
print(rh) | ||
row = [ | ||
robot, | ||
str(new_timestamp), | ||
str(date), | ||
str(time), | ||
temp, | ||
rh, | ||
] | ||
results_list.append(row) | ||
# Check if duration elapsed | ||
elapsed_time = datetime.datetime.now() - start_time | ||
if elapsed_time.total_seconds() >= duration * 60: | ||
break | ||
# write to google sheet | ||
try: | ||
google_sheet.write_header(header) | ||
google_sheet.update_row_index() | ||
google_sheet.write_to_row(row) | ||
print("Wrote row") | ||
except RuntimeError: | ||
print("Did not write row.") | ||
# Delay for desired frequency minutes before the next iteration | ||
t.sleep(frequency * 60) # seconds | ||
|
||
# Upload to robot testing data folder | ||
for sublist in results_list: | ||
row_str = ", ".join(map(str, sublist)) + "\n" # type: str | ||
save_file_path = data.append_data_to_file( | ||
test_name, run_id, file_name, row_str | ||
) | ||
print(f"Saved to robot: f{save_file_path}.") | ||
print( | ||
f"Done. Ran for {duration} minutes and collected every {frequency} minutes." | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
robot_list = [ | ||
"DVT1ABR1", | ||
"DVT1ABR2", | ||
"DVT1ABR3", | ||
"DVT1ABR4", | ||
"DVT2ABR5", | ||
"DVT2ABR6", | ||
"PVT1ABR7", | ||
"PVT1ABR8", | ||
"PVT1ABR9", | ||
"PVT1ABR10", | ||
"PVT1ABR11", | ||
"PVT1ABR12", | ||
"ROOM_339", | ||
"Room_340", | ||
] # type: List | ||
robot = _get_user_input(robot_list, "Robot/Room: ") | ||
duration = int(input("Duration (min): ")) | ||
frequency = int(input("Frequency (min): ")) | ||
_ABRAsairSensor(robot, duration, frequency) |
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
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