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

Question: is the openmodelica-to-C external function interface broken?

Question: is the openmodelica-to-C external function interface broken?

From an omc-generated C file:


void eqFunction_32(DATA *data)
{
  $Pground$Pxdot$lB3$rB = 0.0;
}

...

This code involves calling a C function from within a modelica model. The identifier "$Pground$Pxdot$lB3$rB" is, of course, not valid C syntax. Is this a known bug?

Re: Question: is the openmodelica-to-C external function interface broken?

Pardon, I've learned more about preprocessing. However, I'm still left with a bug. If I run gcc -E on the omc output file, I am left with a line that reads:


void eqFunction_7(DATA *data)
{
  collisionDetection_rettype tmp0;
  tmp0 = omc_collisionDetection($Pball, $Pground);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  data->localData[0]->booleanVars[0] = tmp0.c1.colliding;
  copy_real_array_data_mem(&tmp0.c1.sep, &data->localData[0]->realVars[21]);
  data->localData[0]->realVars[27] = tmp0.c1.distance;
}

Any ideas? Is this my problem or omc's?

Re: Question: is the openmodelica-to-C external function interface broken?

That's hard to say without the full model. You have a call to a user-defined function collisionDetection where its inputs do not seem to be part of the final equation system. Might be a problem with the inline module.

Re: Question: is the openmodelica-to-C external function interface broken?

Here's the modelica code. I'm trying to get a very simple collision detection system working. I want to model a soccer ball being kicked.

record objectrecord
    type objectType = enumeration(point, sphere, line, plane);
    Real[3] x;
end objectrecord;

   
class obj
    extends objectrecord;
    Real[3] xdot;
equation
    der(x) = xdot;
end obj;

record collision
    Boolean colliding;
    Real sep[3];
    Real distance;
end collision;


function collisionDetection
    input objectrecord object1, object2;
    output collision info;
external "C" info = distanceObjectToObject(object1, object2);
end collisionDetection;


model World
    obj ground(x.start = {0.0, 0.0, 0.0}, xdot = {0.0, 0.0, 0.0}, objectType = objectrecord.objectType.plane);
    obj ball(x.start = {0.0, 0.0, 1.0}, xdot.start = {0.0, 0.0, 0.0}, objectType = objectrecord.objectType.sphere);
    parameter Real ks = 35000.0;
    parameter Real kd = 50.0;
    parameter Real g[3] = {0.0, 0.0, -9.8};
    collision collisioninfo;
    Real[3] contactforce;
equation
    collisioninfo = collisionDetection(ball, ground);
    contactforce = if collisioninfo.colliding then collisioninfo.sep*ks + ball.xdot*kd else {0.0, 0.0, 0.0};
    der(ball.xdot) = -g - contactforce;
end World;

Re: Question: is the openmodelica-to-C external function interface broken?

A few spontaneous comments:
objectType = objectrecord.objectType.plane should be rejected (objectType is not replaceable and you did not use redeclare). Should probably add a field in the record that you modify.

Also, OpenModelica cannot handle records that contain arrays (I believe this is true for the whole runtime). But that's ok because the Modelica specification does not allow you to pass records in external C declarations anyway current/smile See https://trac.modelica.org/Modelica/ticket/351

There are 0 guests and 0 other users also viewing this topic
You are here: