CIP Tool

CIP State Machine - Lamp Legacy

Design a simple state machine that allows you to switch on a lamp, while switching it off is delayed. This tutorial is intended for users of the old CIP application. more…

CIP State Machine - Lamp

Design a simple state machine where you can switch on a lamp while switching off will be delayed. more…

CIP State Machine - Test Suite - Console

Learn how to specify a CIP Test Suite model and how to run unit tests on your CIP state machine. more…

CIP State Machine - Arduino

Learn how to download and run the generated C code from your CIP machine on the Arduino platform. more…

Subsections of CIP Tool

CIP Statemachine - Lamp

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
  • 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
  • Specify Project type
  • Click Next

image4 image4

  • 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

image5 image5

  • Link with Editor
  • Enable Actifsource Presentation Flag Group Aggregations By Relations

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 Tree View of resource Lamp_CipSystem
    • A new Communication Diagram editor will open on the left

image9 image9

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

image10 image10

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

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

    • Ctrl+Click on the Button label
    • Add ChannelMessage Push and ChannelMessage Release
  • Add the two ChannelMessages Bright and Dark to the Channel Lamp

    • Ctrl+Click on the Lamp label
    • 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

  • 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

  • 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

  • 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

  • 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 Resource View 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
  • State are shared for every mode
  • Enter the desired State name Released and Pushed

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

  • Every Transition needs an input to be triggered
Info

Note that the Actifsource Validator marks all resources that are incomplete

  • Add the input message to Transition from State Released to State Pushed

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

    • Ctrl-Klick 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

  • 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

    • Ctrl-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

    • Open the LampCluster in the Resourceeditor
    • Set the initstate to Released State

image21 image21

  • Use Pulses to communicate between Processes within the same Cluster
  • The PulseCastDiagram specifies which Processes sends Pulses to which other Processes
  • Navigate the Resource View of Lamp_CipSystem down up you see PulseCastDiagram
  • Double click on PulseCastDiagram. Actifsource will automatically open new PulseCastDiagram

image22 image22

  • Add the Process Button and the Process Lamp to your PulseCastDiagram

    • Right-Click on the Diagram
    • Show Resource
    • Select Button and Lamp
  • Connect the Process Button and the Process Lamp using the Relation Tool from the Palette

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

    • Double-Click on the circle of the relation between the 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 ProcessLamp (if not already done)

    • On the System View Right-Click on System1.Lamp.Button.normal
    • Select StateDiagram
    • Select StateDiagram_1
  • 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
    • TIMEUP is a special pulses emitted if timer expires
    • Select Lamp Messages to the outer world

image25 image25

  • Start Timer in Transition #2

    • Ctrl-Click in label Ext
    • Select SET_TIMER
    • Specify DelayOperation (see next page)
  • Stop Timer in Transition #4

    • Ctrl-Click in label Ext
    • Select STOP_TIMER

- Specify the State Machine

image26 image26

  • Create a SetTimer_DelayText
  • The DelayText shall return the delay in system ticks

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

  • Create a new Implementation for System System1
  • On the System View Right-Click on System1
  • Create a new Implementation

image28 image28

  • Create a new Implementation as shown above

image29 image29

  • Find the generated code in the folder cip-gen
  • Find the documentation (html) code in the folder cip-gen

actifsource-point-large

CIP Statemachine - Lamp Legacy

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
  • 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
  • Specify Project type
  • Click Next

image4 image4

  • 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

image5 image5

  • Link with Editor
  • Enable Actifsource Presentation Flag Group Aggregations By Relations

image6 image6

  • Open CIP System View

    • Window/Show View/Other…
    • Actifsource – CIP / System

image7 image7

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)

    • Right Click on System1 in the System View
    • Select CommunicationDiagram from the context menu
    • Open CommunicationDiagram_1

image9 image9

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

image10 image10

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

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

    • Ctrl+Click on the Button label
    • Add ChannelMessage Push and ChannelMessage Release
  • Add the two ChannelMessages Bright and Dark to the Channel Lamp

    • Ctrl+Click on the Lamp label
    • 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

  • 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

  • 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

  • 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

  • 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

  • Open the StateDiagram for Process Button

    • On the System View Right-Click on System1.Lamp.Button.normal
    • Select StateDiagram
    • Select StateDiagram_1

image15 image15

  • Enter two new States Released and Pushed using the Palette
  • State are shared for every mode
  • Enter the desired State name Released and Pushed

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

  • Every Transition needs an input to be triggered
Info

Note that the Actifsource Validator marks all resources that are incomplete

  • Add the input message to Transition from State Released to State Pushed

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

    • Ctrl-Klick 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

  • 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

    • Ctrl-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

    • Open the LampCluster in the Resourceeditor
    • Set the initstate to Released State

image21 image21

  • Use Pulses to communicate between Processes within the same Cluster

  • The PulseCastDiagram specifies which Processes sends Pulses to which other Processes

  • Open the PulseCastDiagram for Cluster Lamp

    • On the System View Right-Click on System1.LampCluster
    • Select PulseCastDiagram
    • Select PulseCastDiagram_1 (or create a new one if necessary)

image22 image22

  • Add the Process Button and the Process Lamp to your PulseCastDiagram

    • Right-Click on the Diagram
    • Show Resource
    • Select Button and Lamp
  • Connect the Process Button and the Process Lamp using the Relation Tool from the Palette

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

    • Double-Click on the circle of the relation between the 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 ProcessLamp (if not already done)

    • On the System View Right-Click on System1.Lamp.Button.normal
    • Select StateDiagram
    • Select StateDiagram_1
  • 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
    • TIMEUP is a special pulses emitted if timer expires
    • Select Lamp Messages to the outer world

image25 image25

  • Start Timer in Transition #2

    • Ctrl-Click in label Ext
    • Select SET_TIMER
    • Specify DelayOperation (see next page)
  • Stop Timer in Transition #4

    • Ctrl-Click in label Ext
    • Select STOP_TIMER

- Specify the State Machine

image26 image26

  • Create a SetTimer_DelayText
  • The DelayText shall return the delay in system ticks

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

  • Create a new Implementation for System System1
  • On the System View Right-Click on System1
  • Create a new Implementation

image28 image28

  • Create a new Implementation as shown above

image29 image29

  • Find the generated code in the folder cip-gen
  • Find the documentation (html) code in the folder cip-gen

actifsource-point-large

CIP Test Suite - Console

logo-large

Tutorial Actifsource Tutorial – CIP Test Suite - Console
Required Time - 30 Minutes
Prerequisites - Actifsource Tutorial – Actifsource Tutorial – [Installing Actifsource]../../..(/tutorials/\10_community/10_install/index.html)
-Actifsource Tutorial – Simple Service
- Actifsource Tutorial – CIP Statemachine - Lamp
Goal - Creating Unit Tests for a CIP Statemachine
Topics covered - Setting up the code options
- Setting up a CIP Test Suite
- Generate the CIP Test Suite
- Generate the CIP Test Suite Documentation
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 CIPTestSuite model

    • Specify message events (input)
    • Specify message action expectations (output)
  • Run the unit tests

Part I Setting up the CIP project

  • Make sure to properly setup the lamp project as seen in the previous tutorial

image2 image2

  • Create a new CIP Project using the wizard
  • Select CIP_C_Statemachine to generate a CIP state maschine
  • Select CIP_C_TestSuite_Console to generate a console test suite
  • Select CIP_HTML_TestSuite_Documentation to generate a html documentation
  • Click Next >

image3 image3

  • The necessary build configs are automatically added to your target folder
  • Click Finish

image4 image4

  • Create the Lamp state machine as shown in the previous tutorial

image5 image5

image6 image6

  • Set the timer delay to 3 ticks

image7 image7

  • Create a new Implementation in your CIPSystem
  • Select the LampCluster in your CipMachine
  • Select input and output channels
  • Select Default_C_CodeOptions

image8 image8

  • Install the CDT (C/C++ development tool)
  • Convert your project to a C/C++ Project

image9 image9

  • Convert to C Project
  • Create an Executable
  • Click Finish

image10 image10

  • To automatically compile choose Build on resource save in the project properties

image11 image11

  • Rearrange the CDT Builder to the last position to make sure that the actifsource generator runs before compiling

Part II Setting up a CIP Test Suite

  • Create a new Resource of type CipTestSuite
  • Specify your test cases

image12 image12

  • Create a new Resource of type CipTestSuite
  • Reference you CIP system and the implementation unit which shall be tested

image13 image13

  • Create a new TestCase called LampOnOff
  • Make sure to properly comment all resources via the comment attribute.

image14 image14

  • Define the first test event of type MessageEvent

  • First define the event message which is sent to the CIP machine

  • Let’s switch on the light by pressing the button

    • Select event message Button.Push
    • Define the expected action message Lamp.Bright

image15 image15

  • Define the second test event of type MessageEvent

  • First define the event message which is sent to the CIP machine

  • Let’s activate the switch off delay by pressing the button

    • Select event message Button.Release
  • Since switching off is delayed, we do not expect the light to be switched off

image16 image16

  • Define the third test event of type TickEvent

  • Define the number of ticks to time up the delay

    • 3 ticks in this example
    • Define the expected action message Lamp.Dark
  • The light is expected to be switched off after 3 ticks

Part III Running the CIP Test Suite

  • In the second part we want to generate an executable which can run the previously defined test cases
  • Make sure to install the CDT (C/C++ Development Tool) and mingw or gcc for C language support

image17 image17

  • Your lamp system should have been generated by now
  • Select your executable and run configuration

image18 image18

  • Select the command line options

    • Select regressive to automatically run test cases
    • Select manual to manually stimulate the event

image19 image19

  • Run the Local C/C++ Application

image20 image20

  • The test out can be found in the console
Info

Note that you can directly link back from the console output in the corresponding model by clicking on the blue GUID links

image21 image21

  • Delete the expectation Lamp.Bright in your first test event and run the test again
  • Link back to the model by clicking the GUID link next to the assertion failure
  • Correct your test model

Part IV Generate the CIP Test Suite Documentation

  • Last but not least we want to generate the test suite documentation
  • The documentation can be used for communication and to ensure quality
  • Make sure to define a new test case any time a problem in your state machine hast been corrected

image22 image22

  • The documentation is generated because of the BuildConfig CIP_HTML_TestSuite_Documentation
  • A file Test_CipSystem_TestSuite_Documentation.html is generated in your target folder

image23 image23

  • Use the generated documentation to ensure quality and communicate with your team mates.

image24 image24

  • Click on messages in the test cases to link back to the system information

actifsource-point-large

CIP Statemachine - Arduino

logo-large

Tutorial Actifsource Tutorial – CIP Statemachine - Arduino
Required Time - 120 Minutes
Prerequisites - Actifsource Tutorial – Installing Actifsource
- Actifsource Tutorial – Simple Service
- Actifsource Tutorial – CIP Statemachine - Lamp
Goal - Compiling and running the CIP Statemachine on the Arduino UNO
Topics covered - Arduino SDK
- Simple Arduino project
- CIP Arduino project
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

  • Arduino SDK

    • The Arduino SDK contains all the necessary source code for your Arduino
    • Installing the com port driver for your Arduino
  • AVR Eclipse Plugin

    • The AVR Plugin is an extension to the C/C++ Development Toolkit to support development for the Atmel AVR series of embedded processors.
    • Configure the AVR Plugin for your Arduino board
  • Simple Arduino project

    • Setup a new C/C++ project
    • Write a very simple code which switches an LED on and off
    • Compile the project including the Arduino core
    • Download to the Arduino target and run
  • CIP Arduino project

    • Modeling a reactive state machine using the CIP method
    • Generating C code for the state machine
    • Connecting the generated state machine code to the Arduino I/O
    • Downloading and testing to the Arduino board

Part I Installing Eclipse & Arduino

  • Install the Eclipse IDE for C/C++ Developers (C/C++ Development Tool) www.eclipse.org/downloads
  • Install the Actifsource Enterprise plugin
  • The Arduino SDK contains all the necessary source code for your Arduino
  • Installing the com port driver for your Arduino

Arduino Software Setup

image2 image2

  • Download your Arduino SDK from www.arduino.cc

  • Unzip the Arduino SDK on your hard disk

    • We use C:\arduino-1.0.3\ in this example

image3 image3

  • Plugin your Arduino to a USB port

    • The installation will fail
  • Open the Device Manager from the Control Panel

  • Find the failed device

  • Install new driver

  • Search the driver on your computer

  • Specify C:\arduino-1.0.3\drivers as the place to look for the driver

    • Warning: You must not select C:\arduino-1.0.3\drivers\FTDI USB Drivers

image4 image4

  • Check if the driver has been installed correctly

  • Important: Remember the com port

    • COM3 in this example

image5 image5

  • Open the boards.txt file in C:\arduino-1.0.3\hardware\arduino

  • Print the information for your hardware platform

    • Arduino Uno in this example
  • For Linux you can simply install gcc-avr avr-libc avrdude:

sudo apt-get install gcc-avr avr-libc avrdude

AVR Eclipse Plugin

  • The AVR Plugin (for this tutorial version 2.4.1 will be used)for Eclipse is an extension to the C/C++ Development Toolkit to support development for the Atmel AVR series of embedded processors.
  • Configure the AVR Plugin for your Arduino board

image6 image6

  • Start your Eclipse with a new workspace

    • workspace_arduino in this example
  • In your Eclipse, click Help/Install new Software…

  • Add the AVR-Eclipse plugin update site avr-eclipse.sourceforge.net

  • Installing the plugin requires eclipse to restart

image7 image7

  • Configure the AVR Eclipse Plugin under Windows/Preferences/AVR/Paths
  • Set AVR-GCC to custom value C:\arduino-1.0.3\hardware\tools\avr\bin or /usr/bin
  • Set GNU make to custom value C:\arduino-1.0.3\hardware\tools\avr\utils\\bin or /usr/bin
  • Set SVR-GCC to custom value C:\arduino-1.0.3\hardware\tools\avr\avr\\include or /usr/lib/avr/include
  • Set SVR-GCC to custom value C:\arduino-1.0.3\hardware\tools\avr\bin or /usr/bin
  • Important: Press Apply

Part II Simple Arduino project

  • Setup a new C/C++ project
  • Write a very simple code which switches an LED on and off
  • Compile the project including the Arduino core
  • Download to the Arduino target and run

Simple Arduino project

image11 image11

  • Create a new C++ Project

  • You have to create a C++ project even if you plan to write C code since we have to compile the Arduino Core

  • If you can’t create a C/C++ Project you have probably not downloaded the Eclipse for C/C++ Developers

image12 image12

  • Create a new C++ project named ch.actifsource.tutorial.cip.arduino
  • Choose AVR Cross Target Application
  • Choose the AVR-GCC Toolchain
  • Click Next

image13 image13

  • Do not create a Debug Version

  • The debug code is too large to fit on the Arduino Uno

  • See boards.txt for the maximum code size

    • uno.upload.maximum_size=32256 for this example
  • Click Fish

  • Open the C/C++ Perspective if you are asked or open it manually in the upper right corner image15 image15

Arduino Build Variables Arduino Build Variables

  • For the newly created ch.actifsource.tutorial.cip.arduino, choose Properties (Mouse-Click-Right on the project)
  • Select C/C++ Build
  • In the Build Variables Tab, enter the following variables:
    • AVRDUDEOPTIONS, set to -p atmega328p -c arduino -P/dev/ttyUSB0 -b 115200
    • AVRTARGETFCPU, set to 16000000
    • AVRTARGETMCU, set to atmega328p
  • Click Apply

Arduino Environment Variables Arduino Environment Variables

  • In the Environment Tab, enter the following variables:
    • AVRTARGETFCPU, set to 16000000
    • AVRTARGETMCU, set to atmega328p
  • Click Apply

Ardunio Settings Ardunio Settings

  • In the Settings Tab, set AVRDude to true. This will automatically download the program to the attached board
  • Click Apply

image18 image18

  • This step is only needed on Windows

  • SimpleProject/Properties/C/C++Build/Settings/AVR Compiler/Directories

  • Set Include Path C:\arduino-1.0.3\hardware\tools\avr\avr\include

  • Set Include Path C:\arduino-1.0.3\hardware\arduino\cores\arduino

  • Set Include Path C:\arduino-1.0.3\hardware\arduino\variants\standard

    • See boards.txt (uno.build.variant) for your variant (standard for this example)
  • Click OK

image19 image19

  • Do the same again for SimpleProject/Properties/C/C++Build/Settings/AVR C++ Compiler/Directories

  • Set Include Path C:\arduino-1.0.3\hardware\tools\avr\avr\include

  • Set Include Path C:\arduino-1.0.3\hardware\arduino\cores\arduino

  • Set Include Path C:\arduino-1.0.3\hardware\arduino\variants\standard

    • See boards.txt (uno.build.variant) for your variant (standard for this example)
  • Click OK

image20 image20

  • Create a new folder src in the project

image23 image23

  • Create a new file main.c in the folder src
#include <avr/io.h>
#include <util/delay.h>

#define DELAYTIME 500  // 500ms Verzögerung

int main(void)
{
  DDRB |= _BV(DDB5); // Setze Pin PB5 (Arduino LED) als Ausgang

  while (1) {
    PORTB |= _BV(PORTB5);  // LED einschalten
    _delay_ms(DELAYTIME);  // Wartezeit

    PORTB &= ~_BV(PORTB5); // LED ausschalten
    _delay_ms(DELAYTIME);  // Wartezeit
  }

  return 0; // Dieser Punkt wird nie erreicht
}
  • Write a very simple Arduino program in the file main.c as shown above
  • If you enabled Build on resource save (Auto build) in Project/Properties/C/C++Build/Behaviour before, the code should now be built
  • You can also build manually by pressing Project/Build All (Ctrl+B ) or the build button in the Eclipse toolbar image24 image24
Info

Your code is probably not linking if you named your file main.cpp instead if main.c

image25 image25

  • Download your code to the Arduino

image27 image27

  • Mount your LED between Pin 13 and GND

    • Don’t forget the 330Ω resistor for a 1.7V LED with 10mA 🡪 (5V-1.7V)/0.01A = 330Ω
  • The program starts automatically after the download has been completed

    • The LED should switch on and off once per second

Part III CIP Arduino project

  • Modeling a reactive state machine using the CIP method
  • Generating C code for the state machine
  • Connecting the generated state machine code to the Arduino I/O
  • Downloading and testing to the Arduino board

CIP Arduino project

image28 image28

  • Switch to the Actifsource Perspective image29 image29
  • Select your project ch.actifsource.tutorial.cip.arduino in the Project Explorer
  • Select Configure/Add Actifsource Nature

image30 image30

  • Open Properties/actifsource/Resource Paths
  • Add the Resource Path asrc
  • Press Apply

image31 image31

  • Open Properties/actifsource/Built-in Dependencies
  • Add Builtin CIP
  • Add Builtin DATATYPE
  • Important: Press Apply

image32 image32

  • Open Properties/actifsource/Target Folders
  • Add the existing folder src as target folder
  • Add the BuildConfig CIP_C to the target src
  • Press OK

image33 image33

  • Select the Resource Folder asrc in the Project Explorer
  • Select CipSystem from the New Resource Tool in the Eclipse toolbar

image34 image34

  • Enter ch.actifsource.tutorial.cip.arduino as Namespace
  • Enter LampSystem as Name
  • Press Finish

image35 image35

image36 image36

  • Create a new Implementation named LampSystemImplementation in your LampSystem
  • Create a new ImplementationUnit named LampSystemUnit in your LampSystemImplementation
  • Create a new CipMachine in your LampSystemUnit
  • Reference the Cluster LampCluster in your CipMachine
  • Create a new CipShell in your LampSystemUnit
  • Reference the input channel Button
  • Reference the output channel Lamp
  • Create a new C_CodeOption named LampSystem_CodeOption using Content Assist (Ctrl+Space)

image37 image37

  • Configure the newly created LampSystem_CodeOption
  • Set useInterface to useMessageInterface
  • Set usePostFix to InitPostFix
  • Set enable_PENDING_Information to true
  • The code for your CIP system is now generated in the target folder src
#include <avr/io.h>
#include <util/delay.h>
#include "sLampUnit.h"

#define LED_PIN     PB5   // LED connected to PB5 (Arduino Pin 13)
#define BUTTON_PIN  PB4   // Button connected to PB4 (Arduino Pin 12)

void AI_LampUnit_C2_Dark() {
  PORTB &= ~_BV(LED_PIN); // Turn LED OFF
}
void AI_LampUnit_C2_Bright() {
  PORTB |= _BV(LED_PIN);  // Turn LED ON
}
void iMSG_LampUnit() {
  OUT_LampUnit.C2_Dark = AI_LampUnit_C2_Dark;
  OUT_LampUnit.C2_Bright = AI_LampUnit_C2_Bright;
}

int main(void)
{
  if (!fINIT_LampUnit()) {return 1;} // init cip
  // Set LED_PIN as an output
  DDRB |= _BV(LED_PIN);

  // Set BUTTON_PIN as an input and enable internal pull-up resistor
  DDRB &= ~_BV(BUTTON_PIN);  // Configure as input
  PORTB |= _BV(BUTTON_PIN);  // Activate internal pull-up (idle state = HIGH)

  int oldbuttonState = 0;

  while (1) {
  int newButtonState = PINB & _BV(BUTTON_PIN); // read button pin
  TRG_LampUnit.TICK_();
  // ticking time
  if(oldbuttonState!=newButtonState && newButtonState==1) {
    IN_LampUnit.C1_Push();
  }
  if(oldbuttonState!=newButtonState && newButtonState==0) {
    IN_LampUnit.C1_Release();
  }

  oldbuttonState=newButtonState;

  while (TRG_LampUnit.PENDING_.ANY_) {
    TRG_LampUnit.STEP_();
  }
    delay_ms(4);
  }

  return 0; // Never reached
}
  • Rewrite your main.c as shown above
Info

Your code is probably not linking if you named your file main.cpp instead if main.c

image38 image38

  • Download your code to the Arduino

    • Select your project SimpleProject in the Project Explorer
    • Press the AVR download button in the Eclipse toolbar image26 image26

image39 image39

  • We built a lamp with a delayed off switch

    • Pin 2 on GND means Button is released
    • Pin 2 on 5V means Button is pressed
  • Start while Button is released

  • Press Button 🡪 Light should switch on

  • Release Button 🡪 Light should switch off with delay

    • Tune with the delay function of your timer and the delay_ms() call in the main.c

actifsource-point-large