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

Commit

Permalink
Merge pull request #104 from LimaoC/mitch-face-tolerance
Browse files Browse the repository at this point in the history
Mitch face tolerance
  • Loading branch information
MitchellJC authored Oct 18, 2024
2 parents dcfd9e0 + f706995 commit dd6b852
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
15 changes: 3 additions & 12 deletions client/drivers/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class HardwareComponents:
_PLANT_GEAR_RATIO: float = 2
_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_UPWARDS = _BASE_FULL_SPEED * (4 / 7) * (17 / 20) * 2
_FULL_SPEED_DOWNWARDS = (-1) * _BASE_FULL_SPEED * (6 / 10) * 2

# SECTION: Constructors
Expand Down Expand Up @@ -325,10 +325,10 @@ def initialise_posture_graph(self, user_id: int) -> None:

def unwind_plant(self) -> None:
"""
Unwind the plant to its maximum height, by making 16 full turns (we have 13 turns total).
Unwind the plant to its maximum height, by making 15 full turns (we have 13 turns total).
"""
self.plant_mover.speed = self._FULL_SPEED_UPWARDS
time.sleep(16 * self._PLANT_MOVER_PERIOD * self._PLANT_GEAR_RATIO / 1000)
time.sleep(15 * self._PLANT_MOVER_PERIOD * self._PLANT_GEAR_RATIO / 1000)
self.plant_height = (
self._PLANT_SHAFT_TURNS - self._PLANT_SHAFT_SAFETY_BUFFER_TURNS
)
Expand All @@ -340,15 +340,6 @@ def wind_plant_safe(self) -> None:
Will also reset the `plant_height` to `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 Down
9 changes: 5 additions & 4 deletions client/drivers/pi_overlord.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@
NUM_DATA_POINTS_PER_TIMEOUT = 3

#: Minimum delay between consecutive uses of the vibration motor. Used in handle_feedback().
HANDLE_CUSHION_FEEDBACK_TIMEOUT = timedelta(milliseconds=30000)
HANDLE_CUSHION_FEEDBACK_TIMEOUT = timedelta(milliseconds=15000)
#: Length of time for which the vibration motor should vibrate. Used in handle_cushion_feedback().
CUSHION_ACTIVE_INTERVAL = timedelta(milliseconds=3000)
CUSHION_ACTIVE_INTERVAL = timedelta(milliseconds=2000)
#: Threshold for vibration cushion feedback. If the proportion of "good" sitting posture is below this, the cushion will vibrate.
CUSHION_PROPORTION_GOOD_THRESHOLD = 0.5

#: Minimum delay between consecutive uses of the plant-controlling servos. Used in handle_feedback().
HANDLE_PLANT_FEEDBACK_TIMEOUT = timedelta(milliseconds=15000)
HANDLE_PLANT_FEEDBACK_TIMEOUT = timedelta(milliseconds=7500)
#: Threshold for I. Jensen Plant Mover 10000 feedback. If the proportion of "good" sitting posture is below this,
#: the plant will move down.
PLANT_PROPORTION_GOOD_THRESHOLD = 0.5
PLANT_PROPORTION_GOOD_THRESHOLD = 0.6

#: Number of milliseconds between each loop iteration in run_user_session().
USER_SESSION_INTERVAL = 100
Expand Down Expand Up @@ -191,6 +191,7 @@ def run_user_session(user: ControlledData) -> None:
hardware.display.show()
sleep_ms(LOGOUT_SUCCESS_DELAY)
logger.debug("<!> END run_user_session()")
hardware.unwind_plant()
return

# Run core functionality
Expand Down
13 changes: 10 additions & 3 deletions client/models/face_recognition/recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from data.routines import register_face_embeddings, iter_face_embeddings

MODEL_NAME = "small"
TOLERANCE = 0.3


class Status(Enum):
Expand Down Expand Up @@ -37,7 +38,9 @@ def get_face_match(login_face: np.ndarray) -> int:
login_embedding = login_embeddings[0]

for user_id, user_embeddings in iter_face_embeddings():
matches = face_recognition.compare_faces(user_embeddings, login_embedding)
matches = face_recognition.compare_faces(
user_embeddings, login_embedding, tolerance=TOLERANCE
)

if any(matches):
return user_id
Expand Down Expand Up @@ -69,14 +72,18 @@ def register_faces(user_id: int, faces: list[np.ndarray]) -> int:
face_embeddings.append(face_embedding)

# Ensure that all images contain the same face
matches = face_recognition.compare_faces(face_embeddings[1:], face_embeddings[0])
matches = face_recognition.compare_faces(
face_embeddings[1:], face_embeddings[0], tolerance=TOLERANCE
)
if not all(matches):
return Status.TOO_MANY_FACES.value

# Ensure user is not already registered
for _, other_user_embeddings in iter_face_embeddings():
for embedding in face_embeddings:
matches = face_recognition.compare_faces(other_user_embeddings, embedding)
matches = face_recognition.compare_faces(
other_user_embeddings, embedding, tolerance=TOLERANCE
)

if any(matches):
return Status.ALREADY_REGISTERED.value
Expand Down

0 comments on commit dd6b852

Please sign in to comment.