Skip to content

Commit

Permalink
correct sensor naming in driver
Browse files Browse the repository at this point in the history
  • Loading branch information
falkecarlsen committed Aug 8, 2024
1 parent 049b144 commit ecddc40
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions py_driver/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ def get_state(self):
state = self.get_last_raw_state()
if state:
# Convert distance to water level
state["Tube1_water_mm"] = round(self.convert_distance_to_level(state["Tube1_water_mm"]), 1)
state["Tube2_water_mm"] = round(self.convert_distance_to_level(state["Tube2_water_mm"]), 1)
state["Tube1_sonar_dist_mm"] = round(self.convert_distance_to_level(state["Tube1_sonar_dist_mm"]), 1)
state["Tube2_sonar_dist_mm"] = round(self.convert_distance_to_level(state["Tube2_sonar_dist_mm"]), 1)
self.state = ClaireState()
self.state.set_state(state)
return state
Expand Down
2 changes: 1 addition & 1 deletion py_driver/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def example_experiment():
claire = driver.ClaireDevice(PORT)
state = claire.get_state() # get current state of device
claire.print_state(state)
print(f'Current height of TUBE1: {state["Tube1_water_mm"]}')
print(f'Current height of TUBE1: {state["Tube1_sonar_dist_mm"]}')

claire.set_inflow(1, 100)
sleep(3)
Expand Down
4 changes: 2 additions & 2 deletions py_driver/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Compact regex pattern to match Python dictionaries
dict_pattern = re.compile(
r'\{\s*"([a-zA-Z_][a-zA-Z0-9_]*)"\s*:\s*(-?\d+(\.\d+)?|"\w*")\s*(,\s*"([a-zA-Z_][a-zA-Z0-9_]*)"\s*:\s*(-?\d+(\.\d+)?|"\w*"))*\s*\}')
test_string = '{"Tube1_water_mm": -1.00, "Tube2_water_mm": -1.00, "Tube1_inflow_duty": 0,"Tube1_outflow_duty": 0,"Tube2_inflow_duty": 0,"Tube2_outflow_duty": 0,"Stream_inflow_duty": 0,"Stream_outflow_duty": 0}'
test_string = '{"Tube1_sonar_dist_mm": -1.00, "Tube2_sonar_dist_mm": -1.00, "Tube1_inflow_duty": 0,"Tube1_outflow_duty": 0,"Tube2_inflow_duty": 0,"Tube2_outflow_duty": 0,"Stream_inflow_duty": 0,"Stream_outflow_duty": 0}'


def is_dict(s: str) -> bool:
Expand All @@ -24,7 +24,7 @@ def is_dict(s: str) -> bool:
def parse_str_dict(s: str) -> dict:
"""
>>> parse_str_dict(test_string)
{'Tube1_water_mm': -1.0, 'Tube2_water_mm': -1.0, 'Tube1_inflow_duty': 0, 'Tube1_outflow_duty': 0, 'Tube2_inflow_duty': 0, 'Tube2_outflow_duty': 0, 'Stream_inflow_duty': 0, 'Stream_outflow_duty': 0}
{'Tube1_sonar_dist_mm': -1.0, 'Tube2_sonar_dist_mm': -1.0, 'Tube1_inflow_duty': 0, 'Tube1_outflow_duty': 0, 'Tube2_inflow_duty': 0, 'Tube2_outflow_duty': 0, 'Stream_inflow_duty': 0, 'Stream_outflow_duty': 0}
>>> parse_str_dict('{"a": 1, "b": 2}')
{'a': 1, 'b': 2}
Expand Down

0 comments on commit ecddc40

Please sign in to comment.