Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem generating c++ code from simscape .mdl

26 views
Skip to first unread message

Simon Mackinnon

unread,
Jul 14, 2009, 11:04:04 AM7/14/09
to
Hey guys,
this is my first post on this forum, so i hope someone might be able to help me.

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

Arnaud Miege

unread,
Jul 14, 2009, 11:32:59 AM7/14/09
to

"Simon Mackinnon" <simon.ma...@gmail.com> wrote in message
news:h3i6p4$8tl$1...@fred.mathworks.com...

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


Simon Mackinnon

unread,
Jul 15, 2009, 2:48:01 AM7/15/09
to
"Arnaud Miege" <arnaud...@nospam.mathworks.co.uk> wrote in message <h3i8fc$4ov$1...@fred.mathworks.com>...
hey Arnaud,
I'm using R2008b with a target of ert.tlc (no auto config),

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

Arnaud Miege

unread,
Jul 16, 2009, 4:12:50 AM7/16/09
to

">>
> hey Arnaud,
> I'm using R2008b with a target of ert.tlc (no auto config),
>
> 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


Simon Mackinnon

unread,
Jul 16, 2009, 7:03:01 AM7/16/09
to
"Arnaud Miege" <arnaud...@nospam.mathworks.co.uk> wrote in message <h3mne3$1gc$1...@fred.mathworks.com>...
Thanks for looking into it. I did end up just using generated C code for what I needed. It was a little bit more difficult than I expected, but I was able to get out what I needed.

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

0 new messages