5

Can anyone recommend an Arduino-based asynchronous scheduling library for controlling a small mobile robot?

I'm writing the control code for a small 2-wheeled Arduino-Uno based robot. It has a few bumper sensors, IR sensors, and ultrasonic sensors. I've written an initial pass from scratch, using loop() to read sensors and set motor values appropriately and then wait for the motor to have effect, but I'm finding this cluggy. Some of the sensors, like the ultrasonic range finders, require a small delay to operate, and the motors require a delay to have an effect. Blocking loop() is the simplest way to achieve this, but it wastes cycles, and can be difficult to time each action properly without throwing off other behaviors. Writing an asynchronous scheduler would be more efficient, but a lot more complicated, and I expect I would be reinventing the wheel.

I found this list, of existing scheduling libraries, but I'm not sure which, if any, would be appropriate.

  • You may also want to take a look at cosa library on github. – jfpoilpret Oct 28 '14 at 5:40
  • @jfpoilpret, Interesting. I'm not sure I want to throw out the default Arduino library just to use some scheduling componenets. And it's a shame Cosa's documentation is so bad. Why do so many developers think a class index with few comments and no examples is all they need for docs? Looking through that, it's not clear what I should use. It has a Timer, Alarm and Periodic class, as well as a few other classes that may be scheduling related as well. – Cerin Oct 28 '14 at 13:38
  • you're a bit unfair about documentation, it is not bad at all (compared to the standard arduino lib at least). Regarding examples, there are more than 100 of them and they are even a very good way to learn Cosa. – jfpoilpret Oct 28 '14 at 18:43
  • @jfpoilpret, I would agree that standard Arduino docs aren't great either, but the examples are better broken down by features set. I did see Cosa's examples directory, but other than the CosaAlarm example, I don't see anything else that uses the scheduling classes. – Cerin Oct 28 '14 at 19:57
  • Hello, I'm currently testing leOS / leOS2 (see github.com/leomil72 ) which seems to be a very nice scheduler lib for Arduino – AFract Oct 5 '15 at 20:07
1

I recommend writing your own in C++. Arduino works well with C++ as it is written in C. You can focus on getting the asynchronous behavior to do what you need instead of writing drivers. I don't think it will take any longer to learn enough C++ to make this work than it will to learn to use, and possibly fix, a library. Your C++ knowledge will be much more generally useful than knowing a specific library.

Igor points out the advantages of going to a real time operating system. I agree and think that, if you want to work on robots long term, you should go with an RTOS and get away from Arduino. Working with C++ and Arduino is one way to get started.

0

I would recommend ChibiOS: albeit it just got support for Arduino and it lacks a few drivers (I'm writing one for INTx and PCINT), it's got a fundamentally healthy design, a community around it and the author himself is very responsive.

You might have to write or port the drivers for external shields, however the upside is to get rid of the cruft that plagues most of the Arduino libraries.

You can even choose between 2 RTOS:

  • ChibiOS RT, a full fledged RTOS.
  • ChibiOS NIL, a minimalistic OS, actually almost a scheduler, which leaves more space and execution time for your own code. - But if you check the amount of FLASH taken up by a typical binary built with the default Arduino libraries, you will see that it pulls in a large amount of typically unused stuff, so you could trade that for the use of the full fledged RT.

Disclaimer: I'm just a very happy user of the OS, I do not have any other involvement with it, especially the commercial part.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.