def producer(control_bus, delay_s): control = Controller() motor = motor_commands.MotorCommands() while 1: get_val = control_bus.read() angle = control.main_control(get_val, motor) time.sleep(delay_s)
def consumer_producer(control_bus, delay_s): control = Controller() motor = motor_commands.MotorCommands() while (1): get_val = control_bus.read() angle = control.main_control(get_val, motor) control_bus.write(angle) time.sleep(delay_s)
#!/usr/bin/env python3 import motor_commands import interpretor import sensor_commands import controller import bus from sensor_commands import producer as sensor_function from interpretor import consumer_producer as interpreter_function from controller import consumer_producer as controller_function import concurrent.futures from readerwriterlock import rwlock motor = motor_commands.MotorCommands() inter = interpretor.Interpretor() contr = controller.Controller() sens = sensor_commands.SensorCommands() sensor_values_bus = bus.Bus() interpreter_bus = bus.Bus() controller_bus = bus.Bus() sensor_delay = 1 interpreter_delay = 1 controller_delay = 1 with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor: eSensor = executor.submit(sensor_function, sensor_values_bus, sensor_delay) eInterpreter = executor.submit(interpreter_function, sensor_values_bus, interpreter_bus, interpreter_delay)