LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Fun with StateCharts

For the past couple of days I’ve been exploring the new StateChart Module Toolkit.  With a little bit of help I managed to work my way through the Getting Started Tutorial.  But still felt I was missing a few pieces.

Starting at this page: https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000x3UMCAY&l=en-US  I found many useful links.  But I couldn’t find a link to the code for the Vending Machine that was described.  It seemed like it would be a very good exercise to try and create my own. 

It took me a few hours to do it.  But I think it was a very worthy exercise.  In the few years that I have been using LabVIEW, I’ve never really made use of the Event Structure or the Project Manager.  So this made things even more challenging.  Although I suppose I could have done it without using either. 

I’m posting my code because feedback from other developers is always useful to me.  There’s also not a whole lot of StateChart examples around yet.  If you work with this example or improve it, post your code if you would.  I’d like to see how others use this tool.

 

If anyone knows of other examples, I’d love to see them. 

 
---------------------
Patrick Allen: FunctionalityUnlimited.ca
Message 1 of 5
(3,227 Views)
On Apr 24, 2:40 pm, pallen <x...@no.email> wrote:
> For the past couple of days I?ve been exploring the new
> StateChart Module Toolkit.&nbsp; With a little
> bit of help I managed to work my way through the Getting Started Tutorial.&nbsp; But still felt I was missing a few pieces.
>
> Starting at this page: <a href="http://zone.ni.com/devzone/cda/tut/p/id/6194" target="_blank">http://zone.ni.com/devzone/cda/tut/p/id/6194</a> &nbsp; I found many useful links.&nbsp; But I couldn?t find a link to the code for
> the Vending Machine that was described.&nbsp;
> It seemed like it would be a very good exercise to try and create my
> own.&nbsp;
>
> It took me a few hours to do it.&nbsp; But I think it was a very worthy
> exercise.&nbsp; In the few years that I have
> been using LabVIEW, I?ve never really made use of the Event Structure or the
> Project Manager.&nbsp; So this made things
> even more challenging.&nbsp; Although I
> suppose I could have done it without using either.&nbsp;
>
> I?m posting my code because feedback from other developers
> is always useful to me.&nbsp; There?s also not
> a whole lot of StateChart examples around yet.&nbsp;
> If you work with this example or improve it, post your code if you
> would.&nbsp; I?d like to see how others use
> this tool.
>
> There?s another NI example posted here:&nbsp; <a href="http://zone.ni.com/devzone/cda/epd/p/id/5437" target="_blank">http://zone.ni.com/devzone/cda/epd/p/id/5437</a>
>
> If anyone knows of other examples, I?d love to see
> them.&nbsp;
>
> Vending Machine StateChart.zip:http://forums.ni.com/attachments/ni/170/318841/1/VendingMachine StateChart.zip

I don't know of any other State Chart examples. But Mathworks has
several Stateflow demos availabe on their Web Site. See:
http://www.mathworks.com/products/stateflow/demos.html?file=/products/demos/shipping/stateflow/sf_seqrec.htm
Of course you won't be able to run these demos but Mathworks does
provide a block diagram and considerable text with the block diagram.
You may find one of demos interesting.

Do you know of any good books on State Charts or Stateflow?

Howard
0 Kudos
Message 2 of 5
(3,195 Views)
hrh1818 wrote:
> On Apr 24, 2:40 pm, pallen <x...@no.email> wrote:
>> For the past couple of days I?ve been exploring the new
>> StateChart Module Toolkit.&nbsp; With a little
>> bit of help I managed to work my way through the Getting Started Tutorial.&nbsp; But still felt I was missing a few pieces.
>>
>> Starting at this page: <a href="http://zone.ni.com/devzone/cda/tut/p/id/6194" target="_blank">http://zone.ni.com/devzone/cda/tut/p/id/6194</a> &nbsp; I found many useful links.&nbsp; But I couldn?t find a link to the code for
>> the Vending Machine that was described.&nbsp;
>> It seemed like it would be a very good exercise to try and create my
>> own.&nbsp;
>>
>> It took me a few hours to do it.&nbsp; But I think it was a very worthy
>> exercise.&nbsp; In the few years that I have
>> been using LabVIEW, I?ve never really made use of the Event Structure or the
>> Project Manager.&nbsp; So this made things
>> even more challenging.&nbsp; Although I
>> suppose I could have done it without using either.&nbsp;
>>
>> I?m posting my code because feedback from other developers
>> is always useful to me.&nbsp; There?s also not
>> a whole lot of StateChart examples around yet.&nbsp;
>> If you work with this example or improve it, post your code if you
>> would.&nbsp; I?d like to see how others use
>> this tool.
>>
>> There?s another NI example posted here:&nbsp; <a href="http://zone.ni.com/devzone/cda/epd/p/id/5437" target="_blank">http://zone.ni.com/devzone/cda/epd/p/id/5437</a>
>>
>> If anyone knows of other examples, I?d love to see
>> them.&nbsp;
>>
>> Vending Machine StateChart.zip:http://forums.ni.com/attachments/ni/170/318841/1/VendingMachine StateChart.zip
>
> I don't know of any other State Chart examples. But Mathworks has
> several Stateflow demos availabe on their Web Site. See:
> http://www.mathworks.com/products/stateflow/demos.html?file=/products/demos/shipping/stateflow/sf_seqrec.htm
> Of course you won't be able to run these demos but Mathworks does
> provide a block diagram and considerable text with the block diagram.
> You may find one of demos interesting.
>
> Do you know of any good books on State Charts or Stateflow?
> Howard


Practical Statecharts in C/C++ by Miro Samek
http://www.quantum-leaps.com/resources/index.htm
Way cool!
0 Kudos
Message 3 of 5
(3,194 Views)
One thing I'm curious about is the use of Wait Timers in Static Reaction states. 

In the Count Coins State of this example, I have a Static Reaction that uses a Null Trigger.  It checks to see if a dollar's worth of coins has been deposited on every iteration of the state.  There are no Wait Timers anywhere in this code, yet the processor usage stays very low.  What I'm unclear on though is whether or not I should be using a Wait Timer anywhere in my StateChart code. 

I'll be trying out a few experiments over the weekend and into next week.  But I'm curious if anyone has any insight on this. 
---------------------
Patrick Allen: FunctionalityUnlimited.ca
0 Kudos
Message 4 of 5
(3,141 Views)
The image I used as a "template" to create my StateChart actually only showed one transition from the Idle State to the Vending Super State.  I was able to create a single transition that would respond to any of the three triggers. (nickel, dime, or quarter)  But I was unable to figure out how to pass that first trigger information into the Count Coins State so I could include that first coin with the rest that would be counted in that state.

I also thought about just adding that value to internal State Data right in that transition.  But if I set a transition to respond to any one of three triggers, how do I know exactly which one it responded to? 

Is there a way of using the History node to pass that trigger infomation into another state?   (Since I'm not leaving the state and then returning, this doesn't seem to be the way to go)


---------------------
Patrick Allen: FunctionalityUnlimited.ca
0 Kudos
Message 5 of 5
(3,126 Views)