rosruby

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 http://ros.org/wiki/ROS/Installation .

You can install ruby by apt.

$ sudo apt-get install ruby rake

Download rosruby into your ROS_PACKAGE_PATH.

$ git clone git://github.com/OTL/rosruby.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 (gen_for_precompiled.py) If you are using ROS from source, it requires just recompile the msg/srv packages by rosmake rosruby.

$ rosrun rosruby gen_for_precompiled.py

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 gen_for_precompiled.py 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

Subscriber

#!/usr/bin/env ruby

require 'ros'
require 'std_msgs/String'

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

while node.ok?
  node.spin_once
  sleep(1)
end

Publisher

#!/usr/bin/env ruby

require 'ros'
require 'std_msgs/String'

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

msg = Std_msgs::String.new

i = 0
while node.ok?
  msg.data = "Hello, rosruby!: #{i}"
  publisher.publish(msg)
  sleep(1.0)
  i += 1
end

Note

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

or

$ roscd rosruby
$ rake test