Active Objects, Hierarchical State Machines and Modeling in Practice

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024
  • This is the talk "Modern Embedded Programming with Hierarchical State Machines and Active Objects" that Miro Samek presented at the [Embedded Online Conference in May 2021] (www.embeddedon....
    This presentation focuses on the practical aspects of modern embedded programming by showing you, step-by-step, the process of designing and implementing a fun "Fly 'n' Shoot" game to run on an embedded ARM Cortex-M board as well as on your PC.
    1:25 Agenda
    3:45 "Active Object" design pattern
    4:45 Traditional RTOS-based approach
    5:28 Perils of blocking
    6:05 High-level event-driven design
    7:00 Assigning resources to active objects
    9:05 Identifying events
    10:10 Sequence diagram explanation
    15:00 Detailed design and implementation
    18:00 QM modeling tool and designing a model in it
    27:34 Coding and code generation
    35:20 Importance of automatic code generation
    35:55 Options of executing active object-based application
    37:10 Preemptive, but non-blocking QK kernel
    38:33 Running on Windows ("dual-targeting")
    40:00 Summary
    Specifically, you will see how to partition a problem into loosely coupled, event-driven components called active objects and then how to design interactions among them using sequence diagrams.
    Next, you will see how to elaborate the internal behavior of identified active objects with modern hierarchical state machines.
    And finally, you will see how the state machines are implemented in C and how this code can be generated automatically.
    The session will utilize hands-on demonstrations using EFM32 Pearl-Gecko ARM Cortex-M4 board, the QP/C real-time embedded framework and the QM modeling and code-generation tool.
    End Notes:
    ----------
    Embedded software and host-based tools referenced in this video:
    www.state-mach...
    www.state-mach...
    www.state-mach...
    Free downloads:
    ---------------
    www.state-mach...
    GitHub:
    -------
    github.com/Qua...
    Music credits:
    --------------
    The background music comes from:
    www.bensound.c...

Комментарии • 37

  • @toddmoore112
    @toddmoore112 2 года назад +2

    I love qp model tool and working with it. It is so simple to use.

  • @theroninpianist4443
    @theroninpianist4443 2 года назад +5

    This information is extremely valuable, it also applies for Linux based systems.The sad part is that in 2022 very few engineers in the field can recognize this is a much better approach than the classic threads/resource blocking mechanism.

    • @StateMachineCOM
      @StateMachineCOM  2 года назад +3

      The event-driven thinking and the Active Object (Actor) design pattern are increasingly popular in enterprise computing, but they are certainly not mainstream in embedded software yet. This begs an interesting question of how people do their "architecture" or "design" with the traditional RTOS, blocking threads, semaphores, mutexes, and the rest of it. They can hardly use UML or state machines for that... Instead, people seem to improvise and either "invent" their own "block diagrams", or masquerade flowcharts as "state machines". All this is crazy considering that Active Objects and modern state machines are ideal for deeply embedded programming. --MMS

  • @ArdaX95
    @ArdaX95 2 года назад +3

    Thank you for making the video avaliable for those who could not attend to embedded online conference.

  • @ethiopia-prevails498
    @ethiopia-prevails498 Год назад +1

    I love it tnx. How can i find this lesson's zip file.❤

  • @rupantaradhikary6580
    @rupantaradhikary6580 3 месяца назад

    I have found that It's not really a coincidence that I gradually think and implement such a inheritance way for active object at least in c this is the only way to go it seems. I have learned all three concepts active object, opp's and state machine from this channel.

  • @technics6215
    @technics6215 2 года назад

    Thank you Sir. QP software is great, I wish there were more affordable licensing options for small (1-2 perople) companies.

    • @StateMachineCOM
      @StateMachineCOM  2 года назад +2

      I'm really glad that you like the QP frameworks. Regarding the licensing, the software *is* free to use under the GPL open source license. If you have reasons not to comply with GPL, then you most likely use QP for profit. In that case, it is a bit unfair that you do this without contributing anything back. Commercial licensing is a way to contribute something towards the ongoing development of QP and to make sure that it will be available in the future. (How else do you think that would happen?) For small businesses, there are half-priced small business commercial licenses. To my knowledge, this is unique in the industry, and no other software vendor offers such generous discounts for small businesses. Also, the commercial license prices haven't been increased ever (in 17 years), even though the functionality has been continuously enhanced and new components and tools have been added over time (QK, QXK, QM, QP/Spy, QUTest, QView, QWin, etc.) Finally, the commercial prices would even go down as a consequence of economies of scale, but too many developers either steal the software or plagiarize QP by making some cosmetic changes to work "around" the licensing.

    • @technics6215
      @technics6215 2 года назад

      @@StateMachineCOM Well, I totally agree this software is worth more. I probably should ask about licensing for people from countries where you cannot earn $1495 in 1.9 work days ;)

  • @bayroncabrera2592
    @bayroncabrera2592 Год назад

    Thank you a lot for this presentation, I'll surely make use of this resources in my incoming projects and make sure my partners take a look at this approach.

  • @jeswanthkumar4291
    @jeswanthkumar4291 2 года назад +1

    Thanks for the great tutorials Dr. Samek. I want to know if each active object needs to be confined to there respective task?

    • @StateMachineCOM
      @StateMachineCOM  2 года назад

      Yes, each Active Object runs in its own task (a.k.a. thread) and also has its own event queue (and a state machine). To learn more about the "Active Object" design pattern in embedded systems, there is a whole playlist: ruclips.net/p/PLPW8O6W-1chxSKPGnPbK8kZnQQHepv47I

    • @jeswanthkumar4291
      @jeswanthkumar4291 2 года назад

      @@StateMachineCOM thanks a lot for the clarification but again if each active object requires it's own task then will it not be difficult to develop and maintain large scale projects, project will then have lot of tasks and choosing the priorities will also be a very difficult right?

    • @StateMachineCOM
      @StateMachineCOM  2 года назад

      @@jeswanthkumar4291 One of the main points of this video was that Active Objects can contain much more functionality than traditional threads because AOs don't block and remain *responsive* to all events. In fact, the video demonstrated how to combine two traditional threads into one AO, so that the number of required threads is *drastically reduced*. This is *exactly* important for large-scale projects. If you don't like Active Objects, try the traditional blocking threads in a traditional RTOS approach -- then you can talk about the explosion of threads!

    • @jeswanthkumar4291
      @jeswanthkumar4291 2 года назад

      @@StateMachineCOM Got it, I have just started learning AO and qp framework. I have been working with traditional Rtos from past 7 years and clearly know the problems. I am finding it difficult to understand and digest AO any tips will also be helpful. But thanks a lot for your fast reply and your contribution to embedded world.

    • @StateMachineCOM
      @StateMachineCOM  2 года назад

      @@jeswanthkumar4291 One aspect mentioned in the video, but not elaborated on, was that *not* all state machines in the system need to be Active Objects. For example, the Mines in the "Fly 'n' Shoot" game were just passive components inside the Tunnel Active Object. This illustrates the use of the "Orthogonal Component" pattern (see www.state-machine.com/doc/Pattern_Orthogonal.pdf ) and can drastically reduce the number of Active Objects and threads in the system.

  • @wegi9621
    @wegi9621 2 года назад

    As I understand everything of this evoluate on to Windows/Linux system, which are in consequentions doesn't REAL TIME systems, but exactly the system of messages. So at the end messages going to non-realtime or "virtual-time" system. It is not?

    • @StateMachineCOM
      @StateMachineCOM  2 года назад

      Yes, that's right: Windows/Linux are not real-time. But still, you can use them for *development* of large portions of the embedded code that are not time critical, such as user interfaces. If you are interested in real-time event-driven programming, I've made a special video exactly about this subject: ruclips.net/video/6VhvmJVvaKY/видео.html . Please watch! --MMS

  • @BerthaProt
    @BerthaProt Год назад

    Hi, is this approch can be used on any embedded system (like IOT device with BT - screen and so on...), in that case will it make sense to "group" in the same Active object the display - the touch and the buttons together ?

    • @StateMachineCOM
      @StateMachineCOM  Год назад +1

      Yes, this approach can and should be used in any embedded system, especially IoT and low-power wireless. This is because the event-driven approach is inherently efficient and uses the CPU only when there are events to handle. Otherwise, the CPU and peripherals can be put into a low-power sleep mode. Regarding grouping the functionality in an Active Object (AO), this will work as well. Because AOs are event-driven, it is trivial to keep adding events to them. This is what it means that AOs are extensible. In contrast, traditional RTOS threads cannot easily be extended to handle new events because they block and respond only to the selected events. --MMS

    • @BerthaProt
      @BerthaProt Год назад

      @@StateMachineCOM Hi MMS, I have a concern before totally switching to AO approch : My application use a touch display "populated" using touchGFX engine (STM32 equivalent to LVGL), which run into a while(1) loop. Will it be still a good approch ?

    • @StateMachineCOM
      @StateMachineCOM  Год назад +1

      @@BerthaProt The active-object approach can work for embedded GUIs. I don't know the exact details of touchGFX, but there is an Application Note about using the QP framework with the SEGGER emWin GUI ( www.state-machine.com/doc/AN_QP_emWin.pdf ). The approach can be similar in the case of touchGFX. --MMS

    • @BerthaProt
      @BerthaProt Год назад

      @@StateMachineCOM Thanks a lot, I think I have the big picture. Let's code now 😆😆, again a big thanks for your support MMS

  • @honggangwei5085
    @honggangwei5085 Год назад

    Do you think there should be a mechanism to monitor all the active actor in health state?

    • @StateMachineCOM
      @StateMachineCOM  Год назад +1

      Yes, there should be a mechanism to monitor active objects in any state, not just in a "health state". Interestingly, the Active Object framework, like QP, already controls all interesting interactions in the system and "knows" about all state machine activities. Therefore, a framework like that is an ideal place to add *software tracing instrumentation* to monitor the whole application. Exactly this has been already done and you can watch a video ruclips.net/video/1L4bAOZHdIc/видео.html . --MMS

  • @statemachinecom9706
    @statemachinecom9706 2 года назад +6

    Here is an interesting comment posted by "Zwariowany Wampir" by somehow lost, so I re-post it here: "One piece missing for me is how to handle severely CPU-bound tasks. In order to preserve real-time constraints in this case you need preemptive kernel, right? But then you still need mutexes (at least in some cases). Mutexes == risk of deadlock and real-time response degradation. If I remember correctly the scheduling in QP is done from Pend SV interrupt. Is it possible to 'move' computationally intensive task to the 'main' function?"

    • @statemachinecom9706
      @statemachinecom9706 2 года назад +4

      Yes, for CPU-intensive processing, which means longer RTC (run-to-completion) steps, you can use a preemptive kernel. But the mutexes are needed only for protection of *sheared* resources among active objects. Please remember that an active object (AO) can handle significantly more functionality than a traditional RTOS thread, because AO does not block and thus remains *responsive* to all events. This means that you can drastically limit sharing by combining ftionalities that access the common resources. Such functionalities are called "cohesive", and AOs allow you to make highly cohesive designs that minimize sharing at the same time.
      Finally, regarding the specific implementation of preemptive kernels, PendSV is used obviously only to switch context in ARM Cortex-M CPUs. But I don't follow your stipulation of moving CPU-intensive work to the 'main' function. If the work is high-priority, it needs to be done in a high-priority AO. If the work is low-priority, you should put it in a low-priority AO. The 'main' function does not even run under a preemptive kernel.

  • @toddmoore112
    @toddmoore112 2 года назад

    Your tool doesnt support named entry points. Does it?

    • @StateMachineCOM
      @StateMachineCOM  2 года назад

      The QM tool supports submachines where entry and exit points *are* available. Please see www.state-machine.com/qm/sm_epseg.html --MMS

  • @weizhao4664
    @weizhao4664 2 года назад

    不错不错

  • @ashrafkamel1287
    @ashrafkamel1287 2 года назад

    Could you please make a video on how to write the event driven scheduler "dispatcher"?
    As you did with rtos

    • @StateMachineCOM
      @StateMachineCOM  2 года назад +3

      Event driven active objects can be executed in more ways than just the traditional RTOS threads, and the video briefly shows some of the available options at 35:58. So the event-driven scheduler "dispatcher" can be implemented in many different ways, because it can take advantage of the fact that active objects don't block internally. The options range from the non-preemptive run-to-completion execution (like the QV kernel mentioned in the video), to preemptive but non-blocking kernels (like the OSEK/VDX kernels or the QK kernel) to dual-mode kernels (like QXK), where you can mix non-blocking active objects with traditional blocking threads. I will discuss these interesting kernels in the future videos. --MMS

    • @ashrafkamel1287
      @ashrafkamel1287 2 года назад +1

      @@StateMachineCOM many thanks for your response,
      it would be great if you go over these topics.
      would solve a lot of mysteries about posting and subscribing to events.
      and how to use these patterns with priority introduced and synchronization between different priorities tasks.

    • @StateMachineCOM
      @StateMachineCOM  2 года назад +2

      More videos about event passing, dynamic events, and various patterns of their use are planned. Stay tuned! --MMS

  • @Embedded_Developer
    @Embedded_Developer 2 года назад

    Good!