Inscructions on how to run the closed-loop control in real-time on the Raspberry RPi connected with an Awite biogas analyzer (that "collects" also the data of the biogas flow rate) via Modbus.
The "connections" between the files, the "blood" of this very simple controller structure is the use of "Timestamp" column in dataframes and files, correctly formatted.
- TO BE RUN FROM TERMINAL (in the "...\Example\awite" directory):
modbus3.pypwm_set_R1.py
- TO BE RUN WITH CRONJOB EVERY HH AT HH:01 (in the "...\Example" directory):
cronjob.py
- With
modbus3.pyin the\awitesubfolder you read raw registers data and write likeCSTR_1_2025_05_06.csv(it does reading for both reactors R1 and R2). preprocess_meas.pyin the\awitesubfolder reads raw CSV files and preprocesses them (for both R1 and R2 reactors). It uses thefrom_register_to_data.pyandfrom_data_to_y.pyPython codes/functions. The "first step" of preprocessing is returned asdata_R1.csv. The last step that will be read by the controller is asy_df_data_on_alt_R1.csv(see below).
cronjob.pychecks every hour if the controller shall run or not. IfTrue, it callscontroller.py(modelnameis the number of the reactor you want to perform control on, as string).- In
controller.pytheconvert_u_to_pwm.pyfunction converts the control action in g d$^{-1}$ to ON/OFF duty cycles of the peristaltic pumps (as pulse width modulation (PWM).
NMPC_R1_pwm_actual_ANCILLARY.csvin the\Inputsubfolder is where the output of the controller is written, and read by the code that sets the RPi GPIO pins of the pump (pwm_set_R1.py).
To run an ++off-line example++ with the ++provided data files++:
- put the content of the this repository into the desired path. The main current working directory will be
yourpath\\Example(open terminals from here to subfolders, and addyourpathinside the Python files where the...placeholder is present); - also, modify the system path to be added and specify eventual desired input/output folder paths;
- modify row 46 of
preprocess_meas.pywithnow = datetime(2025,5,8,12,0); - do the same in row 76 of
cronjob.py;