ROS client for ruby

Project maintained by OTL Hosted on GitHub Pages — Theme by mattgraham

ROS Ruby Client: rosruby

ROS is Robot Operating System developed by Willow Garage and open source communities.

This project supports ruby ROS client. You can program robots by ruby, very easily.

API Reference

Let's start

Install ROS and ruby first. ROS document is .

You can install ruby by apt.

$ sudo apt-get install ruby rake

Download rosruby into your ROS_PACKAGE_PATH.

$ git clone git://

please add RUBYLIB environment variable, like below (if you are using bash).

$ echo "export RUBYLIB=`rospack find rosruby`/lib" >> ~/.bashrc
$ source ~/.bashrc

To use with precompiled electric release

If you are using precompiled ROS distro, use the msg/srv generation script ( If you are using ROS from source, it requires just recompile the msg/srv packages by rosmake rosruby.

$ rosrun rosruby

This converts msg/srv to .rb which is needed by sample programs. If you want to make other packages, add package names for args.

For example,

$ rosrun rosruby geometry_msgs nav_msgs

This script generates *.rb files under $HOME/.ros/rosruby directory. When you update message generator, it may be good idea to remove that directory.

Sample Source


#!/usr/bin/env ruby

require 'ros'
require 'std_msgs/String'

node ='/rosruby/sample_subscriber')
node.subscribe('/chatter', Std_msgs::String) do |msg|
  puts "message come! = \'#{}\'"

while node.ok?


#!/usr/bin/env ruby

require 'ros'
require 'std_msgs/String'

node ='/rosruby/sample_publisher')
publisher = node.advertise('/chatter', Std_msgs::String)

msg =

i = 0
while node.ok? = "Hello, rosruby!: #{i}"
  i += 1


Ruby requires 'Start with Capital letter' for class or module names. So please use Std_msgs::String class instead of std_msgs::String.

Try Publish and Subscribe

You needs three terminal as it is often for ROS users. Then you run roscore if is not running.

$ roscore

run publisher sample

$ rosrun rosruby sample_publisher.rb

run subscription sample

$ rosrun rosruby sample_subscriber.rb

you can check publication by using rostopic.

$ rostopic list
$ rostopic echo /chatter

Try Service?

$ rosrun rosruby add_two_ints_server.rb

run client with args ('a' and 'b' for roscpp_tutorials/TwoInts)

$ rosrun rosruby add_two_ints_client.rb 10 20

do all tests

run roscore if is not running.

$ roscore

and run the unit tests.

$ rosrun rosruby run-test.rb


$ roscd rosruby
$ rake test