コード例 #1
0
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()
コード例 #2
0
#!/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()
コード例 #3
0
    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 dGyroxValue : %f" % (gyro_sensor.dGyroxValue))
        print("Read dGyroyValue : %f" % (gyro_sensor.dGyroyValue))
        print("Read dGyrozValue : %f" % (gyro_sensor.dGyrozValue))
        print("Read dAccexValue : %f" % (gyro_sensor.dAccexValue))
        print("Read dAcceyValue : %f" % (gyro_sensor.dAcceyValue))
        print("Read dAccezValue : %f" % (gyro_sensor.dAccezValue))
        print("Read dCompassxValue : %f" % (gyro_sensor.dCompassxValue))
        print("Read dCompassyValue : %f" % (gyro_sensor.dCompassyValue))
        print("Read dCompasszValue : %f" % (gyro_sensor.dCompasszValue))
        print("Read dEulerxValue : %f" % (gyro_sensor.dEulerxValue))
        print("Read dEuleryValue : %f" % (gyro_sensor.dEuleryValue))
        print("Read dEulerzValue : %f" % (gyro_sensor.dEulerzValue))
        print("------------------------------------------------")

    if gyro_sensor.dEulerxValue > 160 or gyro_sensor.dEulerxValue < -160:
        print 'getup from fall back'
        api.ubtStartAction("getup_in_back", 1)
    elif gyro_sensor.dEulerxValue > -20 and gyro_sensor.dEulerxValue < 20:
        print 'geup from fall front'
        api.ubtStartAction("getup_in_front", 1)

#---------------------------Disconnect--------------------------------------
api.ubtDisconnectRobot("SDK", "1", gIPAddr)
api.ubtDeinitialize()