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

Commit dd6b852

Browse files
authored
Merge pull request #104 from LimaoC/mitch-face-tolerance
Mitch face tolerance
2 parents dcfd9e0 + f706995 commit dd6b852

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

Diff for: client/drivers/data_structures.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class HardwareComponents:
233233
_PLANT_GEAR_RATIO: float = 2
234234
_PLANT_MOVER_PERIOD: float = 1000 * 60 / 55
235235
_BASE_FULL_SPEED = 0.1
236-
_FULL_SPEED_UPWARDS = _BASE_FULL_SPEED * (4 / 7) * (8 / 9) * 2
236+
_FULL_SPEED_UPWARDS = _BASE_FULL_SPEED * (4 / 7) * (17 / 20) * 2
237237
_FULL_SPEED_DOWNWARDS = (-1) * _BASE_FULL_SPEED * (6 / 10) * 2
238238

239239
# SECTION: Constructors
@@ -325,10 +325,10 @@ def initialise_posture_graph(self, user_id: int) -> None:
325325

326326
def unwind_plant(self) -> None:
327327
"""
328-
Unwind the plant to its maximum height, by making 16 full turns (we have 13 turns total).
328+
Unwind the plant to its maximum height, by making 15 full turns (we have 13 turns total).
329329
"""
330330
self.plant_mover.speed = self._FULL_SPEED_UPWARDS
331-
time.sleep(16 * self._PLANT_MOVER_PERIOD * self._PLANT_GEAR_RATIO / 1000)
331+
time.sleep(15 * self._PLANT_MOVER_PERIOD * self._PLANT_GEAR_RATIO / 1000)
332332
self.plant_height = (
333333
self._PLANT_SHAFT_TURNS - self._PLANT_SHAFT_SAFETY_BUFFER_TURNS
334334
)
@@ -340,15 +340,6 @@ def wind_plant_safe(self) -> None:
340340
Will also reset the `plant_height` to `0`.
341341
"""
342342
self.set_plant_height(0)
343-
# self.plant_mover.speed = self._FULL_SPEED_DOWNWARDS
344-
# time.sleep(
345-
# (self._PLANT_SHAFT_TURNS - self._PLANT_SHAFT_SAFETY_BUFFER_TURNS)
346-
# * self._PLANT_MOVER_PERIOD
347-
# * self._PLANT_GEAR_RATIO
348-
# / 1000
349-
# )
350-
# self.plant_mover.speed = 0
351-
# self.plant_height = 0
352343

353344
def set_plant_height(self, new_height: int) -> None:
354345
"""

Diff for: client/drivers/pi_overlord.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@
4444
NUM_DATA_POINTS_PER_TIMEOUT = 3
4545

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

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

5959
#: Number of milliseconds between each loop iteration in run_user_session().
6060
USER_SESSION_INTERVAL = 100
@@ -191,6 +191,7 @@ def run_user_session(user: ControlledData) -> None:
191191
hardware.display.show()
192192
sleep_ms(LOGOUT_SUCCESS_DELAY)
193193
logger.debug("<!> END run_user_session()")
194+
hardware.unwind_plant()
194195
return
195196

196197
# Run core functionality

Diff for: client/models/face_recognition/recognition.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from data.routines import register_face_embeddings, iter_face_embeddings
77

88
MODEL_NAME = "small"
9+
TOLERANCE = 0.3
910

1011

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

3940
for user_id, user_embeddings in iter_face_embeddings():
40-
matches = face_recognition.compare_faces(user_embeddings, login_embedding)
41+
matches = face_recognition.compare_faces(
42+
user_embeddings, login_embedding, tolerance=TOLERANCE
43+
)
4144

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

7174
# Ensure that all images contain the same face
72-
matches = face_recognition.compare_faces(face_embeddings[1:], face_embeddings[0])
75+
matches = face_recognition.compare_faces(
76+
face_embeddings[1:], face_embeddings[0], tolerance=TOLERANCE
77+
)
7378
if not all(matches):
7479
return Status.TOO_MANY_FACES.value
7580

7681
# Ensure user is not already registered
7782
for _, other_user_embeddings in iter_face_embeddings():
7883
for embedding in face_embeddings:
79-
matches = face_recognition.compare_faces(other_user_embeddings, embedding)
84+
matches = face_recognition.compare_faces(
85+
other_user_embeddings, embedding, tolerance=TOLERANCE
86+
)
8087

8188
if any(matches):
8289
return Status.ALREADY_REGISTERED.value

0 commit comments

Comments
 (0)