I want to know if it's possible to time how long the system has been in a specific state? And when it leaves the state, the "stopwatch" stops and then carries on when the state is once again entered?
If so, how?
I want to know if it's possible to time how long the system has been in a specific state? And when it leaves the state, the "stopwatch" stops and then carries on when the state is once again entered?
If so, how?
"Continous" measurement (not recommended)
A live counter can be implemented with the help of a cyclic transition inside the state of which you want to measure the time. This transition records cyclicly a discrete amount of time spent in this state:
However this is not really a good solution because:
Discrete Measurement
If you do not need to see it live counting, it would be a better idea to use the code fields when the state is entered or left, save a timestamp and just add the difference to your counter once everytime that you leave the state. Both variables are of type double.
Keep in mind however, that (as Benjamin already pointed out in his comment), the value is only up to date when the state is not currently active.