Project

rubysphero

0.0
No commit activity in last 3 years
No release in over 3 years
A Sphero client library to control your Orbotic Sphero 2.0
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0.2.4, ~> 0.2
 Project Readme

rubysphero

Rubysphero is a simple ruby driver for Orbotix's Sphero.

Developed and tested in Ruby 2.2.x on Windows 10, but should work on other platforms (Mac & Linux).

Installation

gem install rubysphero

Example code: Changing colours

require 'rubysphero'

sphero = SpheroClient.new "COM4"  

# Cycle through all Colours the driver knows about.
SpheroClient::COLOURS.each_key do |colour_name|
	sphero.set_colour(colour_name)
	sleep 2
end # each	

##Example code: Orientation and then roll forward at full speed...

require 'rubysphero'

sphero = SpheroClient.new "COM4"  

# Orient which way is back (180 degrees)
# Press and hold 'Enter' to spin the tail light round
# Press SPACE and then Enter to confirm that the tail light is at 180 degrees
sphero.orientation
	
# Roll forward (0 degrees) at speed 70 (out of 255)
sphero.roll(0,127)
sleep 2 

sphero.close

Example code: Orientation and the move in a square

You can also see this on YouTube https://youtu.be/EesOPdC2aw0

Here is the code:

require 'rubysphero'

sphero = SpheroClient.new "COM4"  

sphero.orientation # Orient the Sphero, using Enter key, then Space then Enter.

sphero.roll(0,50)
sleep 1
sphero.roll(90,50)
sleep 1
sphero.roll(180,50)
sleep 1
sphero.roll(270,50)

Example code: React when Sphero hits something.

require 'rubysphero'

sphero = SpheroClient.new "COM4"  

# Add first message to show after a collision
sphero.define_event_handling_for(:collision) do
	puts "Bang!"
end # event

# Add second message to show after a collision
sphero.define_event_handling_for(:collision) do
	puts "Crash!"
end # event

sphero.collision_detection(true)

sphero.orientation # Orient the Sphero, using Enter key, then Space then Enter.

sphero.roll(0,255) # Roll 0 degrees at full speed.

sleep 2