Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring/stepper.py #36

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
e1c02a7
Made modifications to main.py in the adafruithat and planktoscopehat
Oumayma-hy Apr 29, 2024
ffd5b13
On this branch, the main.py will remain unchanged
Oumayma-hy Apr 29, 2024
252f8c2
this is not a final version of the pump.py and focus.py
Oumayma-hy May 2, 2024
a01c4ce
deleting the older version of stepper
Oumayma-hy May 2, 2024
354de6c
Merge remote-tracking branch 'upstream/main' into refactoring/stepper.py
Oumayma-hy May 16, 2024
878eea0
Merge branch 'main' into refactoring/stepper.py
Oumayma-hy May 17, 2024
35c323b
modified comment
Oumayma-hy May 21, 2024
02bf69f
changed the focus and pump process
Oumayma-hy May 23, 2024
3b1c9c6
some changes in the main.py
Oumayma-hy May 27, 2024
16cf0cd
small changes
Oumayma-hy May 27, 2024
0286d2c
type error resolved
Oumayma-hy May 27, 2024
0a894ef
Merge remote-tracking branch 'upstream/main' into refactoring/stepper.py
Oumayma-hy May 27, 2024
f0c11e1
Merge branch 'refactoring/stepper.py' of https://github.com/Oumayma-h…
Oumayma-hy May 27, 2024
cd6bfb9
Suppress type-checking for external packages
ethanjli May 29, 2024
c528c56
Resolve remaining type-checker and formatter complaints
ethanjli May 29, 2024
a266248
Resolve another linter error
ethanjli May 29, 2024
2b5d9d2
fixed errors
Oumayma-hy May 30, 2024
80e90ba
fixed errors
Oumayma-hy May 30, 2024
00bfaa5
resolving some errors
Oumayma-hy Jun 3, 2024
75c2811
change of one line
Oumayma-hy Jun 6, 2024
99b623a
change of one line
Oumayma-hy Jun 6, 2024
3231f26
changes made to pump.py
Oumayma-hy Jun 10, 2024
2e28146
changes made to pump.py
Oumayma-hy Jun 10, 2024
2940a21
changes made to pump.py
Oumayma-hy Jun 10, 2024
ed2d0e8
changes made to pump.py
Oumayma-hy Jun 10, 2024
8b248b9
changes made to pump.py
Oumayma-hy Jun 10, 2024
0adabc4
changes made to pump.py
Oumayma-hy Jun 10, 2024
2be5aeb
changes made to pump.py
Oumayma-hy Jun 10, 2024
117177e
changes made to pump.py
Oumayma-hy Jun 10, 2024
fdae3c2
changes made to pump.py
Oumayma-hy Jun 10, 2024
8a2abe0
changes made to focus.py
Oumayma-hy Jun 10, 2024
193dd8b
changes made to focus.py
Oumayma-hy Jun 10, 2024
3dbb994
changes made to pump.py
Oumayma-hy Jun 10, 2024
cab87d2
exception handling to resolve the none value error
Oumayma-hy Jun 12, 2024
76fff2d
exception handling to resolve the none value error
Oumayma-hy Jun 12, 2024
dd69f7d
exception handling to resolve the none value error
Oumayma-hy Jun 12, 2024
d86c74f
correcting the structure of the elif
Oumayma-hy Jun 12, 2024
f1605ca
correcting the structure of the elif
Oumayma-hy Jun 12, 2024
29c4d8d
removing blank lines
Oumayma-hy Jun 12, 2024
5ca5a4d
Merge branch 'main' into refactoring/stepper.py
Oumayma-hy Jun 12, 2024
6af6f21
Merge branch 'main' into refactoring/stepper.py
ethanjli Aug 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions control/planktoscopehat/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

from loguru import logger

import planktoscope.focus
import planktoscope.mqtt
import planktoscope.stepper

import planktoscope.light # Fan HAT LEDs
import planktoscope.identity
import planktoscope.pump
import planktoscope.uuidName # Note: this is deprecated.
import planktoscope.display # Fan HAT OLED screen
from planktoscope.imagernew import mqtt as imagernew
Expand Down Expand Up @@ -87,10 +89,15 @@ def handler_stop_signals(signum, frame):
shutdown_event = multiprocessing.Event()
shutdown_event.clear()

# Starts the stepper process for actuators
logger.info("Starting the stepper control process (step 2/5)")
stepper_thread = planktoscope.stepper.StepperProcess(shutdown_event)
stepper_thread.start()
# Starts the focus process for actuators
logger.info("Starting the focus control process (step 2/5)")
focus_thread = planktoscope.focus.FocusProcess(shutdown_event)
focus_thread.start()

# Starts the pump process for actuators
logger.info("Starting the focus control process (step 2/5)")
pump_thread = planktoscope.pump.PumpProcess(shutdown_event)
pump_thread.start()

# TODO try to isolate the imager thread (or another thread)
# Starts the imager control process
Expand Down Expand Up @@ -118,29 +125,43 @@ def handler_stop_signals(signum, frame):

logger.success("Looks like everything is set up and running, have fun!")

# With the creation of this dictionary to keep track of running threads, we can easily
running_threads = {
"pump": pump_thread,
"focus": focus_thread,
"light": light_thread,
"imager": imager_thread
}

while run:
# TODO look into ways of restarting the dead threads
logger.trace("Running around in circles while waiting for someone to die!")
if not stepper_thread.is_alive():
logger.error("The stepper process died unexpectedly! Oh no!")
break
if not imager_thread or not imager_thread.is_alive():
logger.error("The imager process died unexpectedly! Oh no!")
# Check if any threads have terminated unexpectedly and log the error without exiting
for thread_name, thread in running_threads.items():
if not thread or not thread.is_alive():
logger.error(f"The {thread_name} process terminated unexpectedly!")
del running_threads[thread_name] # Remove the dead thread from the dictionary
# Check if all threads have terminated so we can exit the program
if not running_threads: #checks if there is no running thread left
logger.error("All processes terminated unexpectedly! Exiting...")
break
time.sleep(1)


display.display_text("Bye Bye!")
logger.info("Shutting down the shop")
shutdown_event.set()
time.sleep(1)

stepper_thread.join()
focus_thread.join()
pump_thread.join()
if imager_thread:
imager_thread.join()
if light_thread:
light_thread.join()

stepper_thread.close()
focus_thread.close()
pump_thread.close()
if imager_thread:
imager_thread.close()
if light_thread:
Expand Down
Loading