简体   繁体   中英

Executing NAO Choregraphe timeline in python

I need to make a virtual NAO robot speak and move through Python. I am doing this by making movements in Choregraph and exporting these to python. But I don't know how to execute these in Python. I am a beginner at programming so I would appreciate any help!

(The code of the movement is pretty long so I only copied the beginning and the end. I replaced the middle with....)

EDIT = I followed the Hello World Script. My robot does "talk" and execute the sentence. But does not execute the rest of the code. There is no error. The portnumber is 9559 with my robot. This is what I have:

from naoqi import ALProxy
tts = ALProxy ("ALTextToSpeech","127.0.0.1",9559)
tts = ALProxy ("ALMotion","127.0.0.1",9559)

import qi
import argparse
import stk.services
import os
import sys
import time

from naoqi import ALProxy

import time
import argparse
from naoqi import ALProxy
tts = ALProxy ("ALTextToSpeech","127.0.0.1",9559)


tts.say ("Hello my name is Nao \\pau=1000\\ and I am a robot")
#moving his arms welcoming

def main(robotIP, PORT = 9559):

    motion.Proxy.wakeUp()

    names = list()
    times = list()
    keys = list()

    names.append("HeadPitch")
    times.append([0, 0.48, 1, 1.48])
    keys.append([-0.0429941, -0.2102, 0.0820305, -0.16418])

    names.append("HeadYaw")
    times.append([0, 0.48, 1, 1.48])
    keys.append([0.0858622, 0.0398422, 0.0398422, 0.0536479])

    names.append("LAnklePitch")
    times.append([0, 0.4, 0.96, 1.36])
    keys.append([-0.023052, 0.030638, -0.0583338, -0.062936])

    names.append("LAnkleRoll")
    times.append([0, 0.4, 0.96, 1.36])
    keys.append([0.00771189, -0.05825, -0.0628521, -0.05825])

    names.append("LElbowRoll")
    times.append([0, 0.4, 0.92, 1.4])
    keys.append([-1.24403, -1.52015, -1.15715, -1.30027])

    names.append("LElbowYaw")
    times.append([0, 0.4, 0.92, 1.4])
    keys.append([-0.849878, -1.15054, -1.71812, -1.77181])

    names.append("LHand")
    times.append([0, 0.4, 0.92, 1.4])
    keys.append([0.2132, 0.2132, 0.68, 0.7728])

    names.append("LHipPitch")
    times.append([0, 0.4, 0.96, 1.36])
    keys.append([0.242414, 0.44797, -0.115008, -0.0122299])

    names.append("LHipRoll")
    times.append([0, 0.4, 0.96, 1.36])
    keys.append([0.01845, 0.112024, -0.00916195, 0.0123138])

    names.append("LHipYawPitch")
    times.append([0, 0.4, 0.96, 1.36])
    keys.append([-0.352778, -0.338973, -0.366584, -0.371186])

    names.append("LKneePitch")
    times.append([0, 0.4, 0.96, 1.36])
    keys.append([0.128814, -0.0859461, 0.400331, 0.312894])

    names.append("LShoulderPitch")
    times.append([0, 0.4, 0.92, 1.4])
    keys.append([1.46186, 1.333, 1.32687, 1.40817])

    names.append("LShoulderRoll")
    times.append([0, 0.4, 0.92, 1.4])
    keys.append([0.0827939, -0.0414601, -0.00924586, -0.030722])

    names.append("LWristYaw")
    times.append([0, 0.4, 0.92, 1.4])
    keys.append([0.539926, 0.21932, -0.70875, -0.808459])

    names.append("RAnklePitch")
    times.append([0, 0.4, 0.96, 1.36])
    keys.append([0.00157595, -0.06592, -0.266875, -0.251533])

    names.append("RAnkleRoll")
    times.append([0, 0.4, 0.96, 1.36])
    keys.append([0.127364, 0.0706061, 0.016916, 0.0337899])

    names.append("RElbowRoll")
    times.append([0, 0.52, 1, 1.52])
    keys.append([1.26559, 1.51717, 1.15715, 1.30027])

    names.append("RElbowYaw")
    times.append([0, 0.52, 1, 1.52])
    keys.append([1.39436, 1.17807, 1.87297, 1.94201])

    names.append("RHand")
    times.append([0, 0.52, 1, 1.52])
    keys.append([0.0456001, 0.0456001, 0.68, 0.7692])

    names.append("RHipPitch")
    times.append([0, 0.4, 0.96, 1.36])
    keys.append([0.306757, 0.466294, -0.24088, -0.099752])

    names.append("RHipRoll")
    times.append([0, 0.4, 0.96, 1.36])
    keys.append([-0.171766, -0.130348, -0.0720561, -0.078192])

    names.append("RHipYawPitch")
    times.append([0, 0.4, 0.96, 1.36])
    keys.append([-0.352778, -0.338973, -0.366584, -0.371186])

    names.append("RKneePitch")
    times.append([0, 0.4, 0.96, 1.36])
    keys.append([0.0245859, -0.0122299, 0.698011, 0.559952])

    names.append("RShoulderPitch")
    times.append([0, 0.52, 1, 1.52])
    keys.append([1.83778, 1.29934, 1.5141, 1.52944])

    names.append("RShoulderRoll")
    times.append([0, 0.52, 1, 1.52])
    keys.append([-0.136568, -0.019984, 0.0413762, 0.0398422])

    names.append("RWristYaw")
    times.append([0, 0.52, 1, 1.52])
    keys.append([-0.339056, 0.0889301, 0.935697, 1.1029])

    try: 
      motion = ALProxy("ALMotion", "127.0.0.1", 9559)
      motion = ALProxy("ALMotion")
      motion.angleInterpolation(names, keys, times, True)
    except BaseException, err:
      print err

Does anyone know what I should add to be able to execute this through Python?

Welcome to stack overflow !

For running a python script on NAO (real or virtual), see this basic hello world explanation - though be sure to replace 9559 with the actual port of your virtual robot, and be careful that that port might change after you close and re-open Choregraphe!

Once you get the "hello world" working, you can just use ALMotion the same way you used ALTextToSpeech.

If you get an error, you can try posting it here (with just your code it's not easy to tell what you're doing wrong, the code itself looks fine except for the port number).

Based on your updated code, it looks like you've just used the wrong main formulation for Python, so all the code in the main function isn't running because it's never called.

In Python, you define a main function like this.

from naoqi import ALProxy
# rest of setup code...

if __name__ == "__main__":
    tts = ALProxy ("ALTextToSpeech","127.0.0.1",9559)
    tts.say("hello")
    # the rest of your code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM