I'm new to simscape, and therefore am struggling to complete this task. I'm trying to generate c++ code from an .mdl (the same as the "simple mech" exercise in the getting started help guide, called SimpleMech.mdl)
I've been able to generate c code fine, but when i change the language to c++ and attempt to build,
I get this error:
Error building Real-Time Workshop target for block diagram 'SimpleMech'. MATLAB error message:
Error using ==> tlc_c at 116
Undefined function or variable 'targetLang'.
If anyone is aware of the cause of this problem, it would be greatly appriciated to hear a response.
cheers
Which version and which target are you using? I am using R2009a and GRT
target with C++ selected as language and I get the following error message:
"Error building Real-Time Workshop target for block diagram
'ssc_simple_mechanical_system'. MATLAB error message: Simscape does not
currently support C++ code generation."
If I select the C language, it works OK through. Is there a particular
reason why you would need C++?
To generate (C) code, here's the steps I generally take:
- select fixed-step solver ode14x (extrapolation oder 2, nb of Newton's
iterations 4) and select the largest sample time I can get away with.
Compare with variable steps results and iterate until you have good
correlation. Here I used 1ms.
- In the solver block, change to use fixed-cost initialization with 4
non-linear ietrations and 2 mode iterations. Use Fulll linear algebra. Run
the model and check for agreement
- Generate code for GRT and run the executable. Check for agreement.
- Run on real-time platform (note the model must run sufficient fast in
simulation to be able to run in real-time).
HTH,
Arnaud
The reason I need to generate C++ code is to link it to an orocos component and simulate the component using that.
II'm able to simulate it in Simscape using a fixed-step solver (ode2 Heun) with a step-size of 0.002. This simulates the outputs fairly accurately compared to the variable step solver and is also pretty quick as well. If i change to ode14x it gives the same results, but still results in the same error when attempting to build.
Simon
As I mentioned, C++ code generation isn't supported by Simscape. The error
message in R2009a is somehwat clearer thatn the one in R2008b. Generally,
people generate C (and not C++) code from Simscape models to run in
real-time for HIL testing, and the steps I have mentioned reflect that
workflow. Nevertheless, I have created an enhancement report to add C++ code
generation from Simscape and to clarify the documentation.
HTH,
Arnaud
Hopefully people in the future will have the option to generate C++ as it fits well with component based design (in my view anyway.)
Thanks again,
Simon