Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
Minor code refactoring (#99)
Browse files Browse the repository at this point in the history
* refactor: rename client/drivers/main.py -> client/drivers/pi_overlord.py

* refactor: rename auspost -> user, do_everything() -> run_user_session()

* Comments and constants

Put in some basic comments, cleaned up some debug.
Removed unused constants.
Adjusted constant values, to be tested tmrw

* constants

graph 10 sec
plant 15 sec
mousepad 30 sec

* Finalised code functionality

Fixed downwards speed.
Fixed presettting winding up and winding down code.
Changed display to better message.

* Vibrate longer

mousepad vibrates for 3 seconds

* refactor: remove proof_of_concept module

* refactor: change prints to logger debug message

---------

Co-authored-by: polypies73 <[email protected]>
  • Loading branch information
LimaoC and polypies73 authored Oct 17, 2024
1 parent ccfffeb commit f5c1e33
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 871 deletions.
4 changes: 2 additions & 2 deletions client/drivers/camera_overlord.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ def handle_quit(signo, frame):
f = open("/tmp/snapshot.jpg", "x")
f.close()
except FileExistsError:
print("Snapshot already exists")
logger.debug("Snapshot already exists")

try:
f = open("/tmp/big_brother.jpg", "x")
f.close()
except FileExistsError:
print("Big Brother already exists")
logger.debug("Big Brother already exists")

while True:
for _ in range(2 * 3):
Expand Down
49 changes: 28 additions & 21 deletions client/drivers/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Gabriel Field (47484306), Mitchell Clark
"""

import logging
import time
from datetime import datetime
from math import pi, sin
Expand All @@ -22,10 +23,12 @@
RIGHT_BUTTON = 1
DOUBLE_RIGHT_BUTTON = 2

logger = logging.getLogger(__name__)


class ControlledData:
"""
Data for passing around in client/drivers/main.do_everything().
Data for passing around in client/drivers/main.run_user_session().
There should only ever be one object of this class at a time.
Expand Down Expand Up @@ -80,7 +83,9 @@ def make_empty(cls, user_id: int) -> "ControlledData":
return_me._last_snapshot_time = datetime.now()
return_me._last_cushion_time = datetime.now()
return_me._last_plant_time = datetime.now()
print("<!> Made a new empty ControlledData() with user_id", return_me._user_id)
logger.debug(
"<!> Made a new empty ControlledData() with user_id %d", return_me._user_id
)
return return_me

@classmethod
Expand Down Expand Up @@ -156,21 +161,19 @@ def set_last_plant_time(self, time: datetime) -> None:
"""
self._last_plant_time = time

def accept_new_posture_data(
self, posture_data: List[float]
) -> None: # TODO: Refine type signature
def accept_new_posture_data(self, posture_data: List[float]) -> None:
"""
Update the internal store of posture data for the OLED display.
Args:
posture_data: new posture data to accept and merge with the current state of this object.
TODO: Implement me!
"""
print("<!> accept_new_posture_data()")
logger.debug("<!> accept_new_posture_data()")
for datum in posture_data:
self._posture_data.put_nowait(datum)


class HardwareComponents:
"""
Hardware components packaged together into a class.
Expand Down Expand Up @@ -231,7 +234,7 @@ class HardwareComponents:
_PLANT_MOVER_PERIOD: float = 1000 * 60 / 55
_BASE_FULL_SPEED = 0.1
_FULL_SPEED_UPWARDS = _BASE_FULL_SPEED * (4 / 7) * (8 / 9) * 2
_FULL_SPEED_DOWNWARDS = (-1) * _BASE_FULL_SPEED * (4 / 5) * 2
_FULL_SPEED_DOWNWARDS = (-1) * _BASE_FULL_SPEED * (6 / 10) * 2

# SECTION: Constructors

Expand Down Expand Up @@ -277,7 +280,7 @@ def get_control_messages(self, user_id: int) -> List[str]:
Returns:
The messages to display to the user during the main application loop.
"""
return ["b0: logout", "id: " + str(user_id)]
return ["Left: logout", "ID: " + str(user_id)]

def initialise_posture_graph(self, user_id: int) -> None:
"""
Expand Down Expand Up @@ -326,22 +329,26 @@ def unwind_plant(self) -> None:
"""
self.plant_mover.speed = self._FULL_SPEED_UPWARDS
time.sleep(16 * self._PLANT_MOVER_PERIOD * self._PLANT_GEAR_RATIO / 1000)
self.plant_height = (
self._PLANT_SHAFT_TURNS - self._PLANT_SHAFT_SAFETY_BUFFER_TURNS
)
self.plant_mover.speed = 0

def wind_plant_safe(self) -> None:
"""
Wind the plant down to its minimum (safe) height.
Will also reset the `plant_height` to `0`.
"""
self.plant_mover.speed = self._FULL_SPEED_DOWNWARDS
time.sleep(
(self._PLANT_SHAFT_TURNS - self._PLANT_SHAFT_SAFETY_BUFFER_TURNS)
* self._PLANT_MOVER_PERIOD
* self._PLANT_GEAR_RATIO
/ 1000
)
self.plant_mover.speed = 0
self.plant_height = 0
self.set_plant_height(0)
# self.plant_mover.speed = self._FULL_SPEED_DOWNWARDS
# time.sleep(
# (self._PLANT_SHAFT_TURNS - self._PLANT_SHAFT_SAFETY_BUFFER_TURNS)
# * self._PLANT_MOVER_PERIOD
# * self._PLANT_GEAR_RATIO
# / 1000
# )
# self.plant_mover.speed = 0
# self.plant_height = 0

def set_plant_height(self, new_height: int) -> None:
"""
Expand All @@ -351,7 +358,7 @@ def set_plant_height(self, new_height: int) -> None:
new_height: height to which to drive the I. Jensen Plant Mover 10000
"""
self.plant_mover.speed = 0
print(f"<!> set_plant_height: {self.plant_height=}, {new_height=}")
logger.debug(f"<!> set_plant_height: {self.plant_height=}, {new_height=}")
distance = new_height - self.plant_height
distance = distance if distance > 0 else (-1) * distance
if new_height == self.plant_height:
Expand All @@ -361,13 +368,13 @@ def set_plant_height(self, new_height: int) -> None:
new_height
> self._PLANT_SHAFT_TURNS - self._PLANT_SHAFT_SAFETY_BUFFER_TURNS - 1
):
print(
logger.debug(
"<!> Plant mover not schmovin': can't get that high mate, that's just unsafe"
)
self.plant_mover.speed = 0
return
if new_height < 0:
print(
logger.debug(
"<!> Plant mover not schmovin': can't get that low mate, that's just dirty"
)
self.plant_mover.speed = 0
Expand Down
Loading

0 comments on commit f5c1e33

Please sign in to comment.