stepper: reduce method size
This commit is contained in:
parent
12712c241e
commit
98c51828e0
|
@ -254,18 +254,7 @@ class StepperProcess(multiprocessing.Process):
|
||||||
|
|
||||||
logger.info(f"Stepper initialisation is over")
|
logger.info(f"Stepper initialisation is over")
|
||||||
|
|
||||||
def treat_command(self):
|
def __message_pump(self, last_message):
|
||||||
command = ""
|
|
||||||
if self.actuator_client.new_message_received():
|
|
||||||
logger.info("We received a new message")
|
|
||||||
last_message = self.actuator_client.msg["payload"]
|
|
||||||
logger.debug(last_message)
|
|
||||||
command = self.actuator_client.msg["topic"].split("/", 1)[1]
|
|
||||||
logger.debug(command)
|
|
||||||
self.actuator_client.read_message()
|
|
||||||
|
|
||||||
# If the command is "pump"
|
|
||||||
if command == "pump":
|
|
||||||
logger.debug("We have received a pumping command")
|
logger.debug("We have received a pumping command")
|
||||||
if last_message["action"] == "stop":
|
if last_message["action"] == "stop":
|
||||||
logger.debug("We have received a stop pump command")
|
logger.debug("We have received a stop pump command")
|
||||||
|
@ -295,9 +284,7 @@ class StepperProcess(multiprocessing.Process):
|
||||||
logger.error(
|
logger.error(
|
||||||
f"The received message has the wrong argument {last_message}"
|
f"The received message has the wrong argument {last_message}"
|
||||||
)
|
)
|
||||||
self.actuator_client.client.publish(
|
self.actuator_client.client.publish("status/pump", '{"status":"Error"}')
|
||||||
"status/pump", '{"status":"Error"}'
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
# Get direction from the different received arguments
|
# Get direction from the different received arguments
|
||||||
direction = last_message["direction"]
|
direction = last_message["direction"]
|
||||||
|
@ -310,12 +297,9 @@ class StepperProcess(multiprocessing.Process):
|
||||||
logger.info("The pump is started.")
|
logger.info("The pump is started.")
|
||||||
self.pump(direction, volume, flowrate)
|
self.pump(direction, volume, flowrate)
|
||||||
else:
|
else:
|
||||||
logger.warning(
|
logger.warning(f"The received message was not understood {last_message}")
|
||||||
f"The received message was not understood {last_message}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# If the command is "focus"
|
def __message_focus(self, last_message):
|
||||||
elif command == "focus":
|
|
||||||
logger.debug("We have received a focusing request")
|
logger.debug("We have received a focusing request")
|
||||||
# If a new received command is "focus" but args contains "stop" we stop!
|
# If a new received command is "focus" but args contains "stop" we stop!
|
||||||
if last_message["action"] == "stop":
|
if last_message["action"] == "stop":
|
||||||
|
@ -338,10 +322,7 @@ class StepperProcess(multiprocessing.Process):
|
||||||
# Set the LEDs as Yellow
|
# Set the LEDs as Yellow
|
||||||
planktoscope.light.setRGB(255, 255, 0)
|
planktoscope.light.setRGB(255, 255, 0)
|
||||||
|
|
||||||
if (
|
if "direction" not in last_message or "distance" not in last_message:
|
||||||
"direction" not in last_message
|
|
||||||
or "distance" not in last_message
|
|
||||||
):
|
|
||||||
logger.error(
|
logger.error(
|
||||||
f"The received message has the wrong argument {last_message}"
|
f"The received message has the wrong argument {last_message}"
|
||||||
)
|
)
|
||||||
|
@ -357,9 +338,25 @@ class StepperProcess(multiprocessing.Process):
|
||||||
logger.info("The focus movement is started.")
|
logger.info("The focus movement is started.")
|
||||||
self.focus(direction, distance)
|
self.focus(direction, distance)
|
||||||
else:
|
else:
|
||||||
logger.warning(
|
logger.warning(f"The received message was not understood {last_message}")
|
||||||
f"The received message was not understood {last_message}"
|
|
||||||
)
|
def treat_command(self):
|
||||||
|
command = ""
|
||||||
|
if self.actuator_client.new_message_received():
|
||||||
|
logger.info("We received a new message")
|
||||||
|
last_message = self.actuator_client.msg["payload"]
|
||||||
|
logger.debug(last_message)
|
||||||
|
command = self.actuator_client.msg["topic"].split("/", 1)[1]
|
||||||
|
logger.debug(command)
|
||||||
|
self.actuator_client.read_message()
|
||||||
|
|
||||||
|
# If the command is "pump"
|
||||||
|
if command == "pump":
|
||||||
|
self.__message_pump(last_message)
|
||||||
|
|
||||||
|
# If the command is "focus"
|
||||||
|
elif command == "focus":
|
||||||
|
self.__message_focus(last_message)
|
||||||
elif command != "":
|
elif command != "":
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"We did not understand the received request {command} - {last_message}"
|
f"We did not understand the received request {command} - {last_message}"
|
||||||
|
@ -518,7 +515,6 @@ class StepperProcess(multiprocessing.Process):
|
||||||
"status/focus",
|
"status/focus",
|
||||||
'{"status":"Done"}',
|
'{"status":"Done"}',
|
||||||
)
|
)
|
||||||
time.sleep(0)
|
|
||||||
logger.info("Shutting down the stepper process")
|
logger.info("Shutting down the stepper process")
|
||||||
self.actuator_client.client.publish("status/pump", '{"status":"Dead"}')
|
self.actuator_client.client.publish("status/pump", '{"status":"Dead"}')
|
||||||
self.actuator_client.client.publish("status/focus", '{"status":"Dead"}')
|
self.actuator_client.client.publish("status/focus", '{"status":"Dead"}')
|
||||||
|
|
Loading…
Reference in a new issue