[Qt-interest] unable to use more than 1 transition added to a state (QT StateMachine Framework)
Mandeep Sandhu
mandeepsandhu.chd at gmail.com
Thu Mar 18 12:35:59 CET 2010
Thanks for the test program Sean.
But unfortunately, this won't work for me. What I had shown in my SM
was just a sample. The real SM has _many_ more states and transitions.
Eg, there's an ERROR transition that can occur from ~ 14 different
states, which means I'd have to add those many transition for this
event alone (and there are around ~11-12 such events).
The Qt SM framework is based on the hierarchical SM as shown here:
http://www.wisdom.weizmann.ac.il/~dharel/SCANNED.PAPERS/Statecharts.pdf
(Harrel's statecharts)
I need to make use of state groups (parallel/normal) to implement the
SM with less number of transitions...as adding so many would be
cumbersome and possibly error prone.
One of the soln's that I had thought for the second SM (with s3), was:
- put s0,s2 in sg1 and add a transition for e1 with target as s1. from
s1 add transition to s2
- put sg1, s1 in another group sg2. add transition for e3 to goto s3.
- set initial state of sg2 as sg1 and initial state of sg1 as s0
Now this has a problem that we can transition from s0 to s3 on e3
(which is not valid according to the state dia).
So I put a "dummy" transition on s0 (for e3) with target state as s0
itself. So when in s0, and we get e3, the SM stays in s0.
I can extend this idea to my SM except that this would require quite a
lot of dummy transitions. I'm not convinced that this is the only way.
Anybody has suggestion?
Thanks,
-mandeep
On Thu, Mar 18, 2010 at 4:26 PM, Sean Harmer
<sean.harmer at maps-technology.com> wrote:
> Hi,
>
> On Thursday 18 March 2010 10:16:15 Mandeep Sandhu wrote:
>> On Thu, Mar 18, 2010 at 3:07 PM, Sean Harmer
>>
>> <sean.harmer at maps-technology.com> wrote:
>> > Hi,
>> >
>> > On Wednesday 17 March 2010 08:56:01 Mandeep Sandhu wrote:
>> >> On further debugging this problem I found that the issue is because of
>> >> attaching the same transition to more than 1 state.
>> >>
>> >> Can't a transition be attached to more than 1 state?
>> >>
>> >> Eg. If i define my transition as "On event E1, move to State S1"
>> >>
>> >> I attach this transition to S3 and S6...now if an event E1 occurs
>> >> while the state machine is in S3 or S6, it should transition to S1.
>> >> Correct?
>> >>
>> >> Or is this a bug in the state machine framework?
>> >
>> > This is not a bug in the SM framework. You need to use multiple instances
>> > of your specialised guarded transition class. The reason is because each
>> > instance
>>
>> Having multiple instances of my transition for the _same_ event would
>> again violate the principle of Hierarchical SM's.
>>
>> I'll illustrate my SM which needed the same transition to be attached
>> to 2 states:
>>
>> s0-(e1)->s1-(e2)->s2
>> ^ |
>>
>> |__(e1)__|
>>
>> (this dia looks proper with fixed width font!:))
>>
>> So, on event e1 the SM transitions to s1, whether its in s0 or s2.
>>
>> To avoid 2 e1 transitions, I can club s0 and s2 in a super-group (sg1)
>> and apply a single transition for e1 to this super-group. This would
>> be within the principle of HSM's (there'll also be a transition from
>> s1 to s2 on e2).
>>
>> Now, I add another state/transitions to the same SM as below:
>>
>> s1-(e3)->s3 and s2-(e3)->s3
>>
>> This (if seen alone) would require another super-group (sg2) which has
>> s1 and s2 and 1 transition for e3 attached to sg2.
>>
>> But how do I combine sg1 & 2. Basically s2 exists in both these
>> groups...While reading Harrel's statecharts its mentioned that
>> sometimes for overlapping states duplication might be needed.
>>
>> Any ideas on how this canbe resolved the proper HSM way?
>
> Yes, there is no need to introduce grouping states in this case from what you
> have explained. With my poor ascii-art skills I have created the following
> state chart (fixed width font required):
>
> s3<-------
> ^ |
> | e3 | e3
> | |
> s0-------->s1------->s2
> e1 ^ e2 |
> | |
> `---------'
> e1
>
> which combines all the information that you gave. This is very easily created
> with a guarded transition class instantiated a number of times like so:
>
> // Define some custom event offsets
> int e1 = 1024;
> int e2 = 1025;
> int e3 = 1026;
>
> // Create states
> QState* s0 = new QState( machine );
> QState* s1 = new QState( machine );
> QState* s2 = new QState( machine );
> QState* s3 = new QState( machine );
>
> // Create transitions
> CustomEventTransition* s0Tos1 = new CustomEventTransition( QEvent::Type(
> QEvent::User + e1 ), s0 );
> s0Tos1->setTargetState( s1 );
>
> CustomEventTransition* s1Tos2 = new CustomEventTransition( QEvent::Type(
> QEvent::User + e2 ), s1 );
> s1Tos2->setTargetState( s2 );
>
> CustomEventTransition* s2Tos1 = new CustomEventTransition( QEvent::Type(
> QEvent::User + e1 ), s2 );
> s1Tos2->setTargetState( s1 );
>
> CustomEventTransition* s1Tos3 = new CustomEventTransition( QEvent::Type(
> QEvent::User + e3 ), s1 );
> s1Tos3->setTargetState( s3 );
>
> CustomEventTransition* s2Tos3 = new CustomEventTransition( QEvent::Type(
> QEvent::User + e3 ), s2 );
> s1Tos3->setTargetState( s3 );
>
> // Add transitions to states
> s0->addTransition( s0Tos1 );
> s1->addTransition( s1Tos2 );
> s1->addTransition( s1Tos3 );
> s2->addTransition( s2Tos1 );
> s2->addTransition( s2Tos3 );
>
> The attached tarball includes the CustomEventTransition class and the above
> example - it even compiles ;-). That should get you started. You just need to
> add in the code that posts your e1, e2, e3 events to the state machine.
>
> Good luck,
>
> Sean
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
More information about the Qt-interest-old
mailing list