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
  • » glenhenshaw
  • » Profile

Posts

Posts

Jan-16-13 19:16:47
OMC-generated c files contain invalid C identifiers
Category: Developer

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;

Jan-16-13 01:32:23
OMC-generated c files contain invalid C identifiers
Category: Developer

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?

Jan-16-13 00:58:28
OMC-generated c files contain invalid C identifiers
Category: Developer

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?

Jan-03-13 20:27:37
Does OpenModelica support contact dynamics in the MultiBody library?

I would like to model a soccer player kicking a ball. Papers by Michael Otter et al indicate that contact dynamics suitable for this problem were included in the Modelica MultiBody library around 2005, but colleagues of mine who use Modelica are not so sure. Does OpenModelica support Otter's (or anyone else's) collision detection and contact modeling?

Dec-14-12 01:25:46
Converting the BouncingBall demo to use array variables fails...

Oh, so it's a bug? That's good to know, won't keep banging my head against it then. Thanks!

Dec-14-12 00:33:25
Converting the BouncingBall demo to use array variables fails...

I would like to modify the BouncingBall demo to be three dimensional instead of one. The cleanest way to do this would seem to be to use 3-vectors for the position and velocity. However, a straightforward rewrite of the demo code fails; the problem is apparently the reinit() command. The code is as follows:



model Ball
    Real[3] x(start={0.0, 0.0, 0.0});
    Real[3] xdot;
    Real[3] xdot_new;
   
    parameter Real g=9.81 "gravitational acceleration";
    parameter Real e=0.7 "coefficient of restitution";

    Boolean impactWithFloor;
    Boolean flying(start=true) "true, if ball is flying";
 
equation
    impactWithFloor = x[3]<=0.0;
   
    der(x) = xdot;
    der(xdot) = if flying then {0.0, 0.0, -g} else {0.0, 0.0, 0.0};
   
    when {x[3] <= 0.0 and xdot[3] <= 0.0, impactWithFloor} then
        xdot_new = if edge(impactWithFloor) then {0.0, 0.0, -e*pre(xdot[3])} else {0.0, 0.0, 0.0};
        flying = xdot_new[3] > 0;
        reinit(xdot, xdot_new);
    end when;

end Ball;


The simulation fails with the error:

base_array.c: array dimensions sizes are NULL!
Assertion failed: (base_array_ok(source)), function copy_real_array_data_mem, file util/real_array.c, line 142.

Rewriting the Ball object to use three scalar variables x1, x2, x3 works fine. What's going on here?

Dec-13-12 22:17:14
There's some magic to this but I can't figure it out...

I don't use OMEdit because it crashes on startup on my machine. I'm running OSX 10.8.2 and I'm using the openmodelica-devel port. OMNotebook also doesn't work, or at least that's what the port documentation says. So OMShell is the only interactive environment I have available.

Dec-12-12 01:25:45
There's some magic to this but I can't figure it out...

Aha, success. It requires a fully qualified path name. Running system("Users/myname/Code/modelica/examples/BouncingBall -override h=5") works.

This is, needless to say, a pain in the butt. Is there any way to modify the behavior?

Dec-12-12 01:23:33
There's some magic to this but I can't figure it out...

I'm guessing, but I think the problem may be that the system("foo") command isn't doing what I think it should be doing, ie it doesn't seem to actually execute BouncingBall. It returns "127" - what does that indicate?

In fact, the result is identical whether I do a system("BouncingBall") or a system("foo"), where foo does not exist - I still get a 127 return value.

Dec-12-12 01:21:03
There's some magic to this but I can't figure it out...

Yeah, I tried that. There *is* a "BouncingBall" file, and it is an executable and does run. But the above commands *still* don't seem to change the initial value of h. I always get the identical plot.

Dec-12-12 01:01:31
There's some magic to this but I can't figure it out...

First, I really appreciate the help.

When I run either set of code, everything seems to execute - I don't get any errors - but the output is identical. h is not initialized to 5, it is initialized to 1.

In the directory where I have saved the BouncingBall.mo file, after doing the simulate or buildModel, there are a lot of generated files, but "BouncingBall.exe" isn't one of them. Repeat: there does not seem to be a BouncingBall.exe file anywhere I look. BouncingBall.c, BouncingBall.o, BouncingBall.libs, and so on, but no executable.

For what it's worth, I'm running OSX and installed using the openmodelica-devel port.

Dec-12-12 00:17:21
There's some magic to this but I can't figure it out...

Maybe I'm missing something here, because the above don't make sense to me...

What I *think* I would like to do is enter an OMShell interactive session, load a model, set some initial values, and run a simulation. Something like:

> loadFile("BouncingBall.mo")
> h(start)=5
> simulate(BouncingBall, startTime=0.0, stopTime=10.0)
> plot(h)

I can run the commands in Adeel's example, and they seem to execute, but make no difference. Every time I run the simulate command, h is initialized to 0. No XML file seems to get loaded. Adrian's suggestion is for how to do this from a terminal shell, not, it seems, from OMShell.

If the preferred way to interact with modelica is from the command line, then that's OK, but if that's the case I'm confused about what OMShell is for. As I try to learn this, I feel like I'm missing a piece of documentation that tells me how to use OMShell. I get the language just fine, it's great, and it's well documented. But the tools that surround it don't seem to be documented well anywhere. Where should I look?

Dec-11-12 19:42:14
There's some magic to this but I can't figure it out...

Excuse me, that should be how do I load it in OMShell?

Dec-11-12 19:41:50
There's some magic to this but I can't figure it out...

Where do I find it, and how do I load it in OMEdit?

Dec-08-12 01:39:39
There's some magic to this but I can't figure it out...

Suppose I want to run a simulation in OMShell (for instance, the Bouncing Ball demo simulation), but I want to play with different initial values of a state variable (h from the Bouncing Ball model). There must be a way of initializing h to a value without manually modifying and reloading the .mo file, but there doesn't seem to be any documentation on it, and it isn't at all obvious how to go about it. What's the trick?

Dec-07-12 21:13:25
openmodelica +python port for OSX appears to fail under Mountain Lion
Category: Developer

NB that manually executing:

> cd /opt/local/var/macports/build/_opt_local_var_macports_sources_build.openmodelica.org_macports_lang_openmodelica-devel/openmodelica-devel/work/openmodelica_14280/PythonInterface
> sudo omniidl -p/opt/local/lib/python2.7/site-packages/omniidl_be -bpython -Wbglobal=_OMCIDL -Wbpackage=OMPythonIDL ..//Compiler/runtime/omc_communication.idl
> sudo port install openmodelica-devel +python

appears to allow the install to proceed. However, adding /opt/local/lib/python2.7/site-packages/omniidl_be to my PYTHONPATH in ~/.profile does not work.

Dec-07-12 19:42:28
openmodelica +python port for OSX appears to fail under Mountain Lion
Category: Developer

I think the openmodelica +python port is broken. I execute:

> sudo port install openmodelica +python

and eventually I get


--->  Computing dependencies for openmodelica
--->  Staging openmodelica into destroot
Error: org.macports.destroot for port openmodelica returned: command execution failed
Please see the log file for port openmodelica for details:
    /opt/local/var/macports/logs/_opt_local_var_macports_sources_build.openmodelica.org_macports_lang_openmodelica/openmodelica/main.log
To report a bug, follow the instructions in the guide:
    http://guide.macports.org/#project.tickets
Error: Processing of port openmodelica failed

-------------------------------------
The end of the log file reads:


:info:destroot (time /usr/bin/make -C PythonInterface -f Makefile)
:info:destroot make[1]: Entering directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_build.openmodelica.org_macports_lang_openmodelica/openmodelica/work/openmodelica_14071/PythonInterface'
:info:destroot omniidl -bpython -Wbglobal=_OMCIDL -Wbpackage=OMPythonIDL ..//Compiler/runtime/omc_communication.idl
:info:destroot omniidl: Could not import back-end 'python'
:info:destroot omniidl: Maybe you need to use the -p option?
:info:destroot omniidl: (The error was 'No module named python')
:info:destroot make[1]: *** [OMPythonIDL/omc_communication_idl.py] Error 1
:info:destroot make[1]: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_build.openmodelica.org_macports_lang_openmodelica/openmodelica/work/openmodelica_14071/PythonInterface'
:info:destroot
:info:destroot real    0m0.474s
:info:destroot user    0m0.070s
:info:destroot sys    0m0.030s
:info:destroot make: *** [install-python] Error 2
:info:destroot make: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_build.openmodelica.org_macports_lang_openmodelica/openmodelica/work/openmodelica_14071'
:info:destroot Command failed:  cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_build.openmodelica.org_macports_lang_openmodelica/openmodelica/work/openmodelica_14071" && /usr/bin/make -w install DESTDIR=/opt/local/var/macports/build/_opt_local_var_macports_sources_build.openmodelica.org_macports_lang_openmodelica/openmodelica/work/destroot
:info:destroot Exit code: 2
:error:destroot org.macports.destroot for port openmodelica returned: command execution failed
:debug:destroot Error code: CHILDSTATUS 36007 2
:debug:destroot Backtrace: command execution failed
    while executing
"system -nice 0 $fullcmdstring"
    ("eval" body line 1)
    invoked from within
"eval system $notty $nice \$fullcmdstring"
    invoked from within
"command_exec destroot"
    (procedure "portdestroot::destroot_main" line 2)
    invoked from within
"$procedure $targetname"
:info:destroot Warning: targets not executed for openmodelica: org.macports.activate org.macports.destroot org.macports.install
:notice:destroot Please see the log file for port openmodelica for details:
    /opt/local/var/macports/logs/_opt_local_var_macports_sources_build.openmodelica.org_macports_lang_openmodelica/openmodelica/main.log

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