Modeling a simple embedded system in Modelica

I want to model a very simple embedded system in Modelica (OpenModelica) from a more logical (or behavioral) point of view rather than a low level (electrical) one. The main problem for me is that I've never worked with Modelica before, and I really had trouble figuring out how to look at thoughts in order to model them correctly.

The system should be very simple to start and consists of a sensor that connects via a bus to the controller. The desired system behavior should be that the sensor generates values โ€‹โ€‹periodically and informs the controller via an interrupt. The controller must respond to this interrupt and retrieve the value. The purpose of this example for me, as I mentioned, is to first understand how to look at thoughts in Modelica and get an initial (maybe not very useful) working example that I can iteratively expand to a more complex one.

Here is the system I've modeled so far:

Sensor model:

model ES_Sensor
    parameter Integer id = 1;
    parameter Real frequency = 1.0;
    Integer reg_temperature = 0;
    ES_Interface interface;
algorithm
    when sample(0, 1 / frequency) then
        reg_temperature := reg_temperature + 1;
        interface.interrupt := 1;
    end when;
    when interface.address == id then
        interface.data := reg_temperature;
    end when;
end ES_Sensor;

      

Interface connector:

connector ES_Interface
    flow Real dummy1;
    flow Real dummy2;
    flow Real dummy3;
    Integer address = 0;
    Integer data = 0;
    Integer interrupt = 0;
end ES_Interface;

      

Tire model:

model ES_Bus
    ES_Interface master;
    ES_Interface slave;
equation
    master.data = slave.data;
    master.address = slave.address;
    master.interrupt = slave.interrupt;
end ES_Bus;

      

Controller model:

 model ES_Controller
     ES_Interface interface1;
     Integer reg_a = 0;
 algorithm
     when
          interface1.interrupt == 1 then
          interface1.interrupt := 0;
          interface1.address := 1;
          reg_a := interface1.data;
          interface1.address := 0;
     end when
 end ES_Controller;

      

System model:

 model Simple_System
     ES_Sensor Sensor;
     ES_Bus Bus;
 equation
     connect(Controller.interface1, Bus.master);
     connect(Bus.slave, Sensor.interface);
 end Simple_System;

      

If I try to simulate "Simple_System" I get two errors. One tells me that the system is redefined (35 equations versus 26 variables), and the other says, "Found equation without time-dependent variables: Controller.interface1.interrupt = 0.0".

The first thing I really understand, but I have absolutely an idea on how to solve it. The second one I don't understand at all.

Any help would be appreciated! I would also be grateful if someone could recommend some useful literature to me.

+3


source to share


1 answer


Ok, I suggest you read a little more about Modelica.

You can read the spec: https://modelica.org/documents

Or read Michael T's free book: http://book.xogeny.com/

Or get some books by Peter F: http://www.amazon.com/s?ie=UTF8&page=1&rh=n%3A283155%2Cp_27%3APeter%20Fritzson

Since you don't have a physical connector, you must remove the flow variables from the connector. Also, use reit inside inside equations.



connector ES_Interface
    Integer address;
    Integer data;
    Integer interrupt;
end ES_Interface;

model ES_Sensor
    parameter Integer id = 1;
    parameter Real frequency = 1.0;
    Integer reg_temperature = 0;
    ES_Interface interface;
algorithm
    when sample(0, 1 / frequency) then
        reinit(reg_temperature, reg_temperature + 1);
        reinit(interface.interrupt, 1);
    end when;
    when interface.address == id then
        reinit(interface.data, reg_temperature);
    end when;
end ES_Sensor;

model ES_Bus
    ES_Interface master;
    ES_Interface slave;
equation
    master.data = slave.data;
    master.address = slave.address;
    master.interrupt = slave.interrupt;
end ES_Bus;

model ES_Controller
     ES_Interface interface1;
     Integer reg_a = 0;
 algorithm
     when interface1.interrupt == 1 then
          reinit(interface1.interrupt, 0);
          reinit(interface1.address, 1);
          reinit(reg_a, interface1.data);
     end when;
end ES_Controller;

model Simple_System
     ES_Sensor Sensor;
     ES_Bus Bus;
     ES_Controller Controller;
equation
     connect(Controller.interface1, Bus.master);
     connect(Bus.slave, Sensor.interface);
end Simple_System;

      

Now, if you instantiate the model, you get:

class Simple_System
  parameter Integer Sensor.id = 1;
  parameter Real Sensor.frequency = 1.0;
  Integer Sensor.reg_temperature = 0;
  Integer Sensor.interface.address;
  Integer Sensor.interface.data;
  Integer Sensor.interface.interrupt;
  Integer Bus.master.address;
  Integer Bus.master.data;
  Integer Bus.master.interrupt;
  Integer Bus.slave.address;
  Integer Bus.slave.data;
  Integer Bus.slave.interrupt;
  Integer Controller.interface1.address;
  Integer Controller.interface1.data;
  Integer Controller.interface1.interrupt;
  Integer Controller.reg_a = 0;
equation
  Bus.master.data = Bus.slave.data;
  Bus.master.address = Bus.slave.address;
  Bus.master.interrupt = Bus.slave.interrupt;
  Bus.master.address = Controller.interface1.address;
  Bus.master.data = Controller.interface1.data;
  Bus.master.interrupt = Controller.interface1.interrupt;
  Bus.slave.address = Sensor.interface.address;
  Bus.slave.data = Sensor.interface.data;
  Bus.slave.interrupt = Sensor.interface.interrupt;
algorithm
  when sample(0.0, 1.0 / Sensor.frequency) then
    reinit(/*Real*/(Sensor.reg_temperature), /*Real*/(1 + Sensor.reg_temperature));
    reinit(/*Real*/(Sensor.interface.interrupt), 1.0);
  end when;
  when Sensor.interface.address == Sensor.id then
    reinit(/*Real*/(Sensor.interface.data), /*Real*/(Sensor.reg_temperature));
  end when;
algorithm
  when Controller.interface1.interrupt == 1 then
    reinit(/*Real*/(Controller.interface1.interrupt), 0.0);
    reinit(/*Real*/(Controller.interface1.address), 1.0);
    reinit(/*Real*/(Controller.reg_a), /*Real*/(Controller.interface1.data));
  end when;
end Simple_System;

      

Who has 11 equations and 14 variables. You will need more equations to model the behavior of some variables. Note that when equations are only active at a specific point in time, they are not considered equations. This is why you need to add more equations to the model that tell you how the variable changes continuously over time.

+5


source







All Articles