EFeru / bldc-motor-control-FOC

Field Oriented Control (FOC) for BLDC motors
GNU General Public License v3.0
242 stars 91 forks source link

Generate Code error - Matlab_R2019b #1

Closed omkarg closed 3 years ago

omkarg commented 3 years ago

Hi, I am getting the following error when trying to generate code from Simulink model, could you please help me with this? I am using Matlab_R2019b version

Generating code into build folder: /Users/mac15/Downloads/BLDC/Matlab/bldc-motor-control-FOC-master/01_Libraries/02_Plant/BLDCmotor_FOC_R2017b_fixdt_ert_rtw

Build procedure for model: 'BLDCmotor_FOC_R2017b_fixdt' aborted due to an error.

Error in S-function 'BLDCmotor_FOC_R2017b_fixdt/BLDC_model_closed/BLDC_model_sfcn': S-Function 'BLDC_model_sf' does not exist Component:Simulink | Category:Block diagram error Error in S-function 'BLDCmotor_FOC_R2017b_fixdt/PWM_gates/PWM_generator1/PWM_generator_sfcn': S-Function 'PWM_generator_sf' does not exist

EFeru commented 3 years ago

Did you run the init_model first? Are you able to simulate the model by pressing play?

omkarg commented 3 years ago

Yes, I ran the init_model and it ran successfully. attached screenshot for reference. But if I try to generate code from Simulink it gives that error

Screenshot 2021-04-15 at 11 58 15 PM
omkarg commented 3 years ago

These paths are also set in Matlab (attached screenshot)

Screenshot 2021-04-16 at 12 00 20 AM
omkarg commented 3 years ago

Hi @EmanuelFeru , Is there something else that needs to be set? Or I checked for few resources online to fix this issue by running the mex command but I am unable to find the .c file for it. If you could help me that would be really great

EFeru commented 3 years ago

Are you able to run the model? And yes you need to install a c compiler to run and build the code. See here https://www.mathworks.com/support/requirements/supported-compilers.html I have the first one MinGW.

Also i used Matlab R2017b I am not sure if there are some incompatibility issue. Normally it should be upwards compatible.

omkarg commented 3 years ago

Yes the C compiler is already installed and I am able to run the model from Matlab as seen in the above screenshots but if I run it in Simulink it gives me this error.

Screenshot 2021-04-18 at 11 13 47 PM
EFeru commented 3 years ago

This is an indication that the s functions are not compatible with the 2019b. I will give a try myself next day, I think I still have the 2019b version installed.

omkarg commented 3 years ago

@EmanuelFeru or you can upload the C file for the S functions and I can or anyone else who faces this issue can also generate the S functions.

EFeru commented 3 years ago

Is it possible to generate s-functions from C files?

omkarg commented 3 years ago

I was assuming this would solve the issue, hence mentioned about the C file https://in.mathworks.com/matlabcentral/answers/146644-error-in-s-funtion-s-function-test-does-not-exist. and they had mentioned it here as well https://stackoverflow.com/questions/8953759/s-function-in-simulink-matlab/33988085

omkarg commented 3 years ago

@EmanuelFeru good afternoon. Is it working at your end on 2019b? or any idea on how I can generate the S functions with this version on matlab

asti-softronic commented 3 years ago

Hi, I have the same problem (MATLAB version is: R2021a). Could you upload the .c source for s-functions? Thank you. A.

EFeru commented 3 years ago

Hi,

I just opened the model in it's own folder location in Matlab R2019b and pressed Run. It worked without problem and produces same output as in 2017b. image image

Edit: If I type mex -setup I get this compiler: image

EFeru commented 3 years ago

@omkarg, I see you are using a Mac. I built the s functions on Windows, can that be the problem?

omkarg commented 3 years ago

@EmanuelFeru that can be the issue. How are you generating the S functions on your machine? If you can provide the files for S function I can try to generate it on my mac machine and see if that works.

omkarg commented 3 years ago

The compiler for mac is also different so may be it is because I am using mac machine it is not working

omkarg commented 3 years ago

@asti-softronic are you using a mac machine?

EFeru commented 3 years ago

To build i just Right click the block and then, go to Code generation and click make s-function. I forgot to tell you, but the open model is also there, it is the commented block _open, right above the used block _closed. Have you tried with the open one?

omkarg commented 3 years ago

@EmanuelFeru Yes even I am using the same process to generate S functions but it does not work on mac machine. Yes i tried with open model , for closed model it is used to give 2 errors for open model it gives one error as per the screenshot. I have attached the open model config and the error screenshots. Can you extract the C code for the S function and provide, may be I can try it that way or if you have any other options I can try that

Screenshot 2021-05-03 at 3 39 15 PM Screenshot 2021-05-03 at 3 39 44 PM
EFeru commented 3 years ago

Inside the PWM_gates block there is also the open model. Try replacing the 6 pwm blocks with the open one. If you still have the error you can delete the 6 pwm blocks and connect line directly inside pwm_gates and try to run.

omkarg commented 3 years ago

@EmanuelFeru Yes, it works in open mode. But I will have to get the closed mode working for it to work in FOC right?

EFeru commented 3 years ago

No need for that. The closed part is the plant model not the controller. I closed the model just to have faster simulation time and in case someone does not have the Simulink motor model. But for the controller it doesn't matter if you use open or closed plant model.

EFeru commented 3 years ago

@omkarg Did you manage to make it run in 2019b?

omkarg commented 3 years ago

@EmanuelFeru Apologies for the late response. With the open model I was able to run it in 2019b version