I have an Arduino and a Raspberry Pi on a differential robot. My plan is to SSH to the PI then being able to run a python script in terminal, thereafter being able to issue commands through the terminal program then the Pi sends it over to the Arduino. The Arduino then controls the robot by executing the commands eg: driving a certain path. I already have the majority of the code working. But I'm concerned that the code is very inefficient and i'm overcomplicating the program. My thought being "surely there is an easier way".
What could the simplest implementation be?
How could one implement modes into the program for example:
For the PI: "Waiting for arduino mode" then the program moves to "Waiting for user commands" then "Sending commands mode" then "Listening for completion flag from arduino".
For arduino: "Waiting for commands from pi mode" then "interpret commands mode" then "excution mode" then circling back.
My idea is at the moment is along the lines of: (arduino has similar structure)
def check_state(): global state match state: case 0: establish_arduino_connection() case 1: wait_for_user_commands() case 2: wait_for_execution() case _: print("Error: Program in unknown state.", now) sys.exit(1)
Then having a loop that constantly check the state: Li-ion Battery
while True: update_time() check_state()
It is a complex program, with which i've been struggling. Some advice would be much appreciated