Help - Search - Members - Calendar
Full Version: using enumeration for states
Modelica Forum > Modelica > MathModelica / OpenModelica
daniel@ka
Hi,

package motion

model ramp
type State = enumeration (A,B,C);
discrete State state(start = State.A);
discrete Integer i(start = 10);
algorithm
when sample(0,1) then
i := i + 1;
// state := State.A; // error when uncommented
end when;
end ramp;

end motion;

I want to separate the motion equations into 3 states: accelerating,driving,decelerating
each state will provide its own equations for x and v.
Unfortunately the above code gives an error. Is there something wrong with usage of
enumeration variables or are enumerations not supported for the purpose I would like them to use?

Thanks in advance,

Daniel
liuliu
for dymola 6.1 using Enumeration types, see following codes,

CODE


model ramp
State.Temp state(
                start=State.accelerating);
  
discrete Integer i(start = 10);
algorithm
when sample(0,1) then
i := i + 1;
state := State.accelerating; // error when uncommented
end when;
end ramp;



additionaly you need this package
CODE

package State
   extends Modelica.Icons.Enumeration;
  constant Integer accelerating=1;
  constant Integer driving=2;
  constant Integer decelerating=3;
    type Temp
    
    extends Modelica.Icons.TypeInteger;
    end Temp;
end State;

it is some workaround for the enumeration type, hopefully this will help you

Regards

QUOTE(daniel@ka @ Nov 23 2009, 11:29 AM) *

Hi,

package motion

model ramp
type State = enumeration (A,B,C);
discrete State state(start = State.A);
discrete Integer i(start = 10);
algorithm
when sample(0,1) then
i := i + 1;
// state := State.A; // error when uncommented
end when;
end ramp;

end motion;

I want to separate the motion equations into 3 states: accelerating,driving,decelerating
each state will provide its own equations for x and v.
Unfortunately the above code gives an error. Is there something wrong with usage of
enumeration variables or are enumerations not supported for the purpose I would like them to use?

Thanks in advance,

Daniel

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.