Uncategorized

State Diagrams notes

Asked 
Active today
Viewed 53 times
1

I am trying to describe the states of all my units connected to the Raspberry Pi. I have several buttons, magnets, reed switches, LEDs, and other. This is a game and it has few phases. I want to describe states of each element for each phase and conditions to pass from one phase to another. I tried to use a state diagram, but there no states for elements. May be somebody has an example or the name of this diagram?

Example: We have 4 buttons (B1, B2, B3, B4) (Push Button Switch NO), 1 led, 1 photodiode, 1 step motor, 1 electric magnet and one contact (C1). Initial phase: – Led is switched on always but the light does not apply to the photodiode (because of the obstacle between them) – the step motor is off – the electric magnet is on and magnetizes a little door. – C1 opened

Phase 1: When buttons pushed in this combination B2, B1, B3, B1, B4 the step motor do 30 steps Then, when the obstacle between led and photodiode removed the step motor do another 30 steps Then, when C1 closed, the magnet switched off and release the little door.

share  edit  follow  reopen   flag
  • 1
    Your question is unclear to me, but AFAIK, what you seem to be describing is in fact a state diagram. There are several “types” of state diagrams with different characteristics – perhaps that’s what you’re after? Try this Wikipedia article on state diagrams as a starter. – Seamus yesterday
  • Hi Dzam, welcome and nice to meet you. Ah let me see. You gaming system is a bit completed. Now let me summarize. (1) Your game system has physical devices such as LED, button, magnet, reed etc. (2) You system has “phases” such as (a) game setup, (b) game playing, (c) game over, (3) Each phase has sequential/concurrent “states” such as the following: (4) State x: (i) all LED on, (ii) all button not pushed, (iii), … (5) State y: (i) button 2 pushed, (ii) reed on, (iii) magnet demagnetized, … You might like to comment or make counter suggestion on how to describe it. / continue, .. – tlfong01 23 hours ago
  • You might to wiki for a rough idea: (1) “State Diagram – Wikipedia“:en.wikipedia.org/wiki/State_diagram, (2) “UML State Machine – Wikipedia”:en.wikipedia.org/wiki/UML_state_machine. I like the UML wiki better. UML explains “actions” “trigger” “events”, “behaviour” “protocol” rather than state “transitions” It is good to use a pocket calculator example states: (a) switch on calculator, (b) push button (action) trigger events (LCD display digits), (c) protocols eg. to add two numbers, (i) “x > + > y > =” or (ii) “= > x > y > +”. State stuff is a hard. Go slow. Cheers. – tlfong01 22 hours ago
  • And you don’t need newbie scary state diagrams with labelled circles and arrows. Those diagrams are very hard to draw nicely. For newbies toy projects, a flowchart can do as well: (1) Flowchart I2C event triggered state trnsisition: imgur.com/gallery/ja4GlM0. Actually even flowchart type state diagrams are also hard to draw. I am usually lazy and just draw timed decision charts. Please let me know if you wish to see my example of decision tables. Feel free to ask me other state diagrams questions newbies are too afraid to ask. Happy gaming. Cheers. – tlfong01 21 hours ago
  • References: (1) “Digital 16bit Serial Output Type Ambient Light Sensor IC – RoHM Semi”:mouser.com/datasheet/2/348/bh1750fvi-e-186247.pdf (2) “Using the BH1750FVI I2C Digital Light Sensor – matt, RpiSpy 2015mar31”: raspberrypi-spy.co.uk/2015/03/…, (3) Using BH-1750 Light Sensor Problem raspberrypi.stackexchange.com/questions/112485/…. Cheers. – tlfong01 21 hours ago
  • A pocket calculator is a state machine: imgur.com/gallery/8DjmLBc. – tlfong01 19 hours ago
  • It is not clear why you say the following: “I tried to use a state diagram, but there [are] no states for elements, …”. I think each of your “elements” has states, logical or analogue states. For example LED may be in ON or OFF state, Reed switch ON or OFF state. Magnet may be in ENERGIZED or NON-ENGERIZED state. Sometimes it is confusing to differentiate between “state”, “event”, or “action”. For example, push button may be in “pushed” or “released state” state, but you can also say pushing or releasing are actions or events which caused transitions of states. / to continue, … – tlfong01 18 hours ago
  • For example, a pushing button action or event may cause a LED’s state’s transition from OFF to ON. I know it is vague or abstract. Perhaps I can think hard and give a real life example, say, using just LEDs and buttons, to make the story simple. Another complication is that implementing games usually needs “event driven” programming, using LUA for example, or multprocessing programmng using python’s multi-threading or multi_processing modules. By the way, python GpioZero is also multithreading and so can be used to implement concurrent LED and buttons. – tlfong01 18 hours ago
  • Now (1) a state decision table: imgur.com/gallery/xgzML3u, and (2) the tutorial:”Microcontroller State Machine Implementation – Heptapod”: heptapod.com/lib/statemachines. Cheers. – tlfong01 16 hours ago
  • The tutorial is very good in explaining how to implement a state machine using Arduino and C++ nested switch/case if-then-else control structures. For Rpi, we can still better, use “dictionaries” and concurrent programming with multiprocessing and multi-threading libraries/modules. – tlfong01 15 hours ago
  • 1
    @tlfong01 thank you for all this useful information. I read it all and saw all examples. But still, I don’t understand how to apply this to my project. I expanded the description with small example, can you help with a diagram for this specific example? Or maybe you have your own but very close to this? – Dzam 14 hours ago
  • Just a couple of quick and dirty random comments: (1) You small example is good, though a bit too complicated. We can make the specific situation more generic, but can still show the trick, (2) You specific example basically has 4 input devices and 4 output device, and can be generalized or abstracted to 4 buttons and 4 LEDs. In other words, if you can solve the 4 button 4 LED problem, of course you can solve n button, m LED problem, and x input device, y output device. / to continue, … – tlfong01 12 hours ago
  • We can start with 4 functions for the 4 input devices, and another 4 functions for the output devices. Using python dictionary control/data structure (no stupid and messy nested switch/case/if-then-else), and multiprocess/multithreading concurrent . It is easy even for users to scale up to 64 buttons and 64 LEDS, or whatever sensor/actuators. – tlfong01 12 hours ago
  • 1
    @tlfong01 The question not about “how to program” this stuff. I am a programmer, for me here no problems, but how to present all these actions/states in one diagram? Or you want to start with python dictionaries and to come to the diagram? – Dzam 12 hours ago
  • I would suggest to use a simple case study or assignment, to show how to solve the problem. Here is the assignment: (1) Wire 4 buttons and 4 LEDs on a bread board, (2) Use Gpio.Zero to write a blink LED, and a read button function. (3) Write a main program to let the 4 buttons to turn/off the 4 LEDs. You can start humble, say, RedButton to control only RedLED etc. Show me your GpioZero program, and I will try to tell you more about the tricks. / to continue, … – tlfong01 12 hours ago
  • I would also suggest you to use the following free drawing tool to draw some pictures, I mean flowcharts, decision tables, or UML state diagrams: “Dia Diagram Editor”: sourceforge.net/projects/dia-installer. Happy drawing. Cheers. – tlfong01 12 hours ago
  • Me programmer too. Perhaps you can tell me your event driven, and interrupt programming experience, so I can gear my explanation to your programming level. By the way, GpioZero is a bit complicated, actually using declarative (Prolog predicate logic) programming paradigm (so I am suggesting python Dictionary, or LUA table). You might also need to use list programming techniques (LISP, Scheme, Haskell) beside “state programming” (will try to find you a tutorial, perhaps later. Of course you need to know what is UML. In short, all above are “non programmer” stuff! – tlfong01 12 hours ago
  • But do you have any, even vague idea of OO ideas of ADT, delegation and polymorphism? You do need some basic UML state-chart ideas to understand state-oriented programming: “State-oriented programming – Miro Samek and Paul Montgomery, Embedded, 2000aug01”: m.eet.com/media/1177726/f-samek.pdf. Cheers. – tlfong01 11 hours ago
.END

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: