How to Code a State Machine | Embedded System Project Series #26

Поделиться
HTML-код
  • Опубликовано: 1 авг 2024
  • The application logic of my robot (as many other embedded systems) can be effectively represented as a finite-state machine. In this video, I sketch out the state diagram with PlantUML and prepare the corresponding skeleton code in C.
    0:00 Overview
    1:56 Draw diagram with PlantUML
    12:40 How I will code it
    13:30 Three previous commits
    16:09 Files
    17:25 State machine logic
    34:48 State wait
    36:35 State search
    43:48 State attack
    49:15 State retreat
    57:29 State manual
    59:00 Compile
    59:40 Flash is full!
    01:01:00 Commit
    01:02:05 Last words
    🌍 Related links
    Project code - github.com/artfulbytes/nsumo_...
    PlantUML - plantuml.com/
    PlantUML previewer - marketplace.visualstudio.com/...
    Quantum Leaps tutorial - • #35 State Machines Par...
    Wikipedia about State machine - en.wikipedia.org/wiki/Finite-...
    🌍 Find me here
    GitHub - github.com/artfulbytes
    Website - www.artfulbytes.com
    👨‍💻 About me
    Hi and welcome. I'm Niklas, an embedded systems engineer from Sweden. On this channel, I make practical videos about embedded systems or, in general terms, about building and programming hardware.
    #cprogramming #robot #embeddedsystems
  • НаукаНаука

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

  • @majestif
    @majestif 9 месяцев назад +3

    Very profound and comprehensive content, keep up great work!

  • @paulYT818
    @paulYT818 8 месяцев назад

    Appreciate all the work you put into these videos! One of the best embedded channels

  • @TradieTrev
    @TradieTrev 9 месяцев назад +2

    This is such a useful tool in process equipment!

  • @nicktyler1836
    @nicktyler1836 4 месяца назад

    Nice demo of Plant UML - seems like writing the text-based implementation of the state diagram would be a helpful exercise to clarify exactly how a project's states should work, if you're still working on the design and its not 100% clear yet. This convinced me to use it in a project i start next week. Great series, thanks!

  • @EqualsEngineering
    @EqualsEngineering 9 месяцев назад +1

    Great as always! Thanks for sharing!

  • @nfjeldberg
    @nfjeldberg 9 месяцев назад +1

    Amazing content, it's so helpful!

  • @palaaaurinkoon
    @palaaaurinkoon 9 месяцев назад +2

    You are the best!

  • @kyambaddemarkarthur6733
    @kyambaddemarkarthur6733 9 месяцев назад

    Insanely awesome!.

  • @truongvietdung4967
    @truongvietdung4967 9 месяцев назад

    Thank you very much

  • @olivialinden8699
    @olivialinden8699 7 месяцев назад

    👍

  • @codemayhem
    @codemayhem 4 месяца назад

    I'm somewhat new to programming and there's one line that i'm having a hard time wrapping my head around. can you explain the data->common.state_machine_data = data bit inside of the state_machine_init function? is it pointing to itself?

    • @artfulbytes
      @artfulbytes  4 месяца назад +1

      Yes that's right. That's used inside state_retreat.c when calling state_machine_post_internal_event. I'm trying to follow the principle of encapsulation here. The substates (e.g. attack, retreat) should not have access to the content of state_machine_data, but they should be able to call state machine functions that may require this data. struct state_machine_data is defined inside state_machine.c, so they don't know about the definition (e.g. trying to do ...data->attack inside state_retreat would give a compile error), but they have access to a pointer to data, so they can pass the pointer.

  • @salmantechnologies282
    @salmantechnologies282 9 месяцев назад

    Hello Niklas I love watching your videos kindly on my request can you make a video on ov2640 camera module driver development i am very confused that how the image array are captured and than displays on our Host or TFT as you are also in the company of camera manufacturing and their software development

    • @artfulbytes
      @artfulbytes  9 месяцев назад

      I don't have a project with a camera planned in the near future unfortunately. But in your case, I would try to find existing drivers (maybe Arduino?) and study them. Working with camera sensors can be complicated as there is quite a lot of terminology to wrap your head around.