0

I need to establish a socket connection between the Nao client and my pc which acts as a server, the python script below has been put on a box on choregraph, I need my Nao robot to take a picture and send it to the server.

class MyClass(GeneratedClass):
def __init__(self):
    GeneratedClass.__init__(self)

def onLoad(self):
    #put initialization code here
    pass

def onUnload(self):
    #put clean-up code here
    pass

def onInput_onStart(self):
    import socket
    import pickle
    import sys

    HOST = '192.168.0.233' # The server's hostname or IP address
    PORT = 8002       # The port used by the server

    #Establish connection
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST, PORT))

    #Call ALVideoDevice service
    session = self.session()
    camSession = session.service("ALVideoDevice")
    resolution = 2 #VGA
    colorSpace = 11 #RGB
    fps = 5

    nameId = camSession.subscribeCamera("cameratest",0,resolution,colorSpace,fps)

    #Get camera image
    naoImage = camSession.getImageRemote(nameId)
    camSession.releaseImage(nameId)
    camSession.unsubscribe(nameId)

    try:
        #Send buffer size
        size = sys.getsizeof(pickle.dumps(naoImage[6]))
        s.send(str(size))

        #Send image to server
        s.send(pickle.dumps(naoImage[6]) + b'[END OF IMAGE]')

        #Get emotion response from server
        emotion=b""
        emotion = s.recv(1024)
        self.logger.info(emotion)

    except Exception as e:
        pass
    finally:
        s.close()
        self.output_emotion(emotion)
        self.onStopped()
    pass

And I got this error

[ERROR] behavior.box :_safeCallOfUserMethod:130 _Behavior__lastUploadedChoregrapheBehaviorbehavior_12771477760:/clientnao_1: Traceback (most recent call last): File "/opt/aldebaran/lib/python2.7/site-packages/albehavior.py", line 120, in _safeCallOfUserMethod func() File "<string>", line 56, in onInput_onStart File "/opt/aldebaran/lib/python2.7/site-packages/ialbehavior.py", line 166, in <lambda> __getattr__ = lambda self, name: _swig_getattr(self, behavior, name) File "/opt/aldebaran/lib/python2.7/site-packages/ialbehavior.py", line 74, in _swig_getattr return _swig_getattr_nondynamic(self, class_type, name, 0) File "/opt/aldebaran/lib/python2.7/site-packages/ialbehavior.py", line 69, in _swig_getattr_nondynamic return object.__getattr__(self, name) AttributeError: type object 'object' has no attribute '__getattr__'

nada nada
  • 1
  • 1
  • 1
    try commenting each line/blocks to find the one producing this error, is it the socket opening, the image grabbing, the send... – Alexandre Mazel Oct 17 '22 at 10:11

0 Answers0