Simple Clock Modeling with SysML
It has been a while since I posted my previous article on this blog, because I was busy in making MagicDraw SysML supports for the new OMG SysML v1.3 Specification [1]. Couple weeks ago, I was asked by a customer about how to model a clock which counts every second with SysML. I created the simple clock model for answering. I also posted it to the SysMLForum and found that some people are interested in my clock model. So, I wrote this article to explain about the clock model and show how to model the system operating by a time trigger.
Start from defining the clock with a SysML block. The clock block contains only a value property t. This value property represents time in second. Thus, a value type Second must be defined for typing the value property as in Figure 1.
Next, SysML State Machine will be created to describe the behavior of the clock block. Here, the clock state-machine was designed to have only one state run as shown in Figure 2. It has a transition to itself triggered by a time event trigger with when attribute is set to 1,000 millisecond. So, the run state will be triggered every second (1,000 millisecond).
At the entry and the exit of the run state, you can specify the Behavior which will be performed when the state is entered and exited respectively. In this model, count activity (Figure 3) has been specified to be invoked at the exit of run state.
The count activity composes of the following actions:
(You can get more information about these actions in UML v2.4.1 Superstructure Specification [2])
The count activity will be performed every second when run state is triggered. So, the value of value property t will increase by 1 every second.
The simulation tool can be used to ensure that the clock model can work correctly. Here, I uses Cameo Simulation Toolkit, which can simulate the UML Activity and State-Machine model according to the fUML and SCXML specifications, as shown in the following video.
You can see that, the value of value property t will be increased by 1 every second when the model was simulated with full animation speed.
I hope this model can help at least someone to gain more understanding in using SysML for modeling time dependence system ;)
References:
[1] "OMG Systems Modeling Language (OMG SysML™) version 1.3" [Electronic]
[2] "OMG Unified Modeling Language™ (OMG UML), Superstructure version 2.4.1" [Electronic]
Kritsana Uttamang, PhD.
Analyst Manager / SysML Domain Expert
No Magic Inc.
Start from defining the clock with a SysML block. The clock block contains only a value property t. This value property represents time in second. Thus, a value type Second must be defined for typing the value property as in Figure 1.
Figure 1 - SysML Block Definition Diagram of Clock Model
Next, SysML State Machine will be created to describe the behavior of the clock block. Here, the clock state-machine was designed to have only one state run as shown in Figure 2. It has a transition to itself triggered by a time event trigger with when attribute is set to 1,000 millisecond. So, the run state will be triggered every second (1,000 millisecond).
Figure 2 - SysML State-Machine Diagram of Clock Model
At the entry and the exit of the run state, you can specify the Behavior which will be performed when the state is entered and exited respectively. In this model, count activity (Figure 3) has been specified to be invoked at the exit of run state.
Figure 3 - SysML Activity Diagram of count activity
The count activity composes of the following actions:
- ReadSelf action, is the action that returns the object of the current context. In this model, the token that flows through the result pin is the object of clock.
- ReadStructuralFeature action, this action reads the value of the specified structural feature from the object (input) pin. Here, the specified structural feature is the value property t. So, the token that flows through the result pin of the action is the value of value property t.
- CallBehavior action, is the action that calls to the opaque behavior IncreaseTimeOneSecond, shown in Figure 1. This opaque behavior has two parameters, tin (input) and tout (return), where: tout = tin + 1
- AddStructuralFeatureValue action which is the action for setting the value to the specified structural feature of the object (object pin). In this model, the new value of value property t should replace the previous one. So, the attribute Is Replace All will be true.
(You can get more information about these actions in UML v2.4.1 Superstructure Specification [2])
The count activity will be performed every second when run state is triggered. So, the value of value property t will increase by 1 every second.
The simulation tool can be used to ensure that the clock model can work correctly. Here, I uses Cameo Simulation Toolkit, which can simulate the UML Activity and State-Machine model according to the fUML and SCXML specifications, as shown in the following video.
You can see that, the value of value property t will be increased by 1 every second when the model was simulated with full animation speed.
I hope this model can help at least someone to gain more understanding in using SysML for modeling time dependence system ;)
References:
[1] "OMG Systems Modeling Language (OMG SysML™) version 1.3" [Electronic]
[2] "OMG Unified Modeling Language™ (OMG UML), Superstructure version 2.4.1" [Electronic]
Kritsana Uttamang, PhD.
Analyst Manager / SysML Domain Expert
No Magic Inc.
พอ SysML 1.3 release แล้ว MagicDraw จะมี upgrade profile ภายในปีนี้หรือเปล่าครับ
ReplyDeleteMagicDraw SysML 17.0.2 has already supported OMG SysML v1.3 (The new SysML profile has already been included). You could get the trial from www.nomagic.com
DeleteFYI, SysML v1.3 has been release since June 1, 2012.
Deletehttp://www.omg.org/spec/SysML/1.3/PDF
This comment has been removed by the author.
ReplyDeleteHi
ReplyDeleteCan you please elaborate about why you have state machine diagram when he behavior of clock is modeled using activity diagram?
Hi,
DeleteActually, you can model the clock with only Activity diagrams if state of the clock is not required. For example, you can create a loop in Activity which contains AcceptTimeEvent action and a CallBehavior action calling "count" activity (asynchronous call).
But, let think about the advantage of using state-machine. For someone who want to control the clock such as to start, stop, pause and resume. With state-machine, you can do such easily by add more states and trigger signals. You can also see the current state of the clock during the execution in Cameo Simulation Toolkit. So, that's why I chose to model with the state-machine.
For other technical view point about difficulty and easily in modelling, the life time of the object is depends on its classifier behaviour. After the object is initialised, it will perform the behaviour specified as its classifier behaviour from the beginning to the end. Then, the object will be disposed after termination of its classifier behaviour. If you model the clock with activity and set it as a classifier behaviour of the clock, the clock object will be disposed immediately when the execution reach the last action in the flow of activity. So, you have to create a loop of activity to make sure that the object won't be disposed. In the other hand, with state-machine, the execution will be held on the state forever if there is no trigger to the final state.
The last reason of using State-Machine with Activity is, I used this post as an example for my clients, to show them how state-machine and activity works together :)
Best regards,
Kritsana U.
Thank you for your answer..
DeleteLet me ask if i can model the clock only with activity diagram as I just need an increment every second or minute.
I am new to sysML, so kindly help me with clock modeling.
Thanks
This comment has been removed by the author.
DeleteYes, you can do that as shown in the picture of the following link.
Deletehttps://dl.dropboxusercontent.com/u/11335796/clock_model_with_activity.png
hope that can help
BTW, I simplified the model by using script to increase value of t variable.
Cheers,
Kritsana U.
Thank you it was helpful..However still have some problems.
DeleteCan I have a skype chat with you..
I need to solve the problem ASAP..
Thank you
Hi,
DeleteI would link to help but, I am not suitable for a call today. Actually, I left No Magic two month ago and I am quite busy with the new company. Anyway, you ca send me an email with yours questions, problems and requirements about the system you want to model. I will reply your email as soon as I can. My personal email is kritsana.u@gmail.com
Best regards,
Kritsana U.
Great Blog Thank you. Keep Posting
ReplyDeleteHikvision Full HD & Night Vision Camera Kit