-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Abr asair sensor #14445
Abr asair sensor #14445
Changes from all commits
1f6b411
9c04a10
879aaf1
d728581
0e88345
3a9e9bc
ce1b8fa
23559be
ea23e72
6561b8f
8e55ce9
7b51761
e0de99a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here you are appending the line to all previous lines, and then you appending that string to the file, and doing this for each line, which means that the file you are writing will be huge and filled with repeated lines. This can be fixed by removing the Then also, you can append each line to the CSV at the same time that you write the data to the google sheet. Just move the |
||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this b/c of the timezone? either leaving a comment to describe what this is doing or somehow specifying the system's timezone would make it more clear