Fix bugs all around

This commit is contained in:
Romain Bazile 2020-11-25 16:58:32 +01:00
parent 9466cdb3fa
commit 1cf3d1df12
7 changed files with 1076 additions and 776 deletions

View file

@ -68,13 +68,13 @@ This topic controls the camera and capture. The message allowed is a JSON messag
```json ```json
{ {
"action": "image", "action": "image",
"sleep": 5, "pump_direction": "FORWARD",
"volume": 1, "volume": 1,
"nb_frame": 200 "nb_frame": 200
} }
``` ```
Sleep in seconds and volume in mL. Volume is in mL.
This topic can also receive a config update message: This topic can also receive a config update message:
```json ```json

File diff suppressed because it is too large Load diff

View file

@ -5,6 +5,6 @@
"pump_steps_per_ml": 507, "pump_steps_per_ml": 507,
"focus_max_speed": 0.5, "focus_max_speed": 0.5,
"pump_max_speed": 30, "pump_max_speed": 30,
"stepper_type": "adafruit", "stepper_type": "waveshare",
"camera_type": "HQ" "camera_type": "HQ"
} }

7
scripts/bash/update.sh Executable file
View file

@ -0,0 +1,7 @@
#!/bin/bash
cd /home/pi/PlanktonScope
git stash
git pull
git checkout stash@{0} -- config.json hardware.json

View file

@ -160,6 +160,7 @@ class ImagerProcess(multiprocessing.Process):
self.__img_done = 0 self.__img_done = 0
self.__sleep_before = None self.__sleep_before = None
self.__pump_volume = None self.__pump_volume = None
self.__pump_direction = "FORWARD"
self.__img_goal = None self.__img_goal = None
self.imager_client = None self.imager_client = None
@ -303,7 +304,12 @@ class ImagerProcess(multiprocessing.Process):
# Get duration to wait before an image from the different received arguments # Get duration to wait before an image from the different received arguments
self.__sleep_before = float(last_message["sleep"]) self.__sleep_before = float(last_message["sleep"])
# Get volume in between two images from the different received arguments # Get volume in between two images from the different received arguments
self.__pump_volume = float(last_message["volume"]) # Minimal volume is 0.1mL
self.__pump_volume = max(float(last_message["volume"]), 0.1)
# Get the pump direction message
self.__pump_direction = last_message["pump_direction"]
# Get the number of frames to image from the different received arguments # Get the number of frames to image from the different received arguments
self.__img_goal = int(last_message["nb_frame"]) self.__img_goal = int(last_message["nb_frame"])
@ -471,6 +477,21 @@ class ImagerProcess(multiprocessing.Process):
f"We did not understand the received request {action} - {last_message}" f"We did not understand the received request {action} - {last_message}"
) )
def __pump_message(self):
"""Sends a message to the pump process"""
# Pump during a given volume
self.imager_client.client.publish(
"actuator/pump",
json.dumps(
{
"action": "move",
"direction": self.__pump_direction,
"volume": self.__pump_volume,
"flowrate": 2,
}
),
)
def __state_imaging(self): def __state_imaging(self):
# TODO we should make sure here that we are not writing to an existing folder # TODO we should make sure here that we are not writing to an existing folder
# otherwise we might overwrite the metadata.json file # otherwise we might overwrite the metadata.json file
@ -516,17 +537,9 @@ class ImagerProcess(multiprocessing.Process):
# Set the LEDs as Blue # Set the LEDs as Blue
planktoscope.light.setRGB(0, 0, 255) planktoscope.light.setRGB(0, 0, 255)
self.imager_client.client.publish(
"actuator/pump", self.__pump_message()
json.dumps(
{
"action": "move",
"direction": "FORWARD",
"volume": self.__pump_volume,
"flowrate": 2,
}
),
)
# FIXME We should probably update the global metadata here with the current datetime/position/etc... # FIXME We should probably update the global metadata here with the current datetime/position/etc...
# Set the LEDs as Green # Set the LEDs as Green
@ -610,18 +623,7 @@ class ImagerProcess(multiprocessing.Process):
"status/pump", self.pump_callback "status/pump", self.pump_callback
) )
# Pump during a given volume self.__pump_message()
self.imager_client.client.publish(
"actuator/pump",
json.dumps(
{
"action": "move",
"direction": "BACKWARD",
"volume": self.__pump_volume,
"flowrate": 2,
}
),
)
# Set the LEDs as Green # Set the LEDs as Green
planktoscope.light.setRGB(0, 255, 0) planktoscope.light.setRGB(0, 255, 0)

View file

@ -92,6 +92,7 @@ def light(state):
## Wait message: Green ## Wait message: Green
## Actuate message: White ## Actuate message: White
## Pumping message: Blue ## Pumping message: Blue
## Pumping 2 message: BLue + Green
# This is called if this script is launched directly # This is called if this script is launched directly
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -16,7 +16,7 @@ logger.info("planktoscope.stepper is loaded")
class StepperWaveshare: class StepperWaveshare:
"""A bipolar stepper motor.""" """A bipolar stepper motor using the Waveshare HAT."""
def __init__(self, dir_pin, step_pin, enable_pin): def __init__(self, dir_pin, step_pin, enable_pin):
self.dir_pin = dir_pin self.dir_pin = dir_pin
@ -178,6 +178,7 @@ class StepperProcess(multiprocessing.Process):
def __init__(self, event): def __init__(self, event):
super(StepperProcess, self).__init__() super(StepperProcess, self).__init__()
logger.info("Initialising the stepper process") logger.info("Initialising the stepper process")
RPi.GPIO.setup([12, 4], RPi.GPIO.OUT, initial=RPi.GPIO.HIGH)
self.stop_event = event self.stop_event = event