Embedded robotics with Lua

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Embedded robotics with Lua

Jorge Visca
Here I present Toribio [1], an environment for writing robotics applications, geared toward low end hardware such as Single-Board Computers.

Toribio is built around Lumen [2], a pure-Lua cooperative scheduler inspired by the Sierra Wireless scheduler. Lumen provides coroutine and signal based concurrency, and integrates with nixio or luasocket for select/poll support. It runs unmodified on Lua 5.1, Lua 5.2 and LuaJIT. Everything runs in a single Lua instance, with shared memory.

Toribio provides easy-to-use objects to manipulate hardware ("devices"). A device could be a digital servo motor, or the accelerometer of a smartphone. When writing a Toribio (and thus Lumen) program you write tasks that send and wait for signals.  For a few examples to check how Toribio works, see the Tutorial. [3]

A very simple Toribio application could be as follows:

--------------------------------------------------------------------------
local motor_left = toribio.wait_for_device('AX:1') --acquire motors
local motor_right = toribio.wait_for_device('AX:2')
sched.sigrun(
    {emitter='*', events = {'setvel'}},
    function(_,_,motor, v)
        if motor=='left' then motor_left.set_speed(v)
        elseif motor=='right' then motor_right.set_speed(v) end
    end
)
sched.run(function()
    while true do
        sched.signal('setvel', 'left', math.random(-100,100))
        sched.sleep(3+math.random(3))
    end
end)
sched.run(function()
    while true do
        sched.signal('setvel', 'right', math.random(-100,100))
        sched.sleep(3+math.random(3))
    end
end)
--------------------------------------------------------------------------

This implements a two wheeled robot that aimlessly wanders around. There is a more detailed description of such a robot available in spanish in a blog post [4]. What you will see there is a basic platform being powered by an Openmoko smartphone (remember the Openmoko?) and an Asus WL520gu wireless router. The same Toribio is installed on both, and the same user application is run. The only native piece of code is nixio library (compiling for ARMv4 is incredibly annoying, luckily I wont have to do it again). It looks something like this:

http://youtu.be/uNz5D_vEhqc
http://youtu.be/x7R883WlGOI

There is a lot of work to do:

* Integrate it with ljsyscall (in addition to nixio and luasocket), to take full advantage of JIT-supported platforms.
* Besides the above mentioned platforms Toribio has been run on x86 and ARM powered XOs. I have access to BeagleBones and a RPi, so they are the next test platform.
* Provide support for more hardware. GPIO module is a good start.
* Lumen provides a remote shell: see if there is a telnet sever library in pure Lua to spice it up.
* A biggy one: provide a web-based IDE straight from Toribio, à la RPi. (have to find a http parser library in pure Lua).
* Related to the previous, create a great environment for initial programming teaching using robots, introducing a wedge between graphical oriented languages (Lego's NXT-G/TurtleArt/Scratch) and Python (as seen on XO's).
* A separate OpenCV tool that will push events to Toribio through a socket/pipe.
* ...the mind boggles at the possibilities.

Hope someone finds this interesting.

Jorge


[1] https://github.com/xopxe/Toribio
[2] https://github.com/xopxe/Lumen
[3] https://github.com/xopxe/Toribio/blob/master/docs/1-Tutorial.md
[4] http://cargueconcuidado.blogspot.com/2012/10/toribio.html