TaskScheduler Library: What are your experiences?

I am referring to Anatoli Arkhipenko's TaskScheduler Library available through the Arduino IDE library manager and also here: GitHub - arkhipenko/TaskScheduler: Cooperative multitasking for Arduino, ESPx and STM32 microcontrollers

It's inevitable that for any project of moderate complexity you end up with various tasks that need to execute with different timings - a beeper beeps for a certain time and an LED blinks for a different time and don't forget to check for inputs and update your outputs. It doesn't take long for delay() to get thrown right out the window. Tracking millis() works, but with all your start time and previous time and duration variables, it can get a bit unwieldy and you still lose time to checking each task more often than is really necessary. Using a scheduler, where you can submit each task with a duration, number of repetitions, first iteration code, etc. along with the ability to add, delete, and modify tasks from within other tasks, seems a very efficient way to execute code. I've played with it a bit and it seems to work fine.

With all that capability and organization in a very small library I would expect it to be very popular, but it looks like hardly anyone uses it. I can't find any references to it on this forum. What are you experiences with this library and with cooperative multitasking on Arduino Uno/Nano/etc in general? Are there major shortcomings or pitfalls that I should watch out for? Is it just less useful than it seems?

I found uMT to work very well on the Due and, of course, freeRTOS on the ESP32 works great.

Idahowalker:
I found uMT to work very well on the Due and, of course, freeRTOS on the ESP32 works great.

Yes, freeRTOS has come up several times on the forum with good reviews. I'll be playing with the Due soon, but my current project is Atmel328P. for ESP32 and Cortex M3 we have the benefit of real hardware support for multithreading. For the Uno, well, we just do the best we can.

EDIT: I should add, because I was unaware until just now, that uMT can also work on the Uno. This is preemptive multitasking rather than cooperative multitasking as is done with the TaskScheduler library. All the releases were June 2017 and nothing since then, so I doubt there is any active development or extensive testing/debugging. GitHub - GO01260/uMT: uMT - a preemptive, soft real-time (not deterministic) multitasker for the ARDUINO AVR and SAM boards

I just use an automatic idle loop library. Anything you want to run in the background you just create from the base idler class and let it go.

Easy peasy!

-jim lee

Hi vocoder,

I'll be playing with the Due soon, but my current project is Atmel328P.

FreeRTOS also works really well on the Atmega328P (Uno, Nano, Pro Mini, etc...), although the 15ms scheduler tick (on these AVR boards) might be too slow for some applications.

It's worth reading the manual: "Mastering the FreeRTOS Real Time Kernel - A Hands On Tutorial Guide" found here: Free RTOS Book and Reference Manual.

It's a nice step-by-step tutorial that covers memory management, task scheduling, timers, queues, semaphores, mutexes, events, interrupt handling, task notifications and debugging.

jimLee:
I just use an automatic idle loop library. Anything you want to run in the background you just create from the base idler class and let it go.

Easy peasy!

-jim lee

That sounds useful. Do you have some example code?

MartinL:
Hi vocoder,

FreeRTOS also works really well on the Atmega328P (Uno, Nano, Pro Mini, etc...), although the 15ms scheduler tick (on these AVR boards) might be too slow for some applications.

It's worth reading the manual: "Mastering the FreeRTOS Real Time Kernel - A Hands On Tutorial Guide" found here: Free RTOS Book and Reference Manual.

It's a nice step-by-step tutorial that covers memory management, task scheduling, timers, queues, semaphores, mutexes, events, interrupt handling, task notifications and debugging.

Wonderful, I'm adding this to my project list.

vocoder:
That sounds useful. Do you have some example code?

You already have the library at your fingertips.

In the library manager search for LC_baseTools its in there with a bunch of goodies.

Oh and, if you use the idlers library, it comes with the sleep(ms) function to be used in your main loop(). Works just like delay(ms), except all your idler processes, Serial ports etc. keep running in the background. Handy handy handy!

Here is an example that comes with the library. "Blink withoug delay". blinker is an object that was built on the idler class. It runs in the background. Source code for blinker is in the library.

#include "blinker.h"

// So everyone wants newbies to write blink without delay. This is good
// because delay() is bad. Well, here's the simple way to do it..

// Allocate a global blinker object.
blinker aBLinker;             

void setup() {

   // Fire it up.
   aBLinker.setOnOff(true);   
}


void loop() {

   // blinker is an idler. Calling idle() once in loop lets ALL idlers run.
   idle();                    
}

-jim lee

Very many arduino projects never get to the “moderately complex” stage...

I donno'. I find aas soon as you add a touchscreen.. It gets complicated.

Actually, that's where the idler stuff comes in so handy. Running your GUI.

-jim lee

vocoder:
Yes, freeRTOS has come up several times on the forum with good reviews. I'll be playing with the Due soon, but my current project is Atmel328P. for ESP32 and Cortex M3 we have the benefit of real hardware support for multithreading. For the Uno, well, we just do the best we can.

EDIT: I should add, because I was unaware until just now, that uMT can also work on the Uno. This is preemptive multitasking rather than cooperative multitasking as is done with the TaskScheduler library. All the releases were June 2017 and nothing since then, so I doubt there is any active development or extensive testing/debugging. GitHub - GO01260/uMT: uMT - a preemptive, soft real-time (not deterministic) multitasker for the ARDUINO AVR and SAM boards

My experience is uMT is the author first wrote the code back in Amiga days and has, over the years, made the code work quite well. The author responds to questions but the uMT documentation is sufficient.

Most projects do not require a full RTOS. RIOS: A Lightweight Task Scheduler for Embedded Systems

RIOS is a lightweight portable task scheduler consisting of just a few dozens lines of code, intended to be understandable by students learning embedded systems programming. Non-preemptive and preemptive scheduler versions exist. Compared to the existing open-source solutions FreeRTOS and AtomThreads, RIOS on average has 95% fewer lines of total C code for a sample multitasking application, a 71% smaller executable, and 70% less scheduler time overhead. RIOS source code and examples are available for free at http://www.riosscheduler.org. RIOS is a sufficient real-time scheduling solution for various commercial applications.

Adding the freeRTOS library to the ESP32 does not incur a memory overhead from a library load. freeRTOS, is built-in/resides on the ESP32.

Follow the train of code for delay() using the Espressiff Core, you'll see delay() is a call to vTaskDelay() a freeRTOS method. In essence, when one is using a ESP32, one is using a RTOS. Why not use it properly?