I'm working on a project which controls the speed of a motor and the temperature of a heating element. I have to run the sample time of the motor on 10Hz. The duration of the function that I use to read my temperature sensor is 0.8sec. So i can't use the temperature reading in my main loop. Now I'm trying to use the concurrent.futures module to run the function of the temperature seperate from my main program once for every 10 cycles of my main program (duration main programm = 0.1s).
This is my code:
with concurrent.futures.ProcessPoolExecutor() as executor:
p1 = executor.submit(GetTemp)
while(time.time() < t_end):
#Get Speed of Motor and Temperature
RealRPMExtruder = round((tach.RPM()/2080),2)
if Counter >= 10:
RealTemp = p1.result()
p1 = executor.submit(GetTemp)
counter = 0
Counter += 1
#PID Controllers
controlExtruder = pidExtruder(RealRPMExtruder)
controlHeater = pidHeater(RealTemp)
#Setting Output Values
PWMExtruder.ChangeDutyCycle(controlExtruder)
PWMHeater.ChangeDutyCycle(controlHeater)
The first 10 cycles it runs just fine, but the second time i try to start the function my programms stops. I need to run this continuous and for a long time, so using queue's and list (multiprocessing) won't work (I think). What do I need to do to call the function mutilple times with some sort of multiprocessing.