#!/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()
#!/usr/bin/python # _*_ coding: utf-8 -*- import time import yanshee_api as api api.ubtInitialize() #------------------------------Connect---------------------------------------- ret = api.ubtConnectRobot("127.0.0.1") if (0 != ret): print("Can not connect to robot") exit(1) #---------------------------Read Sensor Value------------------------------- isInterrputed = 1 gyro_size = 96 gyro_sensor = api.UBT_ROBOTGYRO_SENSOR_T() 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: