Effacer les filtres
Effacer les filtres

Error deploying Python Code to Raspberry Pi

2 vues (au cours des 30 derniers jours)
Farhan Sumantri
Farhan Sumantri le 24 Juin 2022
Réponse apportée : Dinesh le 29 Sep 2023
Hi, I just wanted to test a simple program to test the functionality of running python in a simulink environment as shown in the model below.
with the function block containing the following code:
function out = RunPython(in1, in2)
out = 0; % Has to be preassigned, otherwise Simulink throws an error
coder.extrinsic('py.Python_ExampleCode.test') % Python functions have to be run extrinsically, meaning no C code generated
out = py.Python_ExampleCode.test(in1, in2);
end
with the python code it is referencing being:
def test(in1,in2):
out = in1+in2
return out
And this works fine when run on the development computer, however when i try to deploy this onto a Raspberry Pi Zero W, the following error message comes up.
The extrinsic function 'py.Python_ExampleCode.test' is not available for standalone code generation. It must be eliminated for stand-alone code to be generated. It could not be eliminated because its outputs appear to influence the calling function. Fix this error by not using 'py.Python_ExampleCode.test' or by ensuring that its outputs are unused. Function 'MATLAB Function' (#25.245.271), line 4, column 11: "py.Python_ExampleCode.test"
Just wanted to know how this problem can be worked around or solved. Also note i have verified that the issue is not on the Pi end as I can deploy a simple LED blink test using the Simulink library for the Raspberry Pi

Réponses (1)

Dinesh
Dinesh le 29 Sep 2023
Hi Farhan,
I understand that you are trying to test a simple program to check the functionality of running Python in a Simulink environment. Also, that you can run it properly on your development computer, but you encounter issues when deploying it onto a Raspberry Pi.
The issue arises because when you are performing a simulation, 'coder.extrinsic' functions do not get compiled but are directly sent to MATLAB for execution. However, in the case of code generation, the process is a little bit different. If the output of an 'extrinsic' function affects the output of the calling function, it throws an error. Extrinsic functions for code generation can only be used for data analysis and data logging tasks.
Please refer to the following image, which represents the flow of function execution for extrinsic functions:
For more details regarding the extrinsic functions and using MATLAB engine to execute a function call please refer to the following MATLAB documentation.
Hope this helps.
Best Regards,
Dinesh Reddy Gatla.

Catégories

En savoir plus sur Run on Target Hardware dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by