Skip to content

Parent - Child Relation

Prerequisites - Tutorial: First Steps
Goal - Application extended by another instance of CYL and a MAIN controller
Topics covered - Parent - Child relation
- Parent - Child commands

Create Parent Controller

Create new level

image2017-6-27%2014%2049%203

  • Create another level: level1

image2017-6-27%2014%2050%2042

  • Create a relation between the two levels to define the hierarchy

Create MAIN (parent) controller

image2017-6-27%2014%2053%2057

  • Create a new controllerInstance in level1 and change the ID to 1 (you will get an inconsistency message: ID is not unique)

Best practice

The top controller should have ID 1. This makes it easier to get into the tree (e.g. via service visualisation)


image2017-6-27%2014%2058%2041

  • Change ID of CYL instance to 2

image2017-6-27%2015%200%2040

  • Define a new Controller type in the ControllerInstance

image2017-6-27%2015%203%209

  • Enter name: MAIN
  • Create a new ControllerInterface named: IF_MAIN

image2017-6-27%2015%2019%2044

  • Move MAIN controller into the controller package

Define Parent-Child relation

image2017-6-27%2015%2025%2032

  • Draw relation between MAIN and CYL controller instance
  • In the ChildRef Dialog create a new Child resource
  • Enter name for Child resource: cyl01

image2017-6-27%2015%2027%2043

  • The MAIN controller instance now has a reference to a child controller

image2017-6-27%2016%205%201

  • Define the interface that the child controller has to implement.

MAIN statemachine

image2017-6-27%2015%2053%2017

  • Model the MAIN state machine as shown above.
  • The RUN state is a standard SuperState, the OPEN and CLOSE states can be drawn inside

image2017-6-27%2015%2058%2018

  • Add the existing command OFF and a new command RUN to the IF_MAIN ControllerInterface

image2017-6-27%2016%200%2043

  • Add CommandRef guard to relation from OFF to RUN

image2017-6-27%2016%202%2017

  • Add CommandRef guard to relation from RUN to OFF

Commanding the child controller

image2017-6-27%2016%207%2056

  • In the OPEN_busy state set the POS1 command to the cyl01 child controller

image2017-6-27%2016%2010%204

  • In the guard from OPEN_busy to OPEN, check the child state with the ChildStateRef

Best practice

This shows the advantage if the state and the corresponding command have the same name.


image2017-6-27%2016%2017%2025

  • The same in the close state.

image2017-6-27%2016%2019%2019

  • The OFF command will be sent to the Child controller in the OFF state.

image2017-6-27%2016%2022%2032

  • Check whether all (also future) child controllers are in OFF state.

Best practice

If possible, use the 'globalChildState' option. Thus, future controllers are also checked for the desired state.


Add parameter to define waiting time

image2017-6-27%2016%2044%2015

  • Add a parameter 'idleTime' with type UINT

image2017-6-27%2016%2046%2022

  • Open the MAIN IFS object (in the MAIN controller)
  • Set 2000 as default value as idleTime

Use model function to get statemachine information

image2017-6-27%2017%2050%2034

  • Wait in target state until the idle time has elapsed.

thisGetSmTimeInState() returns the elapsed time in the current state


Adjust configuration

image2017-6-27%2016%2030%2024

  • Add the MAIN_01 controller instance also to the taskGroup1

Congratulation, you have finished the tutorial!