Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register
  • Index
  • » Users
  • » Allyson10
  • » Profile

Posts

Posts

Mar-02-21 12:57:33
Hi, I need to implement an external C function in Modelica.

It worked! Thank you!

Mar-01-21 23:00:25
Hi, I need to implement an external C function in Modelica.

I've seen many examples on how to implement it and it seems so simple, but every time I try to run an external function written in C an error happens.
My goal is to apply it on a predictive control system, but first I'd like to do an simple example to learn how to do it. Can someone help me?

I've tried this example:

class ChirpSignal

  Modelica.Blocks.Interfaces.RealOutput u;
  parameter Modelica.SIunits.AngularVelocity w_start=0;
  parameter Modelica.SIunits.AngularVelocity w_end=10;
  parameter Real A=1;
  parameter Real M=10;
equation
  u=Chirp(w_start, w_end, A, M, time);

end ChirpSignal;

With the Chirp function being:

function Chirp

input Modelica.SIunits.AngularVelocity w_start;
input Modelica.SIunits.AngularVelocity w_end;
input Real A;
input Real M;
input Real t;
output Real u "output signal";
external "C" annotation(Include="#include \"Chirp.c\"");

end Chirp;

And the .c file as:

double Chirp(double w1, double w2, double A, double M, double time)
{
double res;
res=A*w1*w2*M*time;
return res;
}

The error is as shown bellow:
https://drive.google.com/file/d/1AqUfquOGoU07RwUqfP87ZkqckiFR9Jqe/view?usp=sharing

I'm not using a header file, but already tried to use it. What should I do?

Thank you!

  • Index
  • » Users
  • » Allyson10
  • » Profile
You are here: