How to use the sphero_ros Python API?

时间:2016-04-15 15:14:12

标签: python ros sphero

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.

1 个答案:

答案 0 :(得分:0)

我在项目的GitHub davinellulinvega页面上按照Issues的说明操作。这是我在驱动程序附带的test.py文件的改编版本:

#!/usr/bin/python

from sphero_driver import sphero_driver
import time

sphero = sphero_driver.Sphero()

while True:
    try:
        sphero.connect()
        break
    except:
        print '\nTrying to connect again!'
        pass

time.sleep(2)

sphero.set_rgb_led(255, 0, 0, 0, False)
time.sleep(1)
sphero.set_rgb_led(0, 255, 0, 0, False)
time.sleep(1)
sphero.set_rgb_led(0, 0, 255, 0, False)
time.sleep(1)   

如果要连接到特定的Sphero,请使用

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

相反,第二个参数是你的Sphero地址。