Object Oriented State Machine Operating System Goes Open Source

On a desktop computer, you think of an operating system as a big piece of complex software. For small systems (like an Arduino) you might want something a lot simpler. Object Oriented State Machine Operating System (OOSMOS) is a single-file and highly portable operating system, and it recently went open source.

OOSMOS has a unique approach because it is threadless, which makes it easy to use in memory constrained systems because there is no stack required for threads that don’t exist. The unit of execution is a C++ object (although you can use C) that contains a state machine.

You can read the API documentation online. Just remember that this is not an end user OS like Windows or Linux, but an operating environment for managing multiple tasks. You can, though, use OOSMOS under Windows or Linux as well as many other host systems.

To get an idea of the portability options, consider the obligatory blink example. Platforms include Arduino, ESP8266, PIC32, Chipkit, Raspberry Pi, and several more. The Arduino code (in part) looks like this:

static void SetupToggle(int Pin, int OnTimeMS, int OffTimeMS)
  pin * pPin = pinNew(Pin, pinOut, pinActiveHigh);
  toggleNew(pPin, OnTimeMS, OffTimeMS);

extern void setup()
  SetupToggle(13, 2000, 2000);
  SetupToggle(12, 100, 100);
  SetupToggle(11, 50, 1500);

extern void loop()

The SetupToggle object is the state machine object. The setup function creates three instances of this object and the loop function calls the OOSMOS main loop. The pin class used in SetupToggle is part of OOSMOS’s hardware abstraction and the toggle object itself is part of reusable classes.

Of course, like all blinking LED examples, this is pretty simple. But other examples show synchronous functions and other advanced uses, including networking code for Windows and Linux.

We’ve talked about simple application specific operating systems for robots before. There’s also a lot of choices for specific processors, but OOSMOS looks like a great choice for something portable across a wide spectrum of hardware. If you want a look inside state machine theory, we’ve got you covered for that too.

19 thoughts on “Object Oriented State Machine Operating System Goes Open Source

      1. @occam49
        Java generally isn’t interpreted. The first-party runtime uses a JIT compiler to take the bytecode to native machine language. Sun first introduced their JIT in 1996. Incidentally, .Net works the same way.

        OOP frequently gets treated like a cure-all blunt instrument, which can do horrible things to software design. Yet on sites like this one I see many, many complaints about it are littered with mistakes and misunderstandings of varying severity–either of particular platforms, or object orientation in general. It makes me wonder whether some of the complainers have ever actually *used* OOP in a context that made any goddamn sense–that is, outside of “toy” projects for school assignments, or terrible shit-house dev companies whose software will be garbage regardless of paradigm.

  1. Boy, that example looks like a bunch of *procedure* calls. Check out the Arduino-only Cosa if you want to see OO examples:

    It has 14 Blink examples that use built-in threads, FSM, RTC Timer, schedulers and even a DS18B20 temperature. Here’s the Watchdog Blink:

    #include “Cosa/OutputPin.hh”
    #include “Cosa/Watchdog.hh”

    OutputPin ledPin(Board::LED);

    void setup()
    // Start the watchdog (0.5 second timeout)

    void loop()


    Cosa’s RAM, program size and speed metrics are hard to beat, too. Seriously, check out the UART and SPI numbers.

  2. I’ve been on a team developing a state machine bases control platform to replace Ladder logic (used in PLCs) for about two years now. Its called ‘Clockwork’ and is on github at github.com/latproc. At this time is used on full Linux OS but we have plans to take to down to the arm M level of hardware.

  3. QP might be the tool and runtime to have a look at: http://www.state-machine.com/

    The Cosa FSM may be found here: https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/FSM.hh. There is also a benchmark and an “advanced” blink example sketch. This implementation uses a static member function pointer as the state. This highly reduces memory foot-print and gives excellent performance. One alternative is the State Pattern (https://en.wikipedia.org/wiki/State_pattern).

    The Cosa FSM benchmark is the classical Ping-pong machine (bouncing messages): https://github.com/mikaelpatel/Cosa/blob/master/examples/Benchmarks/CosaBenchmarkFSM/CosaBenchmarkFSM.ino

    The RGB LED example sketch: https://github.com/mikaelpatel/Cosa/blob/master/examples/Blink/CosaBlinkFSM/CosaBlinkFSM.ino

    FSM is only one of many programming paradigms that Cosa supports. The most advanced is a UML Actor dependency driven runtime embedded in C++ using operator syntax: https://github.com/mikaelpatel/Cosa-UML


  4. What kind of game is going on in OOSMOS’s forum?

    I registered, my account got killed.
    I registered again, my account got killed again.

    My evil behaviour jus could have been not to write anything up to now but definitely I did not spam or other harm to the site…

    Do I need to understand that game?
    Do want to understand that game?

    I don’t thnk so!

    Bye bye OOSMOS!!!

    1. There was a lot of spam being posted on the forum. My apologies that your account was deleted. I decommissioned the forum until I come up with a better solution. In the meantime, feel free to send comments, questions or suggestions to me directly at mark.glenn@oosmos.com.

      Incidentally, I hope to post the code to Github sometime this week.


  5. A system which is much easier to use than this has been open source for over 5 years, its called Clockwork and now runs on a ESP32 and with work would run a atmel micros.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

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