I was looking for a simple task scheduler, and as I was not able to find anything that pleased my needs I decided to reinvent the wheel and make my own library. In case it is of any help to anyone else out there, here is my project. Feel free to contribute with your comments and/or code.
a timer queue is a fairly basic approach to scheduling many activities either periodically or one-time without needing a pre-emptive scheduler. (see chapter 2 of the XINU book)
a timer queue is a linked list of entries describing an actions (function ptr) and number of timer tics from the previously list entry. New entries can be inserted or removed from the list by simply updating the # of tics the new entry precedes. Multiple entries for the same time can of course exist with zero tics for the 2nd and subsequent entries
each timer event decrements the # tics in the entry at the head of the list and executes it when the # tics becomes zero.
You can also comb through this thread here for examples of Arduino task schedulers. Some interesting examples emerged, some generously described as “operating systems”, but were actually little more than task schedulers: https://forum.arduino.cc/index.php?topic=467927.0
6v6gt:
You can also comb through this thread here for examples of Arduino task schedulers. Some interesting examples emerged, some generously described as “operating systems”, but were actually little more than task schedulers: Arduino Operating System - Project Guidance - Arduino Forum
Had a look at that thread about Arduino OS's people have written. People go on about how they can't see how these could be any benefit... I so totally disagree! For example; a handheld that has different screens running different sketches. How can you do that without some sort of overall OS to manage them?
jimLee:
a handheld that has different screens running different sketches. How can you do that without some sort of overall OS to manage them?
-jim lee
And if you're doing something like that, why on earth do it on an Arduino? Use a $10 RPi ZeroW, and you have Linux, WiFi, HDMI, 512K RAM, and a real operating system. You can run Apache, SQL, Javascript, PHP, and have an app like that running in a couple of hours.
gcjr:
a timer queue is a fairly basic approach to scheduling many activities either periodically or one-time without needing a pre-emptive scheduler. (see chapter 2 of the XINU book)
a timer queue is a linked list of entries describing an actions (function ptr) and number of timer tics from the previously list entry. New entries can be inserted or removed from the list by simply updating the # of tics the new entry precedes. Multiple entries for the same time can of course exist with zero tics for the 2nd and subsequent entries
each timer event decrements the # tics in the entry at the head of the list and executes it when the # tics becomes zero.
Very interesting! That would be a fairly accurate description of what I have implemented. Your comment helped me realize that what I have implemented would be called a 'cooperative multitask'. I added that detail to the description of my project in it's readme file, so thanks for your contribution!
aarg:
You should add at least one example sketch to your library.
Thanks for the comment. As @RayLivingston pointed out, there is an example file named 'TaskScheduler.ino'. I see the confusion, as it is not labeled as such, so I added a clarification in the readme file. Perhaps I should have divided the files in a 'source' and an 'example' folder, but I thought it would be more comfortable and simple to have everything at the same level.
6v6gt:
You can also comb through this thread here for examples of Arduino task schedulers. Some interesting examples emerged, some generously described as “operating systems”, but were actually little more than task schedulers: Arduino Operating System - Project Guidance - Arduino Forum
All I wanted to do is be able to orchestrate the call of functions without using interrupts nor delays. Perhaps my project is over-simplistic, as I was looking for something board-independent and with a high-level of abstraction. The concept of an OS for Arduino sounds interesting, but I guess it would mean a level of complexity I do not want to dig into. Anyways, that thread is a good read and I did learn a couple of new things, so thanks!
jimLee:
Had a look at that thread about Arduino OS's people have written. People go on about how they can't see how these could be any benefit... I so totally disagree! For example; a handheld that has different screens running different sketches. How can you do that without some sort of overall OS to manage them?
-jim lee
Hi Jim. Your example is similar to my case. I wanted to control a bunch of sensors and a display in a orderly manner, making use of idle cycles to access the sensors or refresh the display, minimizing the amount of time the processor is idle. However, I am looking to make a quick proof of concept, so learning how to use an OS would mean a whole lot of effort. That is what motivated me to make this project. However, I am pretty sure there is plenty of room for improvement on what I have done.
RayLivingston:
And if you're doing something like that, why on earth do it on an Arduino? Use a $10 RPi ZeroW, and you have Linux, WiFi, HDMI, 512K RAM, and a real operating system. You can run Apache, SQL, Javascript, PHP, and have an app like that running in a couple of hours.
Regards,
Ray L
Because the Arduino is the easiest thing in the world to code, there are Arduino compatibles that are WAY more powerful I can grab off the shelf (IE Teensys) There is an unending array of hardware that I can use. And above this all, I don't need to learn Linux or anything else to get started. Setup() an loop() and away we go!
joebrave:
Hi Jim. Your example is similar to my case. I wanted to control a bunch of sensors and a display in a orderly manner, making use of idle cycles to access the sensors or refresh the display, minimizing the amount of time the processor is idle. However, I am looking to make a quick proof of concept, so learning how to use an OS would mean a whole lot of effort. That is what motivated me to make this project. However, I am pretty sure there is plenty of room for improvement on what I have done.
Actually I followed the same path awhile ago. I wrote a class idler that has a method void idle(void); Anything that is derived from this class has an idle() method you can inherit and fill in to do whatever you want. Along with all this, comes a function idle() I put in my loop() function. This autamatically calls al my myriad of "ilders" each time through.
If you want to deal with time, as in "lets only look every 100ms" I wrote a class timeObj that works like an egg timer. Set it for a time and it has a method ding() that returns true if the time has expired. Between the two, all of the worries about doing multiple things at once, just evaporated.
I tried to share this stuff, but was basically told I was stupid for writing such drivel.
Since then I've noticed, its common for people to write stuff that really helps them, but just confuses the heck out of everyone else. So I guess begin called dumb, is a somewhat common response.
i have lots of experience writing and debugging application code that relies on OS features to synchronize and communicate with other processes and processors. Early in my careers i read the OS books, Unix, XINU and Minix which gave be a good understanding of those OS concepts i needed later.
But I believe almost all simple applications running on small Atmel or esp32 processor don't have the real-time or social (yea!) needs for a multi-tasking OS. real-time is relative and social just avoid arguments.
Actually, now that I think about it. If I could wipe a Raspberry Pi and make it Arduino compatible; IE setup() loop(), I'd do it! This way the ongoing project is al I'd have to think about. No wondering how all the stuff it comes with works, or why I can't get it to work now.