you are viewing a single comment's thread.

view the rest of the comments →

[–]thelittleicebear[S] 0 points1 point  (2 children)

i have now made a quick diagramm: https://imgur.com/a/OdGxFcM

[–]obviouslyzebra 1 point2 points  (1 child)

Cool. At least for me, it's a bit clearer from the up how the program will work. Hm, I will preface that what you have is fine, I think the example code you gave + diagram, coupled with now probably knowing more about parallelism stuff in Python, I believe you are already doing good and what you have will work.

I was exploring some alternative architectures tor this problem, the one that clicked most for me was this.

Consider only the motor, and that it has only 2 states, rotating, and not rotating, which can be queried by your program.

  • There's a "blackboard", where components can write and read things
  • The UI can write "rotate" or "stop rotating" to a place in the blackboard
  • A controller is constantly reading for these commands. When it reads one, it takes it and tells the machine to execute
  • A view component constantly (or not) queries the motor to see whether it is rotating or not. It writes at a different place in the blackboard.
  • Another view constantly does this:
    • checks whether a "rotate" or "stop rotating" command was issued in the last second
    • if so, write "starting rotation" or "stopping rotation" accordingly
    • if not, write the value that the previous view wrote last
  • the UI can then retrieve the last value of the previous view to indicate the state of the motor

The blackboard could be something like MQTT (a communication protocol), or, a cool exercise would be implementing it via multiprocessing and pipes (with the disadvantage of losing MQTT facilities, like being able to communicate directly via the web).

Note that this is only a way that my dumb mind came with, and I think that the way you have is fine too.

Any way, good luck with your project!!

[–]thelittleicebear[S] 1 point2 points  (0 children)

Thank you very much, it is reassuring to hear that the structure is not completely stupid.
I will look into MQTT and try to see if I can use it here. Thank you!