Initial commit

This commit is contained in:
Kasiaaaaaa committed 2026-09-22 11:52:03 +02:00
commit d89b82be4a
103 files changed
+23110

No files matched your search

+772
View File
@@ -0,0 +1,772 @@
# --------------------------------------------------------------------------
# Authors:
# 2017-03-06: Thirsa
# 2020-01-28: Luke Meyer < l.meyer.5@student.rug.nl >
# Copyright MRC-CBSU(UK), CNRS(FR), UMCG(NL) and the author(s).
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY
# without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see < http: // www.gnu.org/licenses/>.
# --------------------------------------------------------------------------
from naoqi import ALProxy
import random
import math
import time
import paramiko
import sys
import tools.settings as settings
import qi
class Robot(object):
def __init__(self, IPADRESS, PORT, LANG, SUBJECT):
self.language = LANG
self.ipadress = str(IPADRESS)
# port = 54011
self.port = int(PORT)
self.subject = SUBJECT
# self.speaking_volume = 65
# self.stimulus_volume = 75
self.speaking_volume = 40
self.stimulus_volume = 45
self.say_0 = ''
self.say_1 = ''
self.say_2 = ''
self.say_3 = ''
self.say_4 = ''
self.say_5 = ''
self.encouragement_pos = []
self.encouragement_neg = []
self.hips = ["LHipYawPitch", "RHipYawPitch", "LHipPitch", "RHipPitch"]
from naoqi import ALProxy
self.mtn = ALProxy("ALMotion", self.ipadress, self.port)
self.tts = ALProxy("ALTextToSpeech", self.ipadress, self.port)
self.mem = ALProxy("ALMemory", self.ipadress, self.port)
self.pst = ALProxy("ALRobotPosture", self.ipadress, self.port)
self.aas = ALProxy("ALAnimatedSpeech", self.ipadress, self.port)
self.aap = ALProxy("ALAudioPlayer", self.ipadress, self.port)
self.aad = ALProxy("ALAudioDevice", self.ipadress, self.port)
self.all = ALProxy("ALLeds", self.ipadress, self.port)
self.asr = ALProxy("ALSpeechRecognition", self.ipadress, self.port)
self.bms = ALProxy("ALBehaviorManager", self.ipadress, self.port)
self.aad.setOutputVolume(self.speaking_volume)
if self.language == 'EN':
self.tts.setLanguage("English")
elif self.language == 'NL':
self.tts.setLanguage("Dutch")
# Only work when connecting to an actual robot. Does not work with a virtual robot.
# self.afr = ALProxy("ALFaceDetection",self.ipadress,self.port)
def buiging(self):
'''
Choregraphe bezier export in Python.
Bowing gesture
'''
self.mtn.wakeUp()
names = list()
times = list()
keys = list()
names.append("HeadPitch")
times.append([0.6, 1.84, 3])
keys.append([[-0.159578, [3, -0.2, 0], [3, 0.413333, 0]],
[-0.116626, [3, -0.413333, 0], [3, 0.386667, 0]],
[-0.159578, [3, -0.386667, 0], [3, 0, 0]]])
names.append("HeadYaw")
times.append([0.6, 1.84, 3])
keys.append([[-0.0123138, [3, -0.2, 0], [3, 0.413333, 0]],
[-0.0123138, [3, -0.413333, 0], [3, 0.386667, 0]],
[-0.0123138, [3, -0.386667, 0], [3, 0, 0]]])
names.append("LAnklePitch")
times.append([0.6, 1.84, 3])
keys.append([[0.0904641, [3, -0.2, 0], [3, 0.413333, 0]],
[0.115008, [3, -0.413333, 0], [3, 0.386667, 0]],
[0.0904641, [3, -0.386667, 0], [3, 0, 0]]])
names.append("LAnkleRoll")
times.append([0.6, 1.84, 3])
keys.append([[-0.12728, [3, -0.2, 0], [3, 0.413333, 0]],
[-0.151824, [3, -0.413333, 0], [3, 0.386667, 0]],
[-0.12728, [3, -0.386667, 0], [3, 0, 0]]])
names.append("LElbowRoll")
times.append([0.6, 1.84, 3])
keys.append([[-0.45709, [3, -0.2, 0], [3, 0.413333, 0]],
[-1.50481, [3, -0.413333, 0], [3, 0.386667, 0]],
[-0.45709, [3, -0.386667, 0], [3, 0, 0]]])
names.append("LElbowYaw")
times.append([0.6, 1.84, 3])
keys.append([[-1.15054, [3, -0.2, 0], [3, 0.413333, 0]],
[-0.529273, [3, -0.413333, 0], [3, 0.386667, 0]],
[-1.15054, [3, -0.386667, 0], [3, 0, 0]]])
names.append("LHand")
times.append([0.6, 1.84, 3])
keys.append([[0.2832, [3, -0.2, 0], [3, 0.413333, 0]],
[0.2832, [3, -0.413333, 0], [3, 0.386667, 0]],
[0.2832, [3, -0.386667, 0], [3, 0, 0]]])
names.append("LHipPitch")
times.append([0.6, 1.84, 3])
keys.append([[0.131966, [3, -0.2, 0], [3, 0.413333, 0]],
[-0.363515, [3, -0.413333, 0], [3, 0.386667, 0]],
[0.131966, [3, -0.386667, 0], [3, 0, 0]]])
names.append("LHipRoll")
times.append([0.6, 1.84, 3])
keys.append([[0.107422, [3, -0.2, 0], [3, 0.413333, 0]],
[0.0951499, [3, -0.413333, 0], [3, 0.386667, 0]],
[0.107422, [3, -0.386667, 0], [3, 0, 0]]])
names.append("LHipYawPitch")
times.append([0.6, 1.84, 3])
keys.append([[-0.162562, [3, -0.2, 0], [3, 0.413333, 0]],
[-0.25767, [3, -0.413333, 0], [3, 0.386667, 0]],
[-0.162562, [3, -0.386667, 0], [3, 0, 0]]])
names.append("LKneePitch")
times.append([0.6, 1.84, 3])
keys.append([[-0.0844118, [3, -0.2, 0], [3, 0.413333, 0]],
[-0.0844118, [3, -0.413333, 0], [3, 0.386667, 0]],
[-0.0844118, [3, -0.386667, 0], [3, 0, 0]]])
names.append("LShoulderPitch")
times.append([0.6, 1.84, 3])
keys.append([[1.48334, [3, -0.2, 0], [3, 0.413333, 0]],
[1.14432, [3, -0.413333, 0], [3, 0.386667, 0]],
[1.48334, [3, -0.386667, 0], [3, 0, 0]]])
names.append("LShoulderRoll")
times.append([0.6, 1.84, 3])
keys.append([[0.11194, [3, -0.2, 0], [3, 0.413333, 0]],
[0.130348, [3, -0.413333, 0], [3, 0.386667, 0]],
[0.11194, [3, -0.386667, 0], [3, 0, 0]]])
names.append("LWristYaw")
times.append([0.6, 1.84, 3])
keys.append([[0.0459781, [3, -0.2, 0], [3, 0.413333, 0]],
[-1.09225, [3, -0.413333, 0], [3, 0.386667, 0]],
[0.0459781, [3, -0.386667, 0], [3, 0, 0]]])
names.append("RAnklePitch")
times.append([0.6, 1.84, 3])
keys.append([[0.0982179, [3, -0.2, 0], [3, 0.413333, 0]],
[0.0798099, [3, -0.413333, 0], [3, 0.386667, 0]],
[0.0982179, [3, -0.386667, 0], [3, 0, 0]]])
names.append("RAnkleRoll")
times.append([0.6, 1.84, 3])
keys.append([[0.135034, [3, -0.2, 0], [3, 0.413333, 0]],
[0.145772, [3, -0.413333, 0], [3, 0.386667, 0]],
[0.135034, [3, -0.386667, 0], [3, 0, 0]]])
names.append("RElbowRoll")
times.append([0.6, 1.84, 3])
keys.append([[0.385075, [3, -0.2, 0], [3, 0.413333, 0]],
[0.360533, [3, -0.413333, 0], [3, 0.386667, 0]],
[0.385075, [3, -0.386667, 0], [3, 0, 0]]])
names.append("RElbowYaw")
times.append([0.6, 1.84, 3])
keys.append([[1.20415, [3, -0.2, 0], [3, 0.413333, 0]],
[1.39897, [3, -0.413333, 0], [3, 0.386667, 0]],
[1.20415, [3, -0.386667, 0], [3, 0, 0]]])
names.append("RHand")
times.append([0.6, 1.84, 3])
keys.append([[0.2916, [3, -0.2, 0], [3, 0.413333, 0]],
[0.2916, [3, -0.413333, 0], [3, 0.386667, 0]],
[0.2916, [3, -0.386667, 0], [3, 0, 0]]])
names.append("RHipPitch")
times.append([0.6, 1.84, 3])
keys.append([[0.130348, [3, -0.2, 0], [3, 0.413333, 0]],
[-0.322183, [3, -0.413333, 0], [3, 0.386667, 0]],
[0.130348, [3, -0.386667, 0], [3, 0, 0]]])
names.append("RHipRoll")
times.append([0.6, 1.84, 3])
keys.append([[-0.0996681, [3, -0.2, 0], [3, 0.413333, 0]],
[-0.0413762, [3, -0.413333, 0], [3, 0.386667, 0]],
[-0.0996681, [3, -0.386667, 0], [3, 0, 0]]])
names.append("RHipYawPitch")
times.append([0.6, 1.84, 3])
keys.append([[-0.162562, [3, -0.2, 0], [3, 0.413333, 0]],
[-0.25767, [3, -0.413333, 0], [3, 0.386667, 0]],
[-0.162562, [3, -0.386667, 0], [3, 0, 0]]])
names.append("RKneePitch")
times.append([0.6, 1.84, 3])
keys.append([[-0.0858622, [3, -0.2, 0], [3, 0.413333, 0]],
[-0.0923279, [3, -0.413333, 0], [3, 0.386667, 0]],
[-0.0858622, [3, -0.386667, 0], [3, 0, 0]]])
names.append("RShoulderPitch")
times.append([0.6, 1.84, 3])
keys.append([[1.46961, [3, -0.2, 0], [3, 0.413333, 0]],
[0.93118, [3, -0.413333, 0], [3, 0.386667, 0]],
[1.46961, [3, -0.386667, 0], [3, 0, 0]]])
names.append("RShoulderRoll")
times.append([0.6, 1.84, 3])
keys.append([[-0.136568, [3, -0.2, 0], [3, 0.413333, 0]],
[-0.306841, [3, -0.413333, 0], [3, 0.386667, 0]],
[-0.136568, [3, -0.386667, 0], [3, 0, 0]]])
names.append("RWristYaw")
times.append([0.6, 1.84, 3])
keys.append([[0.076658, [3, -0.2, 0], [3, 0.413333, 0]],
[-0.372804, [3, -0.413333, 0], [3, 0.386667, 0]],
[0.076658, [3, -0.386667, 0], [3, 0, 0]]])
try:
self.mtn.angleInterpolationBezier(names, times, keys)
self.aas.say(
"^start(animations/Stand/Gestures/Explain_2)Je gaat 3 keer een triplet van verschillende lettergrepen horen. 1 van de tripletten wordt gezegd met een andere stem. Het is jouw taak om aan te geven welke anders klinkt. Je kunt antwoorden door je hand op mijn rechterhand, \\pau=500\\ hoofd \\pau=500\\of linkerhand te leggen. Laten we het proberen. ^wait(animations/Stand/Gestures/Explain_2)"
)
except BaseException, err:
print err
self.mtn.rest()
self.mtn.setStiffnesses(self.hips, 1.0)
def intro(self):
'''
The intriduction to the experiment. Sam explains how the task will
work and what to do, as well as a demonstration on how to touch
the head and hands
'''
if self.language == "EN":
self.say_0 = "^start(animations/stand/Gestures/Enthusiastic_4) Hi there! My name is Sammmy.\\pau=500\\ Welcome to the PICKA auditory performance game.\\pau=500\\ Lets have some fun!"
elif self.language == 'NL':
if "HIK" in self.subject:
self.say_0 = "^start(animations/stand/Gestures/Enthusiastic_4) Hoi! \\pau=250\\ Ik ben Sam."
else:
self.say_0 = "^start(animations/stand/Gestures/Enthusiastic_4) Hallo! \\pau=250\\ Ik ben Sammmy. \\pau=500\\ Welkom bij de PICKA auditieve optreden spelletje. \\pau=500\\ Laten we wat plezier hebben!"
self.mtn.wakeUp()
self.aas.say(self.say_0)
def play_audio(self, stimulus):
'''
Uploads the stimuli files to Sam using a paramiko sftp server.
Sam then plays the files, then deletes them off its main storage.
'''
NAO_USERNAME = "nao"
NAO_PASSWORD = "nao"
t = paramiko.Transport((self.ipadress, 22))
t.connect(username=NAO_USERNAME, password=NAO_PASSWORD)
sftp = paramiko.SFTPClient.from_transport(t)
sftp.chdir('/home/nao/tests/')
remotepath = str('/home/nao/tests/' + stimulus)
try:
print "Uploading file..."
sftp.put(stimulus, remotepath)
print "File Uploaded"
except:
raise ValueError('No file provided for upload.')
for i in range(1, 1000):
dir_list = sftp.listdir()
if stimulus in dir_list:
break
else:
time.sleep(0.01)
if i == 999:
raise ValueError('File was not uploaded to nao')
# localpath = (
# 'C:\\Users\\Nao\\Documents\\Nao scripts\\Expe_files\\' + soundfile)
try:
# aap = self.aap.playFile(remotepath)
qi.async(self.aap.playFile, remotepath, delay=0)
except RuntimeError as e:
print e
sys.exit(0)
# sftp.remove(stimulus)
time.sleep(0.5)
return True
def game_break(self):
'''
Waits for a response from the subject to start the experiment.
'''
if self.language == 'EN':
self.say_1 = "When you're ready to begin, you can start the game by touching the top of my head."
self.say_2 = "Let's begin!"
self.say_3 = "Ok. Goodbye."
elif self.language == 'NL':
self.say_1 = "Wanneer je klaar bent om te beginnen, kun je het experiment starten door je hand op mijn hoofd te leggen."
self.say_2 = 'Hier gaan we'
self.say_3 = "Ok. Tot ziens."
self.tts.say(self.say_1)
self.mtn.setStiffnesses(["HeadYaw", "HeadPitch"], [1.0, 1.0])
self.hoofd_beweging()
# current_running_time = 0
# start_time = time.time()
# while current_running_time < (start_time+120):
# # check the data continously for 120 seconds
# head1 = self.mem.getData('RearTactilTouched')
# head2 = self.mem.getData('FrontTactilTouched')ell
# head = [head1, head2, head3]
# if any(head):
# break
# current_running_time = time.time()
self.tts.say(self.say_2)
def encouragement(self, robot_input):
'''Issues an encouragement message depending on how the subject is doing.'''
if self.language == 'EN':
self.encouragement_pos = [
"\\vct=110\\You're doing great!\\vct=100\\",
'\\vct=110\\ Keep going! \\vct=100\\',
'\\vct=110\\ Doing well!\\vct=100\\',
"\\vct=110\\ Great!\\vct=100\\"
]
self.encouragement_neg = [
"\\vct=110\\ You can do it! \\vct=100\\",
"\\vct=110\\ Keep trying! \\vct=100\\",
"\\vct=110\\ Give it another go! \\vct=100\\",
"\\vct=110\\ Don't give up!\\vct=100\\"
]
elif self.language == 'NL':
self.encouragement_pos = [
"\\vct=110\\ Goed bezig!\\vct=100\\",
'\\vct=110\\ Ga zo door! \\vct=100\\',
'\\vct=110\\ Je doet het super!\\vct=100\\',
"\\vct=110\\ Super!\\vct=100\\"
]
self.encouragement_neg = [
"\\vct=110\\ Je kunt het! \\vct=100\\",
"\\vct=110\\ Blijf proberen! \\vct=100\\",
"\\vct=110\\ Nog even doorgaan! \\vct=100\\",
"\\vct=110\\ Niet opgeven!\\vct=100\\"
]
answer = str(robot_input)
if answer == 'correct':
encouragement_options_positive = self.encouragement_pos
prob = random.randint(0, len(encouragement_options_positive) - 1)
encou = encouragement_options_positive[prob]
else:
encouragement_options_negative = self.encouragement_neg
prob = random.randint(0, len(encouragement_options_negative) - 1)
encou = encouragement_options_negative[prob]
self.tts.say(encou)
def ending(self):
'''Performs the ending of the experiment.'''
if self.language == 'EN':
self.say_1 = '^start(animations/Stand/Gestures/Enthusiastic_5) That\'s the end of our game! ^wait(animations/Stand/Gestures/Enthusiastic_5) \\pau=200\\ ^start(animations/Stand/Gestures/Explain_1)Thank you for playing with me! ^wait(animations/Stand/Gestures/Explain_1) ^start(animations/Stand/Gestures/Hey_6) Goodbye! ^wait(animations/Stand/Gestures/Hey_6)'
elif self.language == 'NL':
self.say_1 = '^start(animations/Stand/Gestures/Enthusiastic_5) Dit is het einde van ons spel! ^wait(animations/Stand/Gestures/Enthusiastic_5) \\pau=200\\ ^start(animations/Stand/Gestures/Explain_1)Dankjewel voor het meespelen ^wait(animations/Stand/Gestures/Explain_1) ^start(animations/Stand/Gestures/Hey_6)en tot ziens! ^wait(animations/Stand/Gestures/Hey_6)'
self.mtn.wakeUp()
self.aas.setBodyLanguageMode = 2
self.aas.say(self.say_1)
self.mtn.rest()
def head_shake(self):
# Choregraphe bezier export in Python.
names = list()
times = list()
keys = list()
names.append("HeadPitch")
times.append([0.8, 1.6, 2.4])
keys.append([[-0.0782759, [3, -0.266667, 0], [3, 0.266667, 0]],
[-0.090548, [3, -0.266667, 0], [3, 0.266667, 0]],
[-0.07214, [3, -0.266667, 0], [3, 0, 0]]])
names.append("HeadYaw")
times.append([0.8, 1.6, 2.4])
keys.append([[-0.842209, [3, -0.266667, 0], [3, 0.266667, 0]],
[0.619695, [3, -0.266667, 0], [3, 0.266667, 0]],
[-0.0107799, [3, -0.266667, 0], [3, 0, 0]]])
try:
self.mtn.angleInterpolationBezier(names, times, keys)
except BaseException, err:
print err
def head_nod(self):
# Choregraphe bezier export in Python.
names = list()
times = list()
keys = list()
names.append("HeadPitch")
times.append([0.8, 1.6])
keys.append([[0.18864, [3, -0.266667, 0], [3, 0.266667, 0]],
[-0.0567999, [3, -0.266667, 0], [3, 0, 0]]])
names.append("HeadYaw")
times.append([0.8, 1.6])
keys.append([[-0.0567999, [3, -0.266667, 0], [3, 0.266667, 0]],
[-0.0322559, [3, -0.266667, 0], [3, 0, 0]]])
try:
self.mtn.angleInterpolationBezier(names, times, keys)
except BaseException, err:
print err
def retry(self):
if self.language == 'EN':
# \\pau=500\\ If yes \\pau=500\\ touch my head \\pau=500\\ if no \\pau=500\\ touch my left or right hand."
self.say_1 = "Would you like to try again?"
self.tts.say(self.say_1)
current_running_time = 0
start_time = time.time()
self.asr.subscribe("retry")
while current_running_time < (start_time + 120):
if self.mem.getData("WordRecognized")[0] == "yes":
self.asr.unsubscribe("retry")
return True
elif self.mem.getData("WordRecognized")[0] == "no":
self.asr.unsubscribe("retry")
return False
def simple_say(self, msg):
self.tts.say(msg)
def take_break(self):
behaviour_name = "custom_packages-8cd326/take_break"
if self.bms.isBehaviorInstalled(behaviour_name):
if self.bms.isBehaviorRunning(behaviour_name) == True:
self.bms.stopBehavior(behaviour_name)
self.mtn.setStiffnesses(self.hips, 0.0)
self.bms.runBehavior(behaviour_name)
else:
self.tts.say(
"I don't appear to be able to take a break right now.")
self.mtn.setStiffnesses(self.hips, 1.0)
def hoofd_beweging(self):
'''Moves the head down for the subject to test the tactile function of Sam during the introduction.'''
names = list()
times = list()
keys = list()
names.append("HeadPitch")
times.append([0.7])
keys.append([[0.35738, [3, -0.133333, 0], [3, 0, 0]]])
names.append("HeadYaw")
times.append([0.7])
keys.append([[-0.0399261, [3, -0.133333, 0], [3, 0, 0]]])
try:
self.mtn.angleInterpolationBezier(names, times, keys)
except BaseException, err:
print err
start_time = time.time()
current_running_time = 0
while current_running_time < (start_time + 120):
# check the data continously for 7 seconds
head1 = self.mem.getData('RearTactilTouched')
head2 = self.mem.getData('FrontTactilTouched')
head3 = self.mem.getData('MiddleTactilTouched')
head = [head1, head2, head3]
if any(head):
answer_given = 2
break
current_running_time = time.time()
names = list()
times = list()
keys = list()
names.append("HeadPitch")
times.append([0.7])
keys.append([[-0.17185, [3, -0.133333, 0], [3, 0, 0]]])
names.append("HeadYaw")
times.append([0.7])
keys.append([[-0.0153821, [3, -0.133333, 0], [3, 0, 0]]])
try:
self.mtn.angleInterpolationBezier(names, times, keys)
except BaseException, err:
print err
def rechterhand_beweging(self):
'''Moves the right hand up for the subject to test the tactile function of Sam during the introduction.'''
names = list()
times = list()
keys = list()
names.append("LElbowRoll")
times.append([0.7])
keys.append([[-0.412604, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LElbowYaw")
times.append([0.7])
keys.append([[-1.19349, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LHand")
times.append([0.7])
keys.append([[0.2904, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LShoulderPitch")
times.append([0.7])
keys.append([[1.52169, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LShoulderRoll")
times.append([0.7])
keys.append([[0.10427, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LWristYaw")
times.append([0.7])
keys.append([[0.108872, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RElbowRoll")
times.append([0.7])
keys.append([[0.04146, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RElbowYaw")
times.append([0.7])
keys.append([[1.12131, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RHand")
times.append([0.7])
keys.append([[0.29, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RShoulderPitch")
times.append([0.7])
keys.append([[0.457174, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RShoulderRoll")
times.append([0.7])
keys.append([[0.254602, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RWristYaw")
times.append([0.7])
keys.append([[-1.03549, [3, -0.133333, 0], [3, 0, 0]]])
try:
self.mtn.angleInterpolationBezier(names, times, keys)
except BaseException, err:
print err
start_time = time.time()
current_running_time = 0
while current_running_time < (start_time + 120):
right1 = self.mem.getData('HandRightRightTouched')
right2 = self.mem.getData('HandRightBackTouched')
right3 = self.mem.getData('HandRightLeftTouched')
right = [right1, right2, right3]
if any(right):
break
current_running_time = time.time()
names = list()
times = list()
keys = list()
names.append("LElbowRoll")
times.append([0.7])
keys.append([[-0.412604, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LElbowYaw")
times.append([0.7])
keys.append([[-1.19349, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LHand")
times.append([0.7])
keys.append([[0.2904, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LShoulderPitch")
times.append([0.7])
keys.append([[1.52169, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LShoulderRoll")
times.append([0.7])
keys.append([[0.102736, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LWristYaw")
times.append([0.7])
keys.append([[0.108872, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RElbowRoll")
times.append([0.7])
keys.append([[0.382008, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RElbowYaw")
times.append([0.7])
keys.append([[1.16733, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RHand")
times.append([0.7])
keys.append([[0.29, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RShoulderPitch")
times.append([0.7])
keys.append([[1.45274, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RShoulderRoll")
times.append([0.7])
keys.append([[-0.0752079, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RWristYaw")
times.append([0.7])
keys.append([[0.0413761, [3, -0.133333, 0], [3, 0, 0]]])
try:
self.mtn.angleInterpolationBezier(names, times, keys)
except BaseException, err:
print err
def linkerhand_beweging(self):
'''Moves the left hand up for the subject to test the tactile function of Sam during the introduction.'''
names = list()
times = list()
keys = list()
names.append("LElbowRoll")
times.append([0.7])
keys.append([[-0.0367742, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LElbowYaw")
times.append([0.7])
keys.append([[-0.974132, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LHand")
times.append([0.7])
keys.append([[0.2904, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LShoulderPitch")
times.append([0.7])
keys.append([[0.624296, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LShoulderRoll")
times.append([0.7])
keys.append([[-0.227074, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LWristYaw")
times.append([0.7])
keys.append([[0.88661, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RElbowRoll")
times.append([0.7])
keys.append([[0.382008, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RElbowYaw")
times.append([0.7])
keys.append([[1.16733, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RHand")
times.append([0.7])
keys.append([[0.29, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RShoulderPitch")
times.append([0.7])
keys.append([[1.45274, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RShoulderRoll")
times.append([0.7])
keys.append([[-0.0752079, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RWristYaw")
times.append([0.7])
keys.append([[0.0413761, [3, -0.133333, 0], [3, 0, 0]]])
try:
self.mtn.angleInterpolationBezier(names, times, keys)
except BaseException, err:
print err
current_running_time = 0
start_time = time.time()
while current_running_time < (start_time + 120):
left1 = self.mem.getData('HandLeftRightTouched')
left2 = self.mem.getData('HandLeftBackTouched')
left3 = self.mem.getData('HandLeftLeftTouched')
left = [left1, left2, left3]
if any(left):
break
current_running_time = time.time()
names = list()
times = list()
keys = list()
names.append("LElbowRoll")
times.append([0.7])
keys.append([[-0.412604, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LElbowYaw")
times.append([0.7])
keys.append([[-1.19349, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LHand")
times.append([0.7])
keys.append([[0.2904, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LShoulderPitch")
times.append([0.7])
keys.append([[1.52169, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LShoulderRoll")
times.append([0.7])
keys.append([[0.102736, [3, -0.133333, 0], [3, 0, 0]]])
names.append("LWristYaw")
times.append([0.7])
keys.append([[0.108872, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RElbowRoll")
times.append([0.7])
keys.append([[0.382008, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RElbowYaw")
times.append([0.7])
keys.append([[1.16733, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RHand")
times.append([0.7])
keys.append([[0.29, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RShoulderPitch")
times.append([0.7])
keys.append([[1.45274, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RShoulderRoll")
times.append([0.7])
keys.append([[-0.0752079, [3, -0.133333, 0], [3, 0, 0]]])
names.append("RWristYaw")
times.append([0.7])
keys.append([[0.0413761, [3, -0.133333, 0], [3, 0, 0]]])
try:
self.mtn.angleInterpolationBezier(names, times, keys)
except BaseException, err:
print err
if __name__ == "__main__":
nao = Robot('127.0.0.1', 9559, "EN")
nao.buiging()
+121
View File
@@ -0,0 +1,121 @@
from Robot import Robot
import paramiko
import os
import sys
import cPickle as pickle
import time
from naoqi import ALProxy
class RobotCRM(Robot):
def crmIntro(self):
if self.language == "EN":
self.say_1 = "^start(animations/Stand/Gestures/Explain_2)You are going to hear a sentence that sounds like it is spoken in a noisy room. \\pau=500\\ \
It is your task to determine what was said in the sentence. An example sentence is, show the dog where the green 4 is.\\pau=500\\ \
To enter your answer, you will have to use the coloured grid on the tablet provided. You must choose both the correct color and number that was spoken.\
^wait(animations/Stand/Gestures/Explain_2)"
self.say_2 = "\\pau=500\\ During the experiment, when my eyes turn green like this,"
self.say_3 = "I am ready for your answer. \\pau=500\\"
self.say_4 = "Now I will try to make myself as quiet as possible."
elif self.language == "NL":
self.say_1 = "^start(animations/Stand/Gestures/Explain_2)You are going to hear a sentence that sounds like it is spoken in a noisy room. \\pau=500\\ \
It is your task to determine what was said in the sentence. An example sentence is, show the dog where the green 4 is.\\pau=500\\ \
To enter your answer, you will have to use the coloured grid on the tablet provided. You must choose both the correct color and number that was spoken.\
^wait(animations/Stand/Gestures/Explain_2)"
self.say_2 = "\\pau=500\\ During the experiment, when my eyes turn green like this,"
self.say_3 = "I am ready for your answer. \\pau=500\\"
self.say_4 = "Now I will try to make myself as quiet as possible."
self.mtn.wakeUp()
self.aas.say(self.say_1)
self.aas.say(self.say_2)
self.all.fadeRGB("FaceLeds", "green", 0.01)
self.tts.say("\\pau=500\\")
self.aas.say(self.say_3)
self.all.fadeRGB("FaceLeds", "white", 0.01)
self.aas.say(self.say_4)
self.mtn.rest()
self.mtn.setStiffnesses(self.hips, 1.0)
def play_sounds(self, stimulus, lang):
'''
Uploads the stimuli files to Sam using a paramiko sftp server.
Sam then plays the files, then deletes them off its main storage.
'''
NAO_USERNAME = "nao"
NAO_PASSWORD = "nao"
t = paramiko.Transport((self.ipadress, 22))
t.connect(username=NAO_USERNAME, password=NAO_PASSWORD)
sftp = paramiko.SFTPClient.from_transport(t)
sftp.chdir('/home/nao/tests/')
remotepath = str('/home/nao/tests/' + stimulus)
print "trying to upload"
try:
sftp.put(stimulus, remotepath)
except:
raise ValueError('No file provided for upload.')
for i in range(1, 1000):
dir_list = sftp.listdir()
if stimulus in dir_list:
break
else:
time.sleep(0.01)
if i == 999:
raise ValueError('File was not uploaded to nao')
# localpath = (
# 'C:\\Users\\Nao\\Documents\\Nao scripts\\Expe_files\\' + soundfile)
remotepath = str('/home/nao/tests/' + stimulus)
print "uploaded, now playing"
try:
self.aap.playFile(remotepath)
except RuntimeError:
sys.exit(0)
sftp.remove(stimulus)
time.sleep(0.5)
return True
def answer(self, correct_answer, feedback, current_trial, total_trials):
self.mtn.setStiffnesses(self.hips, 1.0)
self.all.fadeRGB("FaceLeds", "green", 0.01)
start_time = time.time()
current_running_time = 0
folder = os.path.dirname("./crm/")
ans_file = 'answer.p'
answer = {}
while current_running_time < start_time + 120:
dirs = os.listdir('./crm')
if ans_file in dirs:
try:
with open('./crm/answer.p', 'rb') as f:
answer = pickle.load(f)
break
except EOFError as e:
print e
current_running_time = time.time()
answer["number"] = int(answer["number"])
response_time = time.time() - start_time
if feedback:
self.mtn.setStiffnesses(["HeadYaw", "HeadPitch"], [1.0, 1.0])
if answer["colour"] == correct_answer["colour"] and answer["number"] == correct_answer["number"]:
self.head_nod()
else:
self.head_shake()
self.mtn.setStiffnesses(["HeadYaw", "HeadPitch"], [0.0, 0.0])
self.all.fadeRGB("FaceLeds", "white", 0.01)
os.remove(os.path.join(folder, ans_file))
trial_track = {"current_trial": current_trial + 1,
"total_trials": total_trials}
with open('./crm/trials.p', 'wb') as f:
pickle.dump(trial_track, f)
print current_trial
return answer, response_time
+190
View File
@@ -0,0 +1,190 @@
import paramiko
import time
import os
import sys
from naoqi import ALProxy
from Robot import Robot
from RobotGender import RobotGender
def printTotals(transferred, toBeTransferred):
print "Transferred: {0}\tOut of: {1}".format(transferred, toBeTransferred)
class RobotEmotion(RobotGender):
def emotionIntro(self):
if self.language == "EN":
self.say_1 = "^start(animations/Stand/Gestures/Explain_2)You are going to hear a voice that sounds either happy, sad, or angry. \
It is your task to determine the emotion of the voice. \
^wait(animations/Stand/Gestures/Explain_2)"
self.say_2 = "\\pau=500\\ During the experiment, when my eyes turn green like this,"
self.say_3 = "I am ready for your answer. You can answer by touching my right hand, head, or left hand. Let's try it. \\pau=500\\"
self.say_4 = "\\pau=500\\ Now I will try to make myself as quite as possible so we can get started."
self.say_5 = "Touch my right hand if the voice sounds happy"
self.say_6 = "My head if the voice sounds angry."
self.say_7 = "Or my left hand if the voice sounds sad."
elif self.language == "NL":
if "HIK" in self.subject:
self.say_1 = "^start(animations/Stand/Gestures/Explain_2)Je gaat een stem horen die blij, verdrietig, of boos klinkt. \
Jouw taak is om te zeggen welke emotie je hebt gehoord. \
^wait(animations/Stand/Gestures/Explain_2)"
self.say_2 = "Prima!\\pau=500\\ Tijdens het experiment, als mijn ogen zo groen worden,"
self.say_3 = "Mag jij antwoord geven."
self.say_4 = "Nog een ding. Als je het experiment tussendoor wilt stoppen, wacht dan tot ik ben gestopt met praten en raak dan mijn rechtervoet aan. \\pau=500\\ Nou zal ik me nu zo stil mogelijk maken."
self.say_5 = "Als de stem blij klinkt, raak dan mijn rechterhand aan. Probeer maar."
self.say_6 = "Super! \\pau=150\\ Als de stem boos klinkt, raak dan mijn hoofd aan."
self.say_7 = "Heel goed! \\pau=150\\ Of als de stem verdrietig klinkt, raak dan mijn linkerhand aan."
else:
self.say_1 = "^start(animations/Stand/Gestures/Explain_2)Je gaat een stem horen die blij, verdrietig, of boos klinkt. \
Jouw taak is om te zeggen welke emotie je hebt gehoord. \
^wait(animations/Stand/Gestures/Explain_2)"
self.say_2 = "Prima!\\pau=500\\ Tijdens het experiment, als mijn ogen zo groen worden,"
self.say_3 = "Mag jij antwoord geven."
self.say_4 = "Nog een ding. Als je het experiment tussendoor wilt stoppen, wacht dan tot ik ben gestopt met praten en raak dan mijn rechtervoet aan. \\pau=500\\ Nou zal ik me nu zo stil mogelijk maken."
self.say_5 = "Als de stem blij klinkt, raak dan mijn rechterhand aan. Probeer maar."
self.say_6 = "Super! \\pau=150\\ Als de stem boos klinkt, raak dan mijn hoofd aan."
self.say_7 = "Heel goed! \\pau=150\\ Of als de stem verdrietig klinkt, raak dan mijn linkerhand aan."
self.mtn.wakeUp()
self.aas.say(self.say_1)
self.aas.setBodyLanguageMode = 0
# self.pst.goToPosture("Stand", 0.7)
# self.rightHandMotion(self.say_5)
self.aas.say(self.say_2)
self.all.fadeRGB("FaceLeds", "green", 0.01)
self.tts.say("\\pau=500\\")
self.aas.say(self.say_3)
self.all.fadeRGB("FaceLeds", "white", 0.01)
self.aas.say(self.say_5)
self.rechterhand_beweging()
# self.tts.say("\\pau=250\\")
# self.headMovement(self.say_6)
self.aas.say(self.say_6)
self.hoofd_beweging()
# self.tts.say("\\pau=250\\")
# self.leftHandMove(self.say_7)
self.aas.say(self.say_7)
self.linkerhand_beweging()
self.aas.say(self.say_4)
self.mtn.rest()
self.mtn.setStiffnesses(self.hips, 1.0)
def play_sounds(self, stimulus, lang):
'''
Uploads the stimuli files to Sam using a paramiko sftp server.
Sam then plays the files, then deletes them off its main storage.
'''
NAO_USERNAME = "nao"
NAO_PASSWORD = "nao"
t = paramiko.Transport((self.ipadress, 22))
t.connect(username=NAO_USERNAME, password=NAO_PASSWORD)
sftp = paramiko.SFTPClient.from_transport(t)
sftp.chdir('/home/nao/tests/')
remotepath = str('/home/nao/tests/' + stimulus)
try:
sftp.put(stimulus, remotepath)
except:
raise ValueError('No file provided for upload.')
for i in range(1, 1000):
dir_list = sftp.listdir()
if stimulus in dir_list:
break
else:
time.sleep(0.01)
if i == 999:
raise ValueError('File was not uploaded to nao')
# localpath = (
# 'C:\\Users\\Nao\\Documents\\Nao scripts\\Expe_files\\' + soundfile)
try:
self.aap.playFile(remotepath)
except RuntimeError:
sys.exit(0)
sftp.remove(stimulus)
time.sleep(0.5)
def answer(self, correct_answer, feedback):
self.mtn.setStiffnesses(self.hips, 1.0)
start_time = time.time()
self.all.fadeRGB("FaceLeds", "green", 0.01)
current_running_time = 0
answer_given = 0
while current_running_time < (start_time + 120):
try:
head1 = self.mem.getData('RearTactilTouched')
head2 = self.mem.getData('FrontTactilTouched')
head3 = self.mem.getData('MiddleTactilTouched')
head = [head1, head2, head3]
left1 = self.mem.getData('HandLeftRightTouched')
left2 = self.mem.getData('HandLeftBackTouched')
left3 = self.mem.getData('HandLeftLeftTouched')
left = [left1, left2, left3]
right1 = self.mem.getData('HandRightRightTouched')
right2 = self.mem.getData('HandRightBackTouched')
right3 = self.mem.getData('HandRightLeftTouched')
right = [right1, right2, right3]
if any(right):
answer_given = "happy"
break
elif any(left):
answer_given = "sad"
break
elif any(head):
answer_given = "angry"
break
current_running_time = time.time()
except RuntimeError as e:
print e
sys.exit(0)
if feedback == 1:
self.mtn.setStiffnesses(["HeadYaw", "HeadPitch"], [1.0, 1.0])
if answer_given == correct_answer:
self.head_nod()
elif answer_given != correct_answer:
self.head_shake()
else:
self.tts.say(self.say_3)
self.mtn.setStiffnesses(["HeadYaw", "HeadPitch"], [0.0, 0.0])
self.all.fadeRGB("FaceLeds", "white", 0.01)
return answer_given
def headMovement(self, string):
'''Moves the head down for the subject to test the tactile function of Sam during the introduction.'''
names = list()
times = list()
keys = list()
names.append("HeadPitch")
times.append([0.7])
keys.append([[0.35738, [3, -0.133333, 0], [3, 0, 0]]])
names.append("HeadYaw")
times.append([0.7])
keys.append([[-0.0399261, [3, -0.133333, 0], [3, 0, 0]]])
try:
motion = ALProxy("ALMotion")
motion.moveInit()
w = motion.post.angleInterpolationBezier(names, times, keys)
self.tts.say(string)
motion.wait(w, 0)
except BaseException, err:
print err
names.append("HeadPitch")
times.append([0.7])
keys.append([[-0.17185, [3, -0.133333, 0], [3, 0, 0]]])
names.append("HeadYaw")
times.append([0.7])
keys.append([[-0.0153821, [3, -0.133333, 0], [3, 0, 0]]])
try:
self.mtn.angleInterpolationBezier(names, times, keys)
except BaseException, err:
print err
+180
View File
@@ -0,0 +1,180 @@
from Robot import Robot
import paramiko
import time
import sys
class RobotFishy(Robot):
def fishyIntro(self):
'''
The intriduction to the experiment. Sam explains how the task will
work and what to do, as well as a demonstration on how to touch
the head and hands
'''
if self.language == 'EN':
self.say_1 = "^start(animations/Stand/Gestures/Explain_2)You are goint to hear a triplet of three different syllables. \
One of the triplets is said in a different voice. \
It is your task to determine which triplet is said in a different voice. \
You can answer by touching my right hand, \\pau=500\\ head \\pau=500\\or left hand. \
Lets give it a try. ^wait(animations/Stand/Gestures/Explain_2)"
self.say_2 = "If the first word is said in a different voice, then touch the top of my right hand. Try it."
self.say_3 = "Great! \\pau=500\\ and if the second sound is said differently, then touch the top of my head."
self.say_4 = "Super! \\pau=500\\ and if the last sound is said in a different voice, then touch the top of my left hand."
self.say_5 = "Very good!. During the experiment, when my eyes turn green like this,"
self.say_6 = "I am ready for your answer."
# self.say_7 = "One last thing. If at any point you want to stop the experiment, wait for me to stop talking, and then press my right foot. \\pau=500\\ Now I will try to make myself as quite as possible."
self.say_7 = "\\pau=500\\ Now I will try to make myself as quite as possible."
elif self.language == 'NL':
self.say_1 = "^start(animations/Stand/Gestures/Explain_2)Je gaat 3 keer een triplet van verschillende lettergrepen horen.\
1 van de tripletten wordt gezegd met een andere stem. Het is jouw taak om aan te geven welke anders klinkt. \
Je kunt antwoorden door je hand op mijn rechterhand, \\pau=500\\ hoofd \\pau=500\\of linkerhand te leggen. \
Laten we het proberen. ^wait(animations/Stand/Gestures/Explain_2)"
self.say_2 = "Als het eerste woord met een andere stem gezegd wordt, leg je jouw hand op de bovenkant van mijn rechterhand. Probeer maar"
self.say_3 = "Heel goed \\pau=500\\ en als het tweede woord met een andere stem gezegd wordt, leg je jouw hand op de bovenkant van mijn hoofd"
self.say_4 = "Super \\pau=500\\ en als laatste de bovenkant van mijn linkerhand"
self.say_5 = "Heel goed. Dan zal ik me nu zo stil mogelijk maken"
self.mtn.wakeUp()
self.aas.say(self.say_1)
self.aas.setBodyLanguageMode = 0
self.pst.goToPosture("Stand", 0.7)
self.aas.say(self.say_2)
self.rechterhand_beweging()
self.aas.say(self.say_3)
self.hoofd_beweging()
self.aas.say(self.say_4)
self.linkerhand_beweging()
# time.sleep(1)
self.aas.say(self.say_5)
self.all.fadeRGB("FaceLeds", "green", 0.01)
self.tts.say("\\pau=500\\")
self.aas.say(self.say_6)
self.all.fadeRGB("FaceLeds", "white", 0.01)
self.aas.say(self.say_7)
self.mtn.rest()
self.mtn.setStiffnesses(self.hips, 1.0)
def play_sounds(self, soundfiles_att):
'''
Uploads the stimuli files to Sam using a paramiko sftp server.
Sam then plays the files, then deletes them off its main storage.
'''
soundfiles = list(soundfiles_att.split(", "))
# soundfiles = []
# filename = ""
# for i in soundfiles_att:
# if i == ',':
# soundfiles.append(filename)
# filename = ''
# else:
# filename = filename+i
NAO_USERNAME = "nao"
NAO_PASSWORD = "nao"
t = paramiko.Transport((self.ipadress, 22))
t.connect(username=NAO_USERNAME, password=NAO_PASSWORD)
sftp = paramiko.SFTPClient.from_transport(t)
sftp.chdir('/home/nao/tests/')
for soundfile in soundfiles:
# localpath = (
# 'C:\\Users\\Nao\\Documents\\Nao\\Python_scripts\\tmp\\' + soundfile)
# localpath = "./" + soundfile.strip()
remotepath = str('/home/nao/tests/' + soundfile)
try:
sftp.put(soundfile, remotepath)
except:
raise ValueError('Yo cannot find the right stuff')
for i in range(1, 1000):
dir_list = sftp.listdir()
if soundfile in dir_list:
break
else:
time.sleep(0.01)
if i == 999:
raise ValueError('File was not uploaded to nao')
sys.exit()
for soundfile in soundfiles:
# localpath = (
# 'C:\\Users\\Nao\\Documents\\Nao scripts\\Expe_files\\' + soundfile)
localpath = "./tmp/" + soundfile
remotepath = str('/home/nao/tests/' + soundfile)
try:
self.aap.playFile(remotepath)
except RuntimeError:
# raise ValueError(
# 'stupid thing needs to be string check type')
sys.exit(0)
sys.exit(0)
sftp.remove(soundfile)
time.sleep(0.5)
def answer(self, robot_input):
'''
Waits for the response from the subject on which of the sounds was different.
'''
try:
if self.language == 'EN':
self.say_1 = "That is correct."
self.say_2 = "That is incorrect."
self.say_3 = "You did not give an answer."
elif self.language == 'NL':
self.say_1 = "Dat is correct."
self.say_2 = "Dat is niet correct."
self.say_3 = "Je hebt geen antwoord gegeven."
correct_answer = int(robot_input[0])
feedback = int(robot_input[1])
# this function returns the answer given by the participant. As input it requires the correct answer (from matlab) and it has an option for feedback (0 or 1).
start_time = time.time()
# LEDs change colour to indicate Sam is ready for a response
self.all.fadeRGB("FaceLeds", "green", 0.01)
current_running_time = 0
answer_given = 0
# TODO maybe add a warning after 7 seconds.
# TODO add a way to replay the sounds if necessary?
while current_running_time < (start_time+120):
# check the data continously for 7 seconds
try:
head1 = self.mem.getData('RearTactilTouched')
head2 = self.mem.getData('FrontTactilTouched')
head3 = self.mem.getData('MiddleTactilTouched')
head = [head1, head2, head3]
left1 = self.mem.getData('HandLeftRightTouched')
left2 = self.mem.getData('HandLeftBackTouched')
left3 = self.mem.getData('HandLeftLeftTouched')
left = [left1, left2, left3]
right1 = self.mem.getData('HandRightRightTouched')
right2 = self.mem.getData('HandRightBackTouched')
right3 = self.mem.getData('HandRightLeftTouched')
right = [right1, right2, right3]
if any(right):
answer_given = 0
break
elif any(head):
answer_given = 1
break
elif any(left):
answer_given = 2
break
current_running_time = time.time()
except RuntimeError:
sys.exit(0)
if feedback == 1:
self.mtn.setStiffnesses(["HeadYaw", "HeadPitch"], [1.0, 1.0])
if answer_given == correct_answer:
self.head_nod()
elif answer_given != correct_answer:
self.head_shake()
else:
self.tts.say(self.say_3)
self.mtn.setStiffnesses(["HeadYaw", "HeadPitch"], [0.0, 0.0])
self.all.fadeRGB("FaceLeds", "white", 0.1)
return answer_given
except RuntimeError:
sys.exit(0)
# === Custom movements ===
+231
View File
@@ -0,0 +1,231 @@
from naoqi import ALProxy
from Robot import Robot
import paramiko
import time
import sys
import os
import numpy as np
class RobotGender(Robot):
def genderIntro(self):
if self.language == "EN":
self.say_1 = "^start(animations/Stand/Gestures/Explain_2)You are going to hear a voice that sounds either like a boy, or a girl. \
It is your task to determine the gender of the voice. \
You can answer by touching my right hand, \\pau=500\\or left hand. \
Each time you hear a voice, I will tell you which of my hands is for boy, and which hand is for girl. \
^wait(animations/Stand/Gestures/Explain_2)"
self.say_2 = "\\pau=500\\ During the experiment, when my eyes turn green like this,"
self.say_3 = "I am ready for your answer."
# self.say_4 = "One last thing. If at any point you want to stop the experiment, wait for me to stop talking, and then press my right foot. \\pau=500\\ Now I will try to make myself as quite as possible."
self.say_4 = "Now I will try to make myself as quite as possible."
if self.language == "NL":
self.say_1 = "^start(animations/Stand/Gestures/Explain_2)Je gaat een stem horen die zoals een jongen of een meisje klinkt. \
Ik vraag dan aan jou of je de stem van een jongen of een meisje hebt gehoord. \
Je kunt antwoorden door mijn rechterhand, \\pau=500\\of linkerhand aan te raken. \
Elke keer als je een stem hoort, zal ik je vertellen welke hand voor jongen is, en welke hand voor meisje is. \
^wait(animations/Stand/Gestures/Explain_2)"
self.say_2 = "\\pau=500\\ Tijdens het experiment, als mijn ogen zo groen worden,"
self.say_3 = "Mag jij antwoord geven."
self.say_4 = "Nog een ding. Als je het experiment tussendoor wilt stoppen, wacht dan tot ik ben gestopt met praten en raak dan mijn rechtervoet aan. \\pau=500\\ Nou zal ik me nu zo stil mogelijk maken."
self.mtn.wakeUp()
self.aas.say(self.say_1)
self.aas.setBodyLanguageMode = 0
self.pst.goToPosture("Stand", 0.7)
self.aas.say(self.say_2)
self.all.fadeRGB("FaceLeds", "green", 0.01)
self.tts.say("\\pau=150\\")
self.aas.say(self.say_3)
self.all.fadeRGB("FaceLeds", "white", 0.01)
self.aas.say(self.say_4)
self.mtn.rest()
self.mtn.setStiffnesses(self.hips, 1.0)
def play_sounds(self, stimulus, lang):
'''
Uploads the stimuli files to Sam using a paramiko sftp server.
Sam then plays the files, then deletes them off its main storage.
'''
NAO_USERNAME = "nao"
NAO_PASSWORD = "nao"
t = paramiko.Transport((self.ipadress, 22))
t.connect(username=NAO_USERNAME, password=NAO_PASSWORD)
sftp = paramiko.SFTPClient.from_transport(t)
sftp.chdir('/home/nao/tests/')
remotepath = str('/home/nao/tests/' + stimulus)
try:
sftp.put(stimulus, remotepath)
except:
raise ValueError('No file provided for upload.')
for i in range(1, 1000):
dir_list = sftp.listdir()
if stimulus in dir_list:
break
else:
time.sleep(0.01)
if i == 999:
raise ValueError('File was not uploaded to nao')
# localpath = (
# 'C:\\Users\\Nao\\Documents\\Nao scripts\\Expe_files\\' + soundfile)
remotepath = str('/home/nao/tests/' + stimulus)
try:
self.aap.playFile(remotepath)
except RuntimeError:
# raise ValueError(
# 'stupid thing needs to be string check type')
sys.exit(0)
sftp.remove(stimulus)
time.sleep(0.5)
def answer(self):
self.mtn.setStiffnesses(self.hips, 1.0)
self.mtn.setStiffnesses(
["RShoulderPitch", "RShoulderRoll", "RElbowYaw", "RElbowRoll", "RWristYaw", "LShoulderPitch", "LShoulderRoll", "LElbowYaw", "LElbowRoll", "LWristYaw"], 1.0)
OR = ""
if self.language == "EN":
gender = np.array(["Boy?", "Girl?"])
OR = "or"
elif self.language == "NL":
gender = np.array(["Jongen?", "Meisje?"])
OR = "of"
np.random.shuffle(gender)
self.rightHandMotion(gender[0])
self.tts.say(OR)
self.leftHandMove(gender[1])
self.mtn.setStiffnesses(
["RShoulderPitch", "RShoulderRoll", "RElbowYaw", "RElbowRoll", "RWristYaw", "LShoulderPitch", "LShoulderRoll", "LElbowYaw", "LElbowRoll", "LWristYaw"], 0.0)
start_time = time.time()
self.all.fadeRGB("FaceLeds", "green", 0.01)
current_running_time = 0
answer_given = 0
gender_chosen = ""
while current_running_time < (start_time + 120):
try:
left1 = self.mem.getData('HandLeftRightTouched')
left2 = self.mem.getData('HandLeftBackTouched')
left3 = self.mem.getData('HandLeftLeftTouched')
left = [left1, left2, left3]
right1 = self.mem.getData('HandRightRightTouched')
right2 = self.mem.getData('HandRightBackTouched')
right3 = self.mem.getData('HandRightLeftTouched')
right = [right1, right2, right3]
if any(right):
answer_given = 1
gender_chosen = gender[0].split(" ")[-1][:-1]
break
elif any(left):
answer_given = 2
gender_chosen = gender[1].split(" ")[-1][:-1]
break
current_running_time = time.time()
except RuntimeError:
sys.exit(0)
self.all.fadeRGB("FaceLeds", "white", 0.01)
resp = {"answer": answer_given, "gender": gender_chosen}
return resp, gender_chosen
# === Custom movements ===
def rightHandMotion(self, gender):
# Choregraphe bezier export in Python.
names = list()
times = list()
keys = list()
names.append("RElbowRoll")
times.append([1, 1.48, 1.96])
keys.append([[0.90817, [3, -0.333333, 0], [3, 0.16, 0]], [0.909704,
[3, -0.16, 0], [3, 0.16, 0]], [0.865218, [3, -0.16, 0], [3, 0, 0]]])
names.append("RElbowYaw")
times.append([1, 1.48, 1.96])
keys.append([[0.493906, [3, -0.333333, 0], [3, 0.16, 0]], [1.00626,
[3, -0.16, 0], [3, 0.16, 0]], [0.486236, [3, -0.16, 0], [3, 0, 0]]])
names.append("RHand")
times.append([1, 1.48, 1.96])
keys.append([[0.3544, [3, -0.333333, 0], [3, 0.16, 0]], [0.3544,
[3, -0.16, 0], [3, 0.16, 0]], [0.3544, [3, -0.16, 0], [3, 0, 0]]])
names.append("RShoulderPitch")
times.append([1, 1.48, 1.96])
keys.append([[1.21804, [3, -0.333333, 0], [3, 0.16, 0]], [1.05083,
[3, -0.16, 0], [3, 0.16, 0]], [1.23338, [3, -0.16, 0], [3, 0, 0]]])
names.append("RShoulderRoll")
times.append([1, 1.48, 1.96])
keys.append([[-0.0552659, [3, -0.333333, 0], [3, 0.16, 0]], [-0.305308,
[3, -0.16, 0], [3, 0.16, 0]], [0.0229681, [3, -0.16, 0], [3, 0, 0]]])
names.append("RWristYaw")
times.append([1, 1.48, 1.96])
keys.append([[0.23466, [3, -0.333333, 0], [3, 0.16, 0]], [1.41737,
[3, -0.16, 0], [3, 0.16, 0]], [0.0429101, [3, -0.16, 0], [3, 0, 0]]])
try:
# uncomment the following line and modify the IP if you use this script outside Choregraphe.
# motion = ALProxy("ALMotion", IP, 9559)
motion = ALProxy("ALMotion")
motion.moveInit()
w = motion.post.angleInterpolationBezier(names, times, keys)
self.tts.say(gender)
motion.wait(w, 0)
except BaseException, err:
print err
def leftHandMove(self, gender):
# Choregraphe bezier export in Python.
names = list()
times = list()
keys = list()
names.append("LElbowRoll")
times.append([1, 1.48])
keys.append([[-1.03848, [3, -0.333333, 0], [3, 0.16, 0]],
[-1.04921, [3, -0.16, 0], [3, 0, 0]]])
names.append("LElbowYaw")
times.append([1, 1.48])
keys.append([[-1.71505, [3, -0.333333, 0], [3, 0.16, 0]],
[-1.49416, [3, -0.16, 0], [3, 0, 0]]])
names.append("LHand")
times.append([1, 1.48])
keys.append([[0.0296, [3, -0.333333, 0], [3, 0.16, 0]],
[0.0296, [3, -0.16, 0], [3, 0, 0]]])
names.append("LShoulderPitch")
times.append([1, 1.48])
keys.append([[1.20875, [3, -0.333333, 0], [3, 0.16, 0]],
[1.53856, [3, -0.16, 0], [3, 0, 0]]])
names.append("LShoulderRoll")
times.append([1, 1.48])
keys.append([[0.171766, [3, -0.333333, 0], [3, 0.16, 0]],
[-0.220938, [3, -0.16, 0], [3, 0, 0]]])
names.append("LWristYaw")
times.append([1, 1.48])
keys.append([[-0.983336, [3, -0.333333, 0], [3, 0.16, 0]],
[0.96331, [3, -0.16, 0], [3, 0, 0]]])
try:
# uncomment the following line and modify the IP if you use this script outside Choregraphe.
# motion = ALProxy("ALMotion", IP, 9559)
motion = ALProxy("ALMotion")
motion.moveInit()
w = motion.post.angleInterpolationBezier(names, times, keys)
self.tts.say(gender)
motion.wait(w, 0)
except BaseException, err:
print err
View File
Whitespace-only changes.