CIP Statemachine - Lamp

Table of Contents

logo-large

Tutorial Actifsource Tutorial – CIP Statemachine - Lamp
Required Time - 60 Minutes
Prerequisites - Actifsource Tutorial – Actifsource Tutorial – Installing Actifsource
-Actifsource Tutorial – Simple Service
Goal - Creating a state machine using the CIP method
- Generating real time C code for any embedded system
Topics covered - Setting up a new CIP Project
- Communicating with the Outer World
- Specify the State Machine
- Generating State Machine Code
Notation ↪ To do
ⓘ Information
Bold: Terms from actifsource or other technologies and tools
Bold underlined: actifsource Resources
Monospaced: User input
Italics: Important terms in current situation
Disclaimer The authors do not accept any liability arising out of the application or use of any information or equipment described herein. The information contained within this document is by its very nature incomplete. Therefore the authors accept no responsibility for the precise accuracy of the documentation contained herein. It should be used rather as a guide and starting point.
Contact Actifsource AG
Täfernstrasse 37
5405 Baden-Dättwil
Switzerland
www.actifsource.com
Trademark Actifsource is a registered trademark of Actifsource AG in Switzerland, the EU, USA, and China. other names appearing on the site may be trademarks of their respective owners.

Overview

  • Learn how to specify a simple state machine

  • Example

    • Button to turn on and off a lamp
    • Turning off the lamp shall be delayed
Info
  • CIP Method

    • The CIP System is the root element

    • The CIP System consists of Clusters

      • Clusters are used to model distributed state machines
    • The CIP Cluster consists of Processes

      • The process declares the state of the state machine
    • The CIP Process consists of Modes

      • Modes are used for different situations like normal, error, run-in, run-out
      • The mode declares the transitions between the states

Part I Setting up a new CIP Project

  • Create a new CIP Project with the CIP Project wizard

image2 image2

  • Prepare a new Actifsource/CIP Project using the Actifsource CIP wizard

    • File/new/other
    • Actifsource/CIP Project
  • Click Next

image3 image3

  • Specifiy Project name ch.actifsource.tutorial.cip.lamp
  • Specify Project type
  • Click Next

image4-1 image4-1

  • Deselect generate javamodel

image4-2 image4-2

  • You may add other build configs (i.e. test suites) as needed
  • Click Finish
Info

Note that the BuildConfigs in TargetFolder are equivalent to the previously selected project type


Part II Communicating with the Outer World

  • Let’s communicate with the outer world
  • Channels are providing messages from physical device

Communicating with the Outer World

image8 image8

  • Open the Communication Diagram (if not already open)

    • Double-Click on CommunicationDiagram in the Project Explorer of resource Lamp_CipSystem

image9 image9

  • Create two new Channels named Button and Lamp using the Channel tool from the Palette

image10 image10

  • Select the Button in the diagram with selected Properties tool from the palette

  • Arrange the Graphical Editor and the Properties View together on the same screen as shown above

  • Add the two ChannelMessages Push and Release to the Channel Button

    • Select process Button with selected Properties tool
    • Add ChannelMessage Push and ChannelMessage Release
  • Add the two ChannelMessages Bright and Dark to the Channel Lamp

    • Select process Lamp with selected Properties tool
    • Add ChannelMessage Bright and ChannelMessage Dark
  • Messages are given as function calls from the other world to the state machine and vice versa


image11 image11

Info

The CIP Method specifies that every physical process needs a logical counterpart in the model

  • Add the two Processes Button and Lamp to the Cluster LampCluster
Info

Note that different Clusters may run on different processors. This allows you to design distributed state machines using the CIP Method.

image12 image12

Info

Channels are Delivering Messages to a Process via Port. Doing so allows you to consider the Process to a self-consistent component.

  • Create an Inport ButtonPort and a relation from the Channel Button to the Port ButtonPort
  • Create an Outport LampPort and a relation from the Port LampPort to the Channel Lamp

image13 image13

Info

Since every Process is a self-consistent component we have to specify a Message interface on the port to. The = Tool in the Message Translation helps us to create the same messages as found on the Channel also on the corresponding Port.

  • Configure the Message Translation between the Channel Button and the Process Button

    • Double-Click on the hexagon of the relation between the Channel Button and the Process Button
    • Select the ChannelMessages Button.Push and Button.Release
    • Use the = Tool to create the corresponding Messages on the Port ButtonPort of the Process Button
  • Configure the Message Translation between the Process Lamp and the Channel Lamp

    • Double-Click on the hexagon of the relation between the the Process Lamp and the Channel Lamp
    • Select the ChannelMessages Lamp.Bright and Lamp.Dark
    • Use the = Tool to create the corresponding Messages on the Port LampPort of the Process Lamp

Part III Specify the State Machine

  • We are now set to specify the state machines for each process
Info
  • Note that the CIP Method knows so called Modes

    • A Process can have one or more Modes
    • States are declared by the Process
    • Transitions are declared by the Mode
  • Making this difference it becomes possible to provide several Modes for several situations

    • Normal Mode
    • Error Mode
    • Run-In Mode
    • Run-Out Mode
  • There are the following rules

    • States are defined in the Process
    • States are shared for every Mode
    • Transitions are defined in the Mode

Specify the State Machine

image14 image14

  • Navigate the Project Explorer of Lamp_CipSystem down up you see Button_normal
  • Double-Click on Button_normal. Actifsource will automatically open new StateDiagram

image15 image15

  • Enter two new States Released and Pushed using the Palette
Info

State are shared for every mode


image17 image17

  • Create a new Transition from State Released to State Pushed using the Relation Tool from the Palette
  • Create a new Transition from State Pushed to State Released using the Relation Tool from the Palette

image18 image18

Info
  • Every Transition needs an input to be triggered
  • Note that the Actifsource Validator marks all resources that are incomplete
  • Add the input message to Transition from State Released to State Pushed

    • Select Edit Tool from the Palette
    • Klick and Ctrl-Space on the italics label Input
    • Select the InportMessage Push
  • Add the input message to Transition from State Pushed to State Released

    • Select Edit Tool from the Palette
    • Klick and Ctrl-Space on the italics label Input
    • Select the InportMessage Release
Info

Note that you now selecting the Messages that we have previously created on the Port Button using the = Tool in the Message Translation


image19 image19

Info
  • Use Messages to communicate with Processes from the outer world
  • Use Pulses to communicate between Processes within the same Cluster
  • Add the Outpulse On to Transition from State Released to State Pushed

    • Select Edit Tool from the Palette

    • Klick on the italics label Outpulse

    • Enter the desired Outpulse named On and press Ctrl-Space

      • Select an existing Outpulse or
      • Create a new Outpulse (as we do in our example)
  • Add the Outpulse Off to Transition from State Pushed to State Released

image20 image20

  • Set the Init-State to specify the State to start with

    • Right-Click on State Released
    • Shape Actions Set Init-State

image21 image21

Info
  • Use Pulses to communicate between Processes within the same Cluster
  • The PulseCastDiagram specifies which Processes sends Pulses to which other Processes
  • Navigate the Project Explorer of Lamp_CipSystem down up you see CommunicationDiagram
  • Double click on CommunicationDiagram.

image22 image22

image22-1 image22-1

  • Connect the Process Button and the Process Lamp using the Relation Tool from the Palette

image22-2 image22-2

  • Configure the Pulse Cast between the Process Button and the Process Lamp

    • Double-Click on the circle of the relation between the Process Button and the Process Lamp
    • Select the Outpulses Button.On and Button.Off
    • Use the = Tool to create the corresponding Inpulses on the Process Lamp

image23 image23

  • Double-Click on Process Lamp to open the StateDiagram

image24 image24

  • Open the StateDiagram for Process Lamp (if not already done)

    • Navigate the Project Explorer of Lamp_CipSystem down up you see Lamp.normal.Lamp_normal
    • Double-Click on Lamp_normal to open the StateDiagram
  • Create States Dark Bright and Delayed

  • Make State Dark the Init-State

  • Create Transition as shown above

    • Select Pulses which have been created in the Pulse Translation (On and Off)
    • TIMEUP is a special pulses emitted if timer expires
    • Select Lamp Messages (Bright and Dark) to the outer world

image25 image25

  • Start Timer in Transition #2

    • Select Transition 2 in the diagram with selected Properties tool from the palette
    • Create a new extensionAction SetTimer_DelayText

image26 image26

  • Define the delay 3 ticks
Info

The DelayText shall return the delay in system ticks

  • Stop Timer in Transition #3 (Optional)

    • Select Transition 3 in the diagram with selected Properties tool from the palette
    • Create a new extensionAction StopTimer

Part IV Generating State Machine Code

  • We have to define the details for the state machine implementation to generate the code

Generating State Machine Code

image27 image27

  • Double-Click on Lamp_CipSystem in the Project Explorer
  • Create a new Implementation LampImplementation

image28 image28

  • Create a new unit LampUnit as shown above

image29 image29

  • Find the generated code in the folder cip-gen

actifsource-point-large