#!/usr/bin/python # _*_ coding: utf-8 -*- import time import yanshee_api yanshee_api.ubtInitialize() #------------------------------Connect---------------------------------------- ret = yanshee_api.ubtConnectRobot("127.0.0.1") if (0 != ret): print("Can not connect to robot") exit(1) #---------------------------Voice recognition Start--------------------------- ret = yanshee_api.ubtStartAsr() if ret != 0: print("Can not start start voice recognition. Error Code: %d" % ret) exit(3) print("Voice recognition service started!") #--------------------------DisConnect--------------------------------- yanshee_api.ubtDisconnectRobot("127.0.0.1") yanshee_api.ubtDeinitialize()
while True: time.sleep(2) ret = api.ubtReadSensorValue("gyro", gyro_sensor, gyro_size) if ret != 0: print("Can not read Sensor value. Error code: %d" % (ret)) continue else: print("Read dEulerxValue : %f" % (gyro_sensor.dEulerxValue)) print("Read dEuleryValue : %f" % (gyro_sensor.dEuleryValue)) print("Read dEulerzValue : %f" % (gyro_sensor.dEulerzValue)) if gyro_sensor.dEulerxValue > 160 or gyro_sensor.dEulerxValue < -160: print 'Detected fall backward, I am going to get up' ret = api.ubtStartTts(isInterrputed, '哎呀,不好意思后脑勺着地了。赶快爬起来。') if ret != 0: print("Can not play TTS voice. Error code: %d" % ret) exit(3) print("Play TTS voice successfully!") api.ubtStartAction("getup_in_back", 1) elif gyro_sensor.dEulerxValue > -20 and gyro_sensor.dEulerxValue < 20: print 'Detected fall forward, I am going to get up' ret = api.ubtStartTts(isInterrputed, '哎呀,不好意思脸着地了,没有人看见吧。') if ret != 0: print("Can not play TTS voice. Error code: %d" % ret) exit(3) api.ubtStartAction("getup_in_front", 1) #---------------------------Disconnect-------------------------------------- api.ubtDisconnectRobot("127.0.0.1") api.ubtDeinitialize()