Skip to main content

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.



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:
  1. 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.
  2. 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.
  3. 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
  4. 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.




Comments

  1. พอ SysML 1.3 release แล้ว MagicDraw จะมี upgrade profile ภายในปีนี้หรือเปล่าครับ

    ReplyDelete
    Replies
    1. MagicDraw 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

      Delete
    2. FYI, SysML v1.3 has been release since June 1, 2012.
      http://www.omg.org/spec/SysML/1.3/PDF

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Hi
    Can you please elaborate about why you have state machine diagram when he behavior of clock is modeled using activity diagram?

    ReplyDelete
    Replies
    1. Hi,

      Actually, 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.

      Delete
    2. Thank you for your answer..

      Let 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

      Delete
    3. This comment has been removed by the author.

      Delete
    4. Yes, you can do that as shown in the picture of the following link.

      https://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.

      Delete
    5. Thank you it was helpful..However still have some problems.

      Can I have a skype chat with you..
      I need to solve the problem ASAP..

      Thank you

      Delete
    6. Hi,
      I 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.

      Delete

Post a Comment

Popular posts from this blog

Decomposing Ports and Connectors with Association Blocks

This article was written when SysML v1.3 specification is in releasing process. If you are a big fan of SysML and keep in touch with SysML RTF, you may have seen some documents or books about SysML v1.3 such as [1] and [2]. One of many things that I am impressed in those books and documents, is the way they use SysML to describe nested ports and specify compatibility between connected ports using association blocks.  When two ports connected by a connector, they may have nested ports which themselves can be connected. An association block has been suggested for defining the internal structure of the connector. It could contain a set of connectors that define the connectors between nested ports of association ends. When a connector is typed by an association block, the interaction between roles at both ends of connector will be handled by the internal structure of the association block [1].  This approach give us not only the ability to decompose ports and connectors but also the a

A Common Misunderstanding in Using Connectors

I have been asked many times by customers, that why they cannot use a connector to connect between ports on the boundaries of blocks in SysML Block Definition Diagram (BDD). Is that a tool's problem? After I have answered this question many times, I think it would be helpful for SysML users if there is an article to answer such question. For easy to explain, please see Figure 1. My customers try to use a connector to connect port p1  of SubSystem1 to the port p2  of SubSystem2  but they cannot. So, they have asked me with above question. Figure 1 -- SysML Block Definition Diagram To answer it, we should start by asking ourselves that does it make sense if a connector can connect both ports together? What should be the meaning of that connection? especially when we have multiple instances of SubSystem1 and SubSystem2 . Should the ports p1 of all  SubSystem1  instances be connected to the ports p2 of all  SubSystem2  instances?  I don't think so. BDD is used to