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

Toggling boolean value depending on condition

Toggling boolean value depending on condition

I am trying to toggle a boolean variable depending on some condition as per the following code.

Code:

model boolean_logic_try

 
  Boolean dio_out;
  Boolean dio_out1;

  equation
  if (mod(time,0.01) == 0.0) then
    dio_out1 = not dio_out;
  else
    dio_out1 = dio_out;
  end if;
  dio_out = dio_out1;
 
end boolean_logic_try;

But, I am getting the following error in compilation stage as follows.

Code:

boolean_logic_try_02nls.c: In function 'initializeStaticDataNLS2':

boolean_logic_try_02nls.c:35:84: error: 'BOOLEAN_ATTRIBUTE {aka struct BOOLEAN_ATTRIBUTE}' has no member named 'nominal'
   sysData->nominal[i] = data->modelData->booleanVarsData[0].attribute /* dio_out */.nominal;
                                                                                    ^
boolean_logic_try_02nls.c:36:84: error: 'BOOLEAN_ATTRIBUTE {aka struct BOOLEAN_ATTRIBUTE}' has no member named 'min'
   sysData->min[i]     = data->modelData->booleanVarsData[0].attribute /* dio_out */.min;
                                                                                    ^
boolean_logic_try_02nls.c:37:84: error: 'BOOLEAN_ATTRIBUTE {aka struct BOOLEAN_ATTRIBUTE}' has no member named 'max'
   sysData->max[i++]   = data->modelData->booleanVarsData[0].attribute /* dio_out */.max;
                                                                                    ^
boolean_logic_try_02nls.c: In function 'initializeStaticDataNLS4':
boolean_logic_try_02nls.c:70:84: error: 'BOOLEAN_ATTRIBUTE {aka struct BOOLEAN_ATTRIBUTE}' has no member named 'nominal'
   sysData->nominal[i] = data->modelData->booleanVarsData[0].attribute /* dio_out */.nominal;
                                                                                    ^
boolean_logic_try_02nls.c:71:84: error: 'BOOLEAN_ATTRIBUTE {aka struct BOOLEAN_ATTRIBUTE}' has no member named 'min'
   sysData->min[i]     = data->modelData->booleanVarsData[0].attribute /* dio_out */.min;
                                                                                    ^
boolean_logic_try_02nls.c:72:84: error: 'BOOLEAN_ATTRIBUTE {aka struct BOOLEAN_ATTRIBUTE}' has no member named 'max'
   sysData->max[i++]   = data->modelData->booleanVarsData[0].attribute /* dio_out */.max;
                                                                                    ^
boolean_logic_try_02nls.c: In function 'boolean_logic_try_initialNonLinearSystem':
boolean_logic_try_02nls.c:96:43: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
   nonLinearSystemData[0].getIterationVars = getIterationVarsNLS2;
                                           ^
boolean_logic_try_02nls.c:108:43: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
   nonLinearSystemData[1].getIterationVars = getIterationVarsNLS4;
                                           ^
<builtin>: recipe for target 'boolean_logic_try_02nls.o' failed
\tools\msys\mingw64\bin\mingw32-make: *** [boolean_logic_try_02nls.o] Error 1
\tools\msys\mingw64\bin\mingw32-make: *** Waiting for unfinished jobs....
Compilation process failed. Exited with code 2.

Is there a problem with my logic or something else?
Any help will be greatly appreciated. Thanks in advance.

Re: Toggling boolean value depending on condition

Yes, you have created an algebraic loop saying basically dio_out = not dio_out, which cannot be solved. Make dio_out a discrete variable:

Code:

when sample(0, 0.01) then

  dio_out = not pre(dio_out);
end when;

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