Created
September 12, 2017 11:29
-
-
Save robbestad/1c551cfdb3a2878000bf31dbf1499708 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: UTF-8 -*- | |
import qi as qi | |
import sys | |
import argparse | |
class RobotName(object): | |
def __init__(self, app): | |
""" | |
Initialisation of qi framework and event detection. | |
""" | |
super(RobotName, self).__init__() | |
app.start() | |
session = app.session | |
self.system = session.service("ALSystem") | |
self.store = session.service("ALStore") | |
self.tts = session.service("ALTextToSpeech") | |
def run(self): | |
# call method | |
# while(True): | |
# input = raw_input("Say something (ctrl+C to exit): ") | |
# self.tts.say("\\style=joyful\\ \\rspd=1\\ I am a happy robot \\pau=500\\ \\rspd=30\\ Would you like to play a \\emph=2\\game ") | |
# self.tts.say("\\rspd=1\\ fromage " + input) | |
# self.tts.say("\\rspd=15\\ \\toi=lhp\\\‘fR+o&U \\toi=orth\\ ") | |
robotName = raw_input("Enter a new name (ctrl+C to exit): ") | |
try: | |
print "Changed robot name to " + robotName | |
# self.tts.say( | |
# "\\style=joyful\\ \\rspd=1\\ Oh \\emph=1\\ thank \\emph=0\\ you so much \\pau=500\\ \\rspd=30\\ From now on, please call me \\emph=2\\ " + robotName) | |
self.system.setRobotName(robotName) | |
self.store.update() | |
self.system.reboot() | |
exit(0) | |
except RuntimeError,e: | |
print "Failed to change robot name:" | |
print str(e) | |
exit(1) | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--ip", type=str, default="127.0.0.1", | |
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") | |
parser.add_argument("--name", type=str, default="Pepe", | |
help="Robot name") | |
args = parser.parse_args() | |
try: | |
# Initialize qi framework. | |
connection_url = "tcp://" + args.ip + ":" + str(args.port) | |
name = str(args.name) | |
app = qi.Application(["RobotName", "--qi-url=" + connection_url]) | |
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) | |
app = RobotName(app) | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment