VeronicaLatLng VeronicaLatLng - 1 year ago 165
Python Question

How to use the sphero_ros Python API?

I have installed sphero_ros on my laptop running Ubuntu 12.04 LTS, and I've made it as far as being able to issue single rostopic commands to the Sphero via the Terminal. However, I would like to use the Python API instead, only I can't find any documentation on where I would even start to accomplish this. In essence, I'm looking for a step-by-step guide or a "Hello World" script of some sort. Can anyone help me?

Your help is much appreciated.

Answer Source

I followed davinellulinvega's instructions on the project's GitHub Issues page. Here is my adapted version of the file that comes with the driver:


from sphero_driver import sphero_driver
import time

sphero = sphero_driver.Sphero()

while True:
        print '\nTrying to connect again!'


sphero.set_rgb_led(255, 0, 0, 0, False)
sphero.set_rgb_led(0, 255, 0, 0, False)
sphero.set_rgb_led(0, 0, 255, 0, False)

If you want to connect to a specific Sphero, use

sphero = sphero_driver.Sphero('Sphero','01:23:45:67:89:AB')

instead, where the second argument is your Sphero's address.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download