forked from SpinazieSin/UvA-Home
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnaoqiutils.py
More file actions
83 lines (66 loc) · 2.32 KB
/
Copy pathnaoqiutils.py
File metadata and controls
83 lines (66 loc) · 2.32 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# -*-coding:utf-8-*-
"""File Containing functions to interact with the naoqi robot.
File name: naoqiutils.py
Author: Media Understanding 2017
Date created: 1/3/2017
Date last modified: 1/3/2017
Python Version: 2.7
"""
from naoqi import ALProxy
import vision_definitions
import PIL.Image as Image
IP = "mio.local"
PORT = 9559
import sys
def speak(phrase):
# errors if not converted to ascii :(
phrase = phrase.encode('ascii', 'ignore')
tts = ALProxy("ALTextToSpeech", IP, PORT)
tts.setVolume(1.0)
tts.say(phrase)
def get_images(amount):
camProxy = ALProxy("ALVideoDevice", IP, PORT)
resolution = 2 # VGA
colorSpace = 11 # RGB
videoClient = camProxy.subscribe("python_client", resolution, colorSpace, 5)
# Get a camera image.
# image[6] contains the image data passed as an array of ASCII chars.
raw_im_list = []
for i in range(amount):
naoImage = camProxy.getImageRemote(videoClient)
imageWidth = naoImage[0]
imageHeight = naoImage[1]
array = naoImage[6]
# Create a PIL Image from our pixel array.
raw_im_list.append((imageWidth, imageHeight, array))
rgb_im_list = []
for imageWidth, imageHeight, array in raw_im_list:
im = Image.fromstring("RGB", (imageWidth, imageHeight), array)
rgb_im_list.append(im)
camProxy.unsubscribe(videoClient)
return rgb_im_list
def get_image():
camProxy = ALProxy("ALVideoDevice", IP, PORT)
# Found the chart! its at
# http://doc.aldebaran.com/2-1/family/robots/video_robot.html
resolution = 2 # VGA 640*480px
colorSpace = 11 # RGB
videoClient = camProxy.subscribe("python_client", resolution, colorSpace, 5)
# Get a camera image.
# image[6] contains the image data passed as an array of ASCII chars.
naoImage = camProxy.getImageRemote(videoClient)
imageWidth = naoImage[0]
imageHeight = naoImage[1]
array = naoImage[6]
camProxy.unsubscribe(videoClient)
# Create a PIL Image from our pixel array.
im = Image.fromstring("RGB", (imageWidth, imageHeight), array)
return im
def play_sine(frequency):
try:
aup = ALProxy("ALAudioPlayer", IP, PORT)
except Exception, e:
print "Could not create proxy to ALAudioPlayer"
print "Error was: ", e
sys.exit(1)
aup.playSine(frequency, 40, 0, 0.5)