如何使用sphero_rosPythonAPI?
How to use the sphero_ros Python API?
我已经安装了 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,只是我找不到任何关于从哪里开始完成它的文档。本质上,我正在寻找分步指南或某种 "Hello World" 脚本。谁能帮帮我?
非常感谢您的帮助。
我关注了 davinellulinvega's instructions on the project's GitHub 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 的地址。
我已经安装了 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,只是我找不到任何关于从哪里开始完成它的文档。本质上,我正在寻找分步指南或某种 "Hello World" 脚本。谁能帮帮我?
非常感谢您的帮助。
我关注了 davinellulinvega's instructions on the project's GitHub 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 的地址。