I need to move a small motor carriage on the rail. There is an infrared detector on the rail to prevent entry too far. The whole system is controlled by Raspberry Pi 3.
I am trying to configure two processes using a multiprocessing package: the first is this move_process, which basically just calls a function that moves the engine for the selected number of steps.
def move():
motor.step(steps, direction, stepmode)
watch_process.terminate()
The second is one watch_processthat calls an infinite loop function, awaiting input from the IR detector:
def watch()
while True:
detector_input = GPIO.input(18)
if detector_input == False:
move_process.terminate()
break
I want to watch_processkill move_processif the detector sends input. I also want to move_processkill watch_processif everything went fine, i.e. When the engine successfully moved without starting the detector.
, , "":
def on_go_pressed():
move_process = multiprocessing.Process(target=move)
watch_process = multiprocessing.Process(target=watch)
move_process.start(), watch_process.start()
, ?
.
.
EDIT: typo