-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetup.py
49 lines (44 loc) · 1.99 KB
/
getup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python
# -*- coding: utf-8 -*-
import time
import RobotApi as api
api.ubtRobotInitialize()
#------------------------------Connect----------------------------------------
ret = api.ubtRobotConnect("SDK", "1", "127.0.0.1")
if (0 != ret):
print ("Can not connect to robot %s" % robotinfo.acName)
exit(1)
#---------------------------Read Sensor Value-------------------------------
isInterrputed = 1
gyro_size = 96
gyro_sensor = api.UBTEDU_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.ubtVoiceTTS(isInterrputed, 'Detected fall backward, I am going to get up')
if ret != 0:
print("Can not play TTS voice. Error code: %d" % ret)
exit(3)
print("Play TTS voice successfully!")
api.ubtStartRobotAction("reset", 1)
api.ubtStartRobotAction("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.ubtVoiceTTS(isInterrputed,'Detected fall forward, I am going to get up')
if ret != 0:
print("Can not play TTS voice. Error code: %d" % ret)
exit(3)
api.ubtStartRobotAction("reset", 1)
api.ubtStartRobotAction("getup_in_front", 1)
#---------------------------Disconnect--------------------------------------
api.ubtRobotDisconnect("SDK","1","127.0.0.1")
api.ubtRobotDeinitialize()