Search code examples
pythonerror-handlingnao-robot

Error in python code in Choregraphe


today I started Choregraphe on my new notebook and I have observed an error I haven't seen yet. The code worked perfectly.

Here is the code:

import sys
import time
from naoqi import ALProxy

def main(robotIP):

    PORT = 5058

    try:
        motionProxy = ALProxy("ALMotion",robotIP,PORT)
    except Exception,e:
        print "Could not create proxy to ALMotion"
        print "Error was: "
        sys.exit(1)

    motionProxy.setStiffnesses("Head", 1.0)

    names = "HeadPitch"
    angleLists = 0.349
    timeLists = 1.0
    isAbsolute = True
    motionProxy.angleInterpolation(names,angleLists,timeLists,isAbsolute)

    time.sleep(1.0)

    motionProxy.setStiffnesses("Head",0.0)

if __name__ == "__main__":
    robotIP = "192.168.0.20"
    main(robotIP)

This code should move head pitch by angle. Yes it worked. The question is: Why is the code showing me this error?

User class evaluation failed with the error:1

I tried to retype the code or tried to hit "ENTER" at the beginning of the code(on C# works sometimes) but nothing works.

Can someone give me an advice what to do?


Solution

  • you can change the port by 9559. Moreover, there is a new code for naoqi I give you an example :

    #! /usr/bin/env python
    # -*- encoding: UTF-8 -*-
    
    import qi
    import sys
    import argparse
    
    
    
    def main(session):
        motionProxy = session.service("ALMotion")
    
        motionProxy.setStiffnesses("Head", 1.0)
    
        names = "HeadPitch"
        angleLists = 0.349
        timeLists = 1.0
        isAbsolute = True
        motionProxy.angleInterpolation(names,angleLists,timeLists,isAbsolute)
    
    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")
    
        args = parser.parse_args()
        session = qi.Session()
        try:
            session.connect("tcp://" + args.ip + ":" + str(args.port))
        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(session)