Skip to content

Commit

Permalink
feat(hardware-testing): Gravimetric "daily-setup" script for confirmi…
Browse files Browse the repository at this point in the history
…ng fixture stability and accuracy (#13876)
  • Loading branch information
andySigler committed Nov 1, 2023
1 parent 916e2a7 commit 5dc8819
Show file tree
Hide file tree
Showing 9 changed files with 465 additions and 11 deletions.
1 change: 1 addition & 0 deletions hardware-testing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ test-gravimetric-96:
.PHONY: test-gravimetric
test-gravimetric:
-$(MAKE) apply-patches-gravimetric
$(python) -m hardware_testing.gravimetric.daily_setup --simulate
$(MAKE) test-gravimetric-single
$(MAKE) test-gravimetric-multi
$(MAKE) test-gravimetric-96
Expand Down
46 changes: 45 additions & 1 deletion hardware-testing/hardware_testing/drivers/radwag/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
)
from .responses import RadwagResponse, RadwagResponseCodes, radwag_response_parse

from hardware_testing.data import get_testing_data_directory


class RadwagScaleBase(ABC):
"""Base class if Radwag scale driver."""
Expand All @@ -40,6 +42,11 @@ def read_serial_number(self) -> str:
"""Read the serial number."""
...

@abstractmethod
def read_max_capacity(self) -> float:
"""Read the max capacity."""
...

@abstractmethod
def continuous_transmission(self, enable: bool) -> None:
"""Enable/disable continuous transmission."""
Expand Down Expand Up @@ -87,7 +94,8 @@ class RadwagScale(RadwagScaleBase):
def __init__(self, connection: Serial) -> None:
"""Constructor."""
self._connection = connection
self._raw_log = open("/data/testing_data/scale_raw.txt", "w")
_raw_file_path = get_testing_data_directory() / "scale_raw.txt"
self._raw_log = open(_raw_file_path, "w")

@classmethod
def create(
Expand Down Expand Up @@ -156,6 +164,22 @@ def disconnect(self) -> None:
self._connection.close()
self._raw_log.close()

def read_max_capacity(self) -> float:
"""Read the max capacity."""
cmd = RadwagCommand.GET_MAX_CAPACITY
res = self._write_command_and_read_response(cmd)
# NOTE: very annoying, different scales give different response codes
# where some will just not have a response code at all...
if len(res.response_list) == 3:
expected_code = RadwagResponseCodes.IN_PROGRESS
elif len(res.response_list) == 2:
expected_code = RadwagResponseCodes.NONE
else:
raise RuntimeError(f"unexpected reponse list: {res.response_list}")
assert res.code == expected_code, f"Unexpected response code: {res.code}"
assert res.message is not None
return float(res.message)

def read_serial_number(self) -> str:
"""Read serial number."""
cmd = RadwagCommand.GET_SERIAL_NUMBER
Expand Down Expand Up @@ -220,6 +244,18 @@ def automatic_internal_adjustment(self, enable: bool) -> None:
res.code == RadwagResponseCodes.CARRIED_OUT
), f"Unexpected response code: {res.code}"

def zero(self) -> None:
"""Sero the scale."""
cmd = RadwagCommand.ZERO
res = self._write_command_and_read_response(cmd)
assert (
res.code == RadwagResponseCodes.IN_PROGRESS
), f"Unexpected response code: {res.code}"
res = self._read_response(cmd, timeout=60)
assert (
res.code == RadwagResponseCodes.CARRIED_OUT_AFTER_IN_PROGRESS
), f"Unexpected response code: {res.code}"

def internal_adjustment(self) -> None:
"""Run internal adjustment."""
cmd = RadwagCommand.INTERNAL_ADJUST_PERFORMANCE
Expand Down Expand Up @@ -269,6 +305,10 @@ def disconnect(self) -> None:
"""Disconnect."""
return

def read_max_capacity(self) -> float:
"""Read the max capacity."""
return 220.0 # :shrug: might as well simulate as low-rez scale

def read_serial_number(self) -> str:
"""Read serial number."""
return "radwag-sim-serial-num"
Expand Down Expand Up @@ -297,6 +337,10 @@ def automatic_internal_adjustment(self, enable: bool) -> None:
"""Automatic internal adjustment."""
return

def zero(self) -> None:
"""Zero."""
return

def internal_adjustment(self) -> None:
"""Internal adjustment."""
return
Expand Down
12 changes: 12 additions & 0 deletions hardware-testing/hardware_testing/drivers/radwag/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,22 @@ def _on_serial_number(
return data


def _on_max_capacity(
command: RadwagCommand, response_list: List[str]
) -> RadwagResponse:
data = RadwagResponse.build(command, response_list)
if 2 <= len(response_list) <= 3:
data.message = response_list[-1].replace('"', "")
else:
raise RuntimeError(f"unexpected response list: {response_list}")
return data


HANDLERS = {
RadwagCommand.GET_MEASUREMENT_BASIC_UNIT: _on_unstable_measurement,
RadwagCommand.GET_MEASUREMENT_CURRENT_UNIT: _on_unstable_measurement,
RadwagCommand.GET_SERIAL_NUMBER: _on_serial_number,
RadwagCommand.GET_MAX_CAPACITY: _on_max_capacity,
}


Expand Down
Loading

0 comments on commit 5dc8819

Please sign in to comment.