Style:
Jesse van den Kieboom

Projects :: Webots Ruby Bindings

This small library provides ruby bindings for the webots robot simulator. The library makes it really easy to develop robot controllers in ruby, in the same convenient way as webots provides itself through the python bindings, but now with the power of ruby.

Because you can't extend webots to really understand the ruby bindings, the idea is to create a very small C controller, wich only task is to run the ruby controller. The ruby controller will get the argc/argv arguments provided to the C controller and expects the name of the ruby script where the ruby controller resides as the first command argument. The whole thing then looks like this:

C code

#include <webots-ruby/webots-ruby.h> int main(int argc, char *argv[]) { return webots_ruby_main(argc, argv); }

Ruby code

class Controller < DifferentialWheels STEP = 64 def run(ms) set_speed(100, 100) return STEP end def reset # Do some reset actions here end end

It's as simple as that. The webots-ruby library looks for a class named Controller. The class needs to descend from the Robot class (either directly, or indirectly through DifferentialWheels or CustomRobot). That's all there is to it! To link against webots-ruby you need to add something like the following to the standard webots controller Makefile:

CFLAGS=`pkg-config --cflags webots-ruby-0.1` LIBRARIES=`pkg-config --libs webots-ruby-0.1` -lruby1.8

You can download 0.1 and try it out!. Most of the API has bindings (except for the image retrieval part of the camera, the sound and physics plugins and the Supervisor robot).