From 4ac1152c5276b322b0274dcbc20c239acff0dcd7 Mon Sep 17 00:00:00 2001 From: Sumeet Koli Date: Fri, 6 Jul 2018 16:57:15 +0530 Subject: Changes in Documentation --- Resources/Images/BlinkLed.png | Bin 0 -> 13699 bytes package.mo | 269 ++++++++++++++---------------------------- 2 files changed, 88 insertions(+), 181 deletions(-) create mode 100644 Resources/Images/BlinkLed.png diff --git a/Resources/Images/BlinkLed.png b/Resources/Images/BlinkLed.png new file mode 100644 index 0000000..9ae4ca8 Binary files /dev/null and b/Resources/Images/BlinkLed.png differ diff --git a/package.mo b/package.mo index dc13527..c7f4bdf 100644 --- a/package.mo +++ b/package.mo @@ -1,69 +1,85 @@ package OpenModelicaEmbedded "Connecting OpenModelica with Arduino" - package GettingStarted "Procedure to run first model using OpenModelicaEmbedded" - extends Modelica.Icons.Information; - annotation(preferredView = "info", Documentation(info = "
.
-.
-The first thing you need to do is upload the Firmware code to your board .
- -Figure 1. Location of the Firmware sketch.
-If you wish to use PID(Proportional-integral-derivative) then use another firmware provided with the package. To open an firmware through Arduino IDE click on “Open“ and Browse to the location where you extracted the package. Insdie the package folder look for folder named “Firmware“ which contains a file named “pidmata3.ino“. Select that file and click open to load firmware in Arduino IDE.
- Important instructions for using above mentioned firmware “pidmata3.ino“:
-
Once the the Firmware code is in the board, you need to write down the serial port that it is using. This is important because you need to give the port name to OpenModelicaEmbedded in order to communicate with the board. You can find the serial port in Tools->Serial Port or in the bottom-right corner of the Arduino software window (see Figure 2). In Windows the serial port name is something like “COM5”, while in OS X and Linux the name will be something like “/dev/ttyACM0”. Now you are ready to make your first model.
- -Figure 2. Finding the serial port being used.
-As a first exercise, you are going to reproduce with OpenModelicaEmbedded the blinking LED example. You can either open the prebuilt example (OpenModelicaEmbedded.Examples.BlinkLed) or build it by yourself. To build the model, locate the components:
-Connect the components as in Figure 3. One thing to notice is that the DigitalOutput model is connected to the Arduino component to specify that the pin belongs to that board. This connection is necessary because OpenModelicaEmbedded can use multiple boards with multiple pins at the same time.
- -Figure 3. Diagram of the blinking LED.
-Next you need to specify the serial port that the board is using. This is done by selecting the Arduino component and showing its parameters. In the parameter view, you can find the Port parameter. Write the port name that you got in the section “Preparing your board”. Important: the name must be have quotation marks as shown in Figure 4.
- -Figure 4. Specifying the serial port name.
-Now you need to set the pin number that you are going to use in the DigitalOutput component. Usually, the Arduino boards have an LED attached to pin 13. Set that number in the Pin parameter as shown in Figure 5.
- -Figure 5. Specifying the pin to use.
-For the BooleanPulse component, set the 'period' parameter to 1. The model is ready to simulate. Press the simulate button and wait to see the results.
-The first time you run the model, it is probably simulated so fast that you do not have time to react. The reason is that OpenModelica simulates the model as fast as possible. In order to interact with your models using OpenModelicaEmbedded, it is necessary to synchronize the simulation time with real time. This is done in by using Synchronisation block in ModelicaDeviceDriver library. After simulating the model one time, you need to check in the checkbox “Synchronize with real-time” as shown in Figure 6.
- //- //
Figure 6. Synchronizing your simulation with real time.
- //If you are building many models with the OpenModelicaEmbedded library, you should set the “Synchronize with real-time” option as a default simulation setting in SimulationCenter under the menu Tools->Options in the section SimulationCenter->Default Experiment (see Figure 7).
- //- //
Figure 7. Setting \"Synchronize with real-time\" as default.
- //Now run the simulation again and you should see the LED blinking until the simulation reaches the stop time. If you want to keep the simulation running continuously, you need to change the stop time to “infinite” as shown in Figure 8.
- // - //Figure 8. Setting the stop time to infinite.
- //If you run the simulation again, you should see the LED blinking continuously.
-One thing that you may have noticed is that OpenModelicaEmbedded prints status messages in the simulation log (see Figure 9). The first thing it prints is a list of the available ports. In that list, you should see your current port (A). After that, it prints the current port and the speed used (B). Once the port is opened, you receive a notification that the board is initialized (C). Usually the boards report the version of Firmata that you are running. Then you set the sampling interval that the board uses (D). In this example, you can see that you are setting pin 13 to be an output because you have used the DigitalOutput component (E). Finally you will see that the board will send you a list of all the pins available and thier capabilities (F). This list contains the number of the pin and the modes in which it can be used, for example: DigitalInput, DigitalOutput, AnalogInput, AnalogOutput, and Servo.
- -Figure 9. Messages shown by OpenModelicaEmbedded.
-This is a checklist that you can follow in order to solve most of the problems that can occur when using the ModelPlug library:
-If you are still having problems, you can go to http://community.wolfram.com and ask a question.
-OpenModelicaEmbedded contains a series of basic examples showing the functionality of the components. You can check the Examples under ModelPlug.Examples. Once you have learned how to use the basic components of OpenModelicaEmbedded, you can check the Arduino Playground to learn how to connect other sensors and actuators (http://playground.arduino.cc).
", revisions = ""), Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5}))); - end GettingStarted; +package GettingStarted "Procedure to run first model using OpenModelicaEmbedded" + extends Modelica.Icons.Information; + annotation(preferredView = "info", Documentation(info = ".
+.
+The first thing you need to do is upload the Firmware code to your board .
+ +Figure 1. Location of the Firmware sketch.
+If you wish to use PID(Proportional-integral-derivative) then use another firmware provided with the package. To open an firmware through Arduino IDE click on “Open“ and Browse to the location where you extracted the package. Insdie the package folder look for folder named “Firmware“ which contains a file named “pidmata3.ino“. Select that file and click open to load firmware in Arduino IDE.
+ Important instructions for using above mentioned firmware “pidmata3.ino“:
+
Once the the Firmware code is in the board, you need to write down the serial port that it is using. This is important because you need to give the port name to OpenModelicaEmbedded in order to communicate with the board. You can find the serial port in Tools->Serial Port or in the bottom-right corner of the Arduino software window (see Figure 2). In Windows the serial port name is something like “COM5”, while in OS X and Linux the name will be something like “/dev/ttyACM0”. Now you are ready to make your first model.
+ +Figure 2. Finding the serial port being used.
+As a first exercise, you are going to reproduce with OpenModelicaEmbedded the blinking LED example. You can either open the prebuilt example (OpenModelicaEmbedded.Examples.BlinkLed) or build it by yourself. To build the model, locate the components:
+Connect the components as in Figure 3. One thing to notice is that the DigitalOutput model is connected to the Arduino component to specify that the pin belongs to that board. This connection is necessary because OpenModelicaEmbedded can use multiple boards with multiple pins at the same time.
+ +Figure 3. Diagram of the blinking LED.
+Next you need to specify the serial port that the board is using. This is done by selecting the Arduino component and showing its parameters. In the parameter view, you can find the Port parameter. Write the port name that you got in the section “Preparing your board”. Important: the name must be have quotation marks as shown in Figure 4.
+ +Figure 4. Specifying the serial port name.
+Now you need to set the pin number that you are going to use in the DigitalOutput component. Usually, the Arduino boards have an LED attached to pin 13. Set that number in the Pin parameter as shown in Figure 5.
+ +Figure 5. Specifying the pin to use.
+For the BooleanPulse component, set the 'period' parameter to 1. The model is ready to simulate. Press the simulate button and wait to see the results.
+The first time you run the model, it is probably simulated so fast that you do not have time to react. The reason is that OpenModelica simulates the model as fast as possible. In order to interact with your models using OpenModelicaEmbedded, it is necessary to synchronize the simulation time with real time. This is done in by using Synchronisation block in ModelicaDeviceDriver library. After simulating the model one time, you need to check in the checkbox “Synchronize with real-time” as shown in Figure 6.
+ //+ //
Figure 6. Synchronizing your simulation with real time.
+ //If you are building many models with the OpenModelicaEmbedded library, you should set the “Synchronize with real-time” option as a default simulation setting in SimulationCenter under the menu Tools->Options in the section SimulationCenter->Default Experiment (see Figure 7).
+ //+ //
Figure 7. Setting \"Synchronize with real-time\" as default.
+ //Now run the simulation again and you should see the LED blinking until the simulation reaches the stop time. If you want to keep the simulation running continuously, you need to change the stop time to “infinite” as shown in Figure 8.
+ // + //Figure 8. Setting the stop time to infinite.
+ //If you run the simulation again, you should see the LED blinking continuously.
+One thing that you may have noticed is that OpenModelicaEmbedded prints status messages in the simulation log (see Figure 9). The first thing it prints is a list of the available ports. In that list, you should see your current port (A). After that, it prints the current port and the speed used (B). Once the port is opened, you receive a notification that the board is initialized (C). Usually the boards report the version of Firmata that you are running. Then you set the sampling interval that the board uses (D). In this example, you can see that you are setting pin 13 to be an output because you have used the DigitalOutput component (E). Finally you will see that the board will send you a list of all the pins available and thier capabilities (F). This list contains the number of the pin and the modes in which it can be used, for example: DigitalInput, DigitalOutput, AnalogInput, AnalogOutput, and Servo.
+ +Figure 9. Messages shown by OpenModelicaEmbedded.
+This is a checklist that you can follow in order to solve most of the problems that can occur when using the OpenModelicaEmbedded library:
+If you are still having problems, you can go to https://github.com/manasdas17/OpenModelicaEmbedded and ask a question.
+OpenModelicaEmbedded contains a series of basic examples showing the functionality of the components. You can check the Examples under OpenModelicaEmbedded.Examples. Once you have learned how to use the basic components of OpenModelicaEmbedded, you can check the Arduino Playground to learn how to connect other sensors and actuators (http://playground.arduino.cc).
", revisions = ""), Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5}))); +end GettingStarted; + + + + + + + + + + + + + + + + package Pins "Components to access the board I/O" @@ -274,7 +290,7 @@ end customBoard; model BlinkLed "Basic example of blinking an LED" extends Modelica.Icons.Example; - replaceable OpenModelicaEmbedded.Boards.Arduino arduino(Port = "COM4", ShowPinCapabilities = true, UseDTR = false) annotation(Placement(visible = true, transformation(origin = {30, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + replaceable OpenModelicaEmbedded.Boards.Arduino arduino(Port = "/dev/ttyACM0", ShowPinCapabilities = true, UseDTR = false) annotation(Placement(visible = true, transformation(origin = {30, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); OpenModelicaEmbedded.Pins.DigitalOutput digitalOutput(Pin = 9) annotation(Placement(visible = true, transformation(origin = {0, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( Placement(visible = true, transformation(origin = {35, 15}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); @@ -716,18 +732,18 @@ end arduino_ex4_led_blink; model arduino_ex1_push_button_status extends Modelica.Icons.Example; Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime1 annotation( - Placement(visible = true, transformation(origin = {-70, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Placement(visible = true, transformation(origin = {-60, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); OpenModelicaEmbedded.Boards.Arduino arduino1(Port = "/dev/ttyACM0") annotation( Placement(visible = true, transformation(origin = {-60, 3.55271e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); OpenModelicaEmbedded.Pins.DigitalInput digitalInput1(Pin = 12) annotation( - Placement(visible = true, transformation(origin = {0, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Placement(visible = true, transformation(origin = {10, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); Modelica.Blocks.Interaction.Show.BooleanValue booleanValue1 annotation( Placement(visible = true, transformation(origin = {80, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); equation - connect(digitalInput1.y, booleanValue1.activePort) annotation( - Line(points = {{20, 0}, {54, 0}, {54, 0}, {58, 0}}, color = {255, 0, 255})); - connect(arduino1.boardConnector, digitalInput1.pinConnector) annotation( - Line(points = {{-60, 0}, {-20, 0}})); + connect(arduino1.boardConnector, digitalInput1.pinConnector) annotation( + Line(points = {{-60, 0}, {-10, 0}})); + connect(digitalInput1.y, booleanValue1.activePort) annotation( + Line(points = {{30, 0}, {58, 0}}, color = {255, 0, 255})); Modelica.Utilities.Streams.print(String(booleanValue1.activePort)); end arduino_ex1_push_button_status; @@ -1744,115 +1760,6 @@ end ArduinoExamples; end Interfaces; annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {10, 10}), graphics = {Polygon(visible = true, origin = {1.383, -4.142}, rotation = 45, fillColor = {64, 64, 64}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, points = {{-15, 93.333}, {-15, 68.333}, {0, 58.333}, {15, 68.333}, {15, 93.333}, {20, 93.333}, {25, 83.333}, {25, 58.333}, {10, 43.333}, {10, -41.667}, {25, -56.667}, {25, -76.667}, {10, -91.667}, {0, -91.667}, {0, -81.667}, {5, -81.667}, {15, -71.667}, {15, -61.667}, {5, -51.667}, {-5, -51.667}, {-15, -61.667}, {-15, -71.667}, {-5, -81.667}, {0, -81.667}, {0, -91.667}, {-10, -91.667}, {-25, -76.667}, {-25, -56.667}, {-10, -41.667}, {-10, 43.333}, {-25, 58.333}, {-25, 83.333}, {-20, 93.333}}), Polygon(visible = true, origin = {10.102, 5.218}, rotation = -45, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, points = {{-15, 87.273}, {15, 87.273}, {20, 82.273}, {20, 27.273}, {10, 17.273}, {10, 7.273}, {20, 2.273}, {20, -2.727}, {5, -2.727}, {5, -77.727}, {10, -87.727}, {5, -112.727}, {-5, -112.727}, {-10, -87.727}, {-5, -77.727}, {-5, -2.727}, {-20, -2.727}, {-20, 2.273}, {-10, 7.273}, {-10, 17.273}, {-20, 27.273}, {-20, 82.273}})})); end Internal; - annotation(preferredView = "info", Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5})), Documentation(info = "ModelPlug is a library that allows you to connect your simulations with the real world. It uses an Arduino board (or compatible) to send analog and digital signals to physical devices and receive signals from them.
- --
With ModelPlug, you can combine simulation models and real hardware. For example, you can get data from your hardware, design a control, and test it in real time.
-- -
You can build a real control panel and use it to control your simulation models.
- -ModelPlug provides the following components:
-- | Inputs | -- |
Analog input | -Reads analog values from the pins | -- |
Digital input | -Reads digital values from the pins | -- |
- | Output | -- |
Analog output | -Writes analog values to the pins | -- |
Digital output | -Writes digital values to the pins | -- |
Servo control | -Writes the angle to servo motors | -- |
- | Board Handlers | -- |
Arduino | -Connects to Arduino boards like Arduino Uno, Arduino Mega 2560 | -- |
Arduino Leonardo | -Connects to Arduino Leonardo boards and boards using native USB | -- |
StandardFirmata | -Connects to Arduino-compatible boards | -- |
CustomFirmata | -Connects to any board supporting Firmata | -- |
ModelPlug connects with the boards using USB serial communication. In order to configure, read, and write to the board, ModelPlug uses the Firmata protocol v2.3 (http://www.firmata.org). This protocol allows you to connect not only to Arduinos, but also to many boards compatible with Arduino. Examples of other boards supporting the Firmata protocol are:
-ModelPlug wraps the functionality of Firmata by providing easy-to-use Modelica models that you can connect in your simulations.
-ModelPlug requires a board with Firmata Version 2.3 or higher.
-Currently ModelPlug does not support sensors that communicate through I2C or SPI with the board.
-The minimum synchronization interval is 1 ms; therefore, ModelPlug cannot have a sampling interval smaller than that. The standard Firmata allows a minimum sampling interval of 10 ms.
ModelPlug uses a serial protocol; therefore, the transfer speed is constrained by the serial port speed. This can be problematic when reading or writing too many inputs/outputs with a small sampling interval.
Ask questions about SystemModeler and ModelPlug
- -Find out how to connect sensors and actuators to the Arduino
- -Get details about the Firmata protocol
- -The breadboard diagrams were created using Fritzing
- --
-
", revisions = ""), version = "1.2", Icon(coordinateSystem( initialScale = 0.1, grid = {5, 5}), graphics = {Rectangle(fillColor = {0, 170, 255}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, extent = {{-100, -100}, {100, 100}}, radius = 25), Text(origin = {-47.5, 55}, extent = {{-42.5, 15}, {137.5, -80}}, textString = "OpenModelica", textStyle = {TextStyle.Bold}), Text(origin = {2.5, -15}, extent = {{-77.5, 15}, {77.5, -15}}, textString = "Embedded", textStyle = {TextStyle.Bold})}), Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5})), + annotation(preferredView = "info", Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5})), version = "1.2", Icon(coordinateSystem( initialScale = 0.1, grid = {5, 5}), graphics = {Rectangle(fillColor = {0, 170, 255}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, extent = {{-100, -100}, {100, 100}}, radius = 25), Text(origin = {-47.5, 55}, extent = {{-42.5, 15}, {137.5, -80}}, textString = "OpenModelica", textStyle = {TextStyle.Bold}), Text(origin = {2.5, -15}, extent = {{-77.5, 15}, {77.5, -15}}, textString = "Embedded", textStyle = {TextStyle.Bold})}), Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5})), uses(Modelica_DeviceDrivers(version = "1.5.0"), Modelica(version = "3.2.2"))); end OpenModelicaEmbedded; -- cgit