-
Notifications
You must be signed in to change notification settings - Fork 1
/
touch.py
56 lines (45 loc) · 1.73 KB
/
touch.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
50
51
52
53
54
55
56
#! /usr/bin/env python
# -*- encoding: UTF-8 -*-
"""Example: Use onTouchDown Method"""
import qi
import argparse
import sys
def main(app):
"""
This example uses the onTouchDown method.
To Test ALTabletService, you need to run the script ON the robot.
"""
# Get the service ALTabletService.
try:
session = app.session
tabletService = session.service("ALTabletService")
# Don't forget to disconnect the signal at the end
signalID = 0
# function called when the signal onTouchDown is triggered
def callback(x, y):
print "coordinate are x: ", x, " y: ", y
if x > 640:
# disconnect the signal
tabletService.onTouchDown.disconnect(signalID)
app.stop()
# attach the callback function to onJSEvent signal
signalID = tabletService.onTouchDown.connect(callback)
app.run()
except Exception, e:
print "Error was: ", e
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--ip", type=str, default="192.168.1.125",
help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
parser.add_argument("--port", type=int, default=9559,
help="Naoqi port number")
args = parser.parse_args()
try:
connection_url = "tcp://" + args.ip + ":" + str(args.port)
app = qi.Application(["TabletModule", "--qi-url=" + connection_url])
app.start()
except RuntimeError:
print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
"Please check your script arguments. Run with -h option for help.")
sys.exit(1)
main(app)