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
- Create another level: level1
- Create a relation between the two levels to define the hierarchy
Create MAIN (parent) controller
- 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)
- Change ID of CYL instance to 2
- Define a new Controller type in the ControllerInstance
- Enter name: MAIN
- Create a new ControllerInterface named: IF_MAIN
- Move MAIN controller into the controller package
Define Parent-Child relation
- Draw relation between MAIN and CYL controller instance
- In the ChildRef Dialog create a new Child resource
- Enter name for Child resource: cyl01
- The MAIN controller instance now has a reference to a child controller
- Define the interface that the child controller has to implement.
MAIN statemachine
- Model the MAIN state machine as shown above.
- The RUN state is a standard SuperState, the OPEN and CLOSE states can be drawn inside
- Add the existing command OFF and a new command RUN to the IF_MAIN ControllerInterface
- Add CommandRef guard to relation from OFF to RUN
- Add CommandRef guard to relation from RUN to OFF
Commanding the child controller
- In the OPEN_busy state set the POS1 command to the cyl01 child controller
- 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.
- The same in the close state.
- The OFF command will be sent to the Child controller in the OFF state.
- 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
- Add a parameter 'idleTime' with type UINT
- Open the MAIN IFS object (in the MAIN controller)
- Set 2000 as default value as idleTime
Use model function to get statemachine information
- Wait in target state until the idle time has elapsed.
thisGetSmTimeInState()
returns the elapsed time in the current state
Adjust configuration
- Add the MAIN_01 controller instance also to the taskGroup1
Congratulation, you have finished the tutorial!