-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTouch_sensor_TTS.py
48 lines (42 loc) · 1.67 KB
/
Touch_sensor_TTS.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
#!/usr/bin/python
# _*_ coding: utf-8 -*-
import time
import RobotApi
RobotApi.ubtRobotInitialize()
#------------------------------Connect---------------------------------
gIPAddr=""
robotinfo=RobotApi.UBTEDU_ROBOTINFO_T()
#The robot name you want to connect
robotinfo.acName="Yanshee_369E"
ret=RobotApi.ubtRobotDiscovery("SDK",1,robotinfo)
if(0!=ret):
print("Return value: %d"%ret)
exit(1)
gIPAddr=robotinfo.acIPAddr
ret=RobotApi.ubtRobotConnect("SDK","1",gIPAddr)
if(0!=ret):
print("Can not connect to robot %s"%robotinfo.acName)
exit(1)
#---------------------------Read Sensor Value--------------------------
touch_sensor=RobotApi.UBTEDU_ROBOTTOUCH_SENSOR_T()
#RobotApi.ubtSetRobotMotion("raise", "left", 3, 1)
while True:
time.sleep(1)
ret=RobotApi.ubtReadSensorValue("touch",touch_sensor,4)
if ret!=0:
print("Can not read Sensor value. Error code: %d"%(ret))
else:
print("Read Touch Sensor Value: %d "%(touch_sensor.iValue))
if touch_sensor.iValue > 0 :
ret = RobotApi.ubtVoiceTTS(1,"很高兴认识你,人类朋友,我是人工智能教育机器人 偃师! ")
RobotApi.ubtSetRobotLED("button", "red", "blink")
time.sleep(2)
RobotApi.ubtSetRobotMotion("head", "left", 3, 1)
RobotApi.ubtSetRobotMotion("head", "front", 3, 1)
RobotApi.ubtSetRobotMotion("raise", "right", 3, 1)
RobotApi.ubtSetRobotMotion("head", "right", 3, 1)
RobotApi.ubtStartRobotAction("reset",1)
RobotApi.ubtSetRobotLED("button", "blue", "breath")
#---------------------------Disconnect---------------------------------
RobotApi.ubtRobotDisconnect("SDK","1",gIPAddr)
RobotApi.ubtRobotDeinitialize()