Topic
  • 2 replies
  • Latest Post - ‏2009-10-15T13:43:40Z by SystemAdmin
SystemAdmin
SystemAdmin
147 Posts

Pinned topic How to get the value of "now" in the statemachine and compare it with Int?

‏2009-10-13T23:09:44Z |
At some switch or selection in state machine, I want to get the value of "now" (current time) in the statemachine and compare it with other Integer variable in the statemachine? But the "now<Int" is not permitted.
How to realize?
Updated on 2009-10-15T13:43:40Z at 2009-10-15T13:43:40Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    147 Posts

    Re: How to get the value of "now" in the statemachine and compare it with Int?

    ‏2009-10-15T08:00:45Z  
    Why are you using an Integer? Tau provides a Time type , and Time is the type of now. There is also a Duration type. Neither has automatic conversion from integer or real attributes, although numeric values are automatically converted to Time and Duration as needed by the expression.

    Assuming that what you are trying to do is see if a certain amount of time has passed since some reference time, here is one way of doing this: at the reference time assign now into an attribute of type Time and, when checking, compare with other values of type Time. Here are some steps to do this:

    1. In the statemachine, declare an attribute of type Time:
    Time tref;

    2. At the reference time:
    tref = now;

    3. later in the statemachine:
    if ( now>tref+5 ) {
    ...
    }

    Another approach is to use a timer: start the timer at the reference time, and use the active() expression to test if it has expired. Steps to do this:

    1. Add a timer to the active class definition, for example in the model view by right-click->New Model Element->Timer, give it a meaningful name, then in the property editor give it a default value, e.g. 5, which is the duration the timer will run for.

    2. At the reference time start the timer (will run for the default duration in the definition):
    set(t1);

    3. To test the timer:
    if ( active( t1() ) ) {
    ...
    }

    HTH
    Ian
  • SystemAdmin
    SystemAdmin
    147 Posts

    Re: How to get the value of "now" in the statemachine and compare it with Int?

    ‏2009-10-15T13:43:40Z  
    I see, Thanks a lot.