How to deploy neural networks on PLECS

I am currently conducting research on artificial intelligence and power electronics. I have trained a neural network in Python and would like to use it to control a converter, but I am unsure how to port it to PLECS.

Please see the “Buck Converter with Controls in Co-Simulation” demo model which suggests a simple but effective way to link Python and PLECS together.

Thank you, I tried running the demo, but it returned an error message “Cannot read value from input file.” I searched for a long time but still don’t kno


w where the error occurred

I tried to close the terminate function code and check if the output Python. txt file exists. The answer is yes. Python read the output PLECS. txt file normally and stored a number in it, but PLECS failed to read this file. I don’t know why.

I have resolved the issue, and it seems that the fscanf function is not working. I have modified the code for the read section. I replaced the fscanf function with fgets and atof to make the simulation run smoothly.

1 Like

Finally, experts, I would like to ask if this can generate RTbox code. Thank you.

No this code will not work with the RT Box. The RT Box real-time cores will not have necessary underlying OS support for the Python interpreter. Perhaps you could develop something using the communication (e.g. UDP, CAN) or automation blocks (Programmable Value / Data Capture) but I suspect the latency will be unacceptable for most real-time control / modeling needs.

By the way, thank you for pointing out this error and implementing your own fix. We’ll address this in an upcoming release so the example works better out of the box!