Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.etrice.doc/doc/020-tutorial-blinky.textile')
-rw-r--r--plugins/org.eclipse.etrice.doc/doc/020-tutorial-blinky.textile47
1 files changed, 39 insertions, 8 deletions
diff --git a/plugins/org.eclipse.etrice.doc/doc/020-tutorial-blinky.textile b/plugins/org.eclipse.etrice.doc/doc/020-tutorial-blinky.textile
index 133c7e459..bd32d6a0c 100644
--- a/plugins/org.eclipse.etrice.doc/doc/020-tutorial-blinky.textile
+++ b/plugins/org.eclipse.etrice.doc/doc/020-tutorial-blinky.textile
@@ -5,13 +5,15 @@ h2. Scope
This tutorial describes how to use the ??TimingService??, how to combine a generated model with manual code and how to model a hierarchical state machine. The idea of the tutorial is to switch a LED on and off. The behavior of the LED should be: blinking in a one second interval for 5 seconds, stop blinking for 5 seconds, blinking, stop,...
For this exercise we will use a little GUI class that will be used in more sophisticated tutorials too. The GUI simulates a pedestrian traffic crossing. For now, just a simple LED simulation will be used from the GUI.
-To use the GUI please copy the package ??de.protos.PedLightGUI?? to your ??src?? directory. The package contains four java classes which implement a small window with a 3-light traffic light which simulates the signals for the car traffic and a 2-light traffic light which simulates the pedestrian signals.
+After the exercise is created you must copy the GUI to your src directory (see below).
+
+The package contains four java classes which implements a small window with a 3-light traffic light which simulates the signals for the car traffic and a 2-light traffic light which simulates the pedestrian signals.
The GUI looks like this:
!images/020-Blinky08.png!
-Within this tutorial we just will toggle the yellow light.
+Within this tutorial we will just toggle the yellow light.
You will perform the following steps:
@@ -28,6 +30,9 @@ h2. Create a new model from scratch
Remember exercise ??HelloWorld??.
Create a new eTrice project and name it ??Blinky??
+
+To use the GUI please copy the package ??org.eclipse.etrice.tutorials.PedLightGUI?? from "org.eclipse.etrice.tutorials/src" to your ??src?? directory "Blinky/src". For this tutorial you must remove the error markers by editing the file ??PedestrianLightWndNoTcp.java??. Appropriate comments are provided to remove the error marker for this turorial.
+
Open the ??Blinky.room?? file and copy the following code into the file or use content assist to create the model.
bc..
@@ -58,6 +63,8 @@ Select ??ActorClass - actor class skeleton?? and name it ??Blinky??.
Repeat the described procedure and name the new actor ??BlinkyController??.
+With Ctrl+Shift+F you can beautify the model code.
+
Save the model and visit the outline view.
h2. Create a new protocol
@@ -73,7 +80,29 @@ With Ctrl-Shift+F or selecting ??Format?? from the context menu you can format t
h2. Import the Timing Service
-Switching on and off the LED is timing controlled. Therefore a timing service is needed. To import the timing service in the outline view right click to ??SubSystem_Blinky??. Select ??Edit Structure??. Drag and Drop an ??ActorRef?? to the ??SubSystem_Blinky?? and name it ??application??. From the actor class drop down list select ??BlinkyTop??. Do the same clicks for the timing service. Name it ??timingService?? and from the drop down list select ??room.basic.service.timing.ATimingService??. Draw a ??LayerConnection?? from ??application?? to each service provision point (SPP) of the ??timingService??. The resulting structure should look like this:
+Switching on and off the LED is timing controlled. The timing service is provided from the model library and must be imported before it can be used from the model.
+
+This is the first time you use an element from the modellib. Make sure that your Java Build Path has the appropriate entry to the modellib. Otherwise the jave code, which will be generated from the modellib, can not be referenced.
+(right click to ??Blinky?? and select properties. Select the ??Java Build Path?? tab)
+
+!images/020-Blinky16.png!
+
+After the build path is set up return to the model and navigate the cursor at the beginning of the model and import the timing service:
+
+bc..
+RoomModel Blinky {
+
+ import room.basic.service.timing.* from "../../org.eclipse.etrice.modellib/models/TimingService.room"
+
+ LogicalSystem System_Blinky {
+ SubSystemRef subsystem: SubSystem_Blinky
+ }
+...
+bq.
+
+Make sure that the path fits to your folder structure.
+
+Now it can be used within the model. Right click to ??SubSystem_Blinky?? within the outline view. Select ??Edit Structure??. The ??application?? is already referenced in the subsystem. Drag and Drop an ??ActorRef?? to the ??SubSystem_Blinky?? and name it ??timingService??. From the actor class drop down list select ??room.basic.service.timing.ATimingService??. Draw a ??LayerConnection?? from ??application?? to each service provision point (SPP) of the ??timingService??. The resulting structure should look like this:
!images/020-Blinky06.png!
@@ -90,7 +119,7 @@ The resulting code should look like this:
h2. Finish the model structure
-From the outline view right click to ??Blinky?? and select ??Edit Structure??. Drag and Drop an ??Interface Port?? to the boarder of the ??Blinky?? actor. Note that an interface port is not possible inside the the actor. Name the port ??ControlPort?? and select ??BlinkyControlProtocol?? from the drop down list. Uncheck ??Conjugated?? and ??Is Relay Port??. Klick ??ok??. The resulting structure should look like this:
+From the outline view right click to ??Blinky?? and select ??Edit Structure??. Drag and Drop an ??Interface Port?? to the boarder of the ??Blinky?? actor. Note that an interface port is not possible inside the actor. Name the port ??ControlPort?? and select ??BlinkyControlProtocol?? from the drop down list. Uncheck ??Conjugated?? and ??Is Relay Port??. Klick ??ok??. The resulting structure should look like this:
!images/020-Blinky04.png!
@@ -116,7 +145,7 @@ Use the ??Transition?? tool to draw transitions from ??init?? to ??off?? from ??
Open the transition dialog by double click the arrow to specify the trigger event and the action code of each transition. Note that the initial transition does not have a trigger event.
-The dialog should look like this:
+The transition dialog should look like this:
!{width=500px}images/020-Blinky09.png!
@@ -125,6 +154,7 @@ The defined ports will be generated as a member attribute of the actor class fro
Within each transition the timer will be restarted and the appropriate message will be sent via the ??ControlPort??.
The resulting state machine should look like this:
+(Note that the arrows peak changes if the transition contains action code.)
!images/020-Blinky10.png!
@@ -136,15 +166,16 @@ Now we will implement ??Blinky??. Due to the fact that ??Blinky?? interacts with
Double click ??Blinky?? in the outline view to navigate to ??Blinky?? within the model file.
Add the following code:
+(type it or simply copy it from the tutorial project)
!images/020-Blinky12.png!
??usercode1?? will be generated at the beginning of the file, outside the class definition. ??usercode2?? will be generated within the class definition. The code imports the GUI class and instantiates the window class. Attributes for the carLights and pedLights will be declared to easily access the lights in the state machine.
The Operation ??destroyUser()?? is a predefined operation that will be called during shutdown of the application. Within this operation, cleanup of manual coded classes can be done.
-
-
-Now design the FSM of ??Blinky??. Open the behavior diagram of ??Blinky?? by right clicking the ??Blinky?? actor in the outline view. Create two states named ??blinking?? and ??off??. Right click to ??blinking?? and create a subgraph.
+Now design the FSM of ??Blinky??. Remember, as the name suggested ??blinking?? is a state in which the LED must be switched on and off. We will realize that by an hierarchical FSM in which the ??blinking?? state has two sub states.
+
+Open the behavior diagram of ??Blinky?? by right clicking the ??Blinky?? actor in the outline view. Create two states named ??blinking?? and ??off??. Right click to ??blinking?? and create a subgraph.
!images/020-Blinky13.png!

Back to the top