Wiki

Clone wiki

scl-manips-group / nengo / SocketNode

Implementation and Usage Notes

File: socketnode.py

class SocketNode(nef.SimpleNode)

This is the node used to communicate with either the robot or the environment/stimulus. An input/output cycle will happen once per simulation tick. The dimensions of the Origins "in" and "out" define the size (in number of doubles) of the packets that will be received and transmitted, respectively. The initialization parameters are:

  • (str) name - for identification
  • (int) recvDimensions - number of double values this socket should receive and store
  • (int) sendDimensions - number of double values this socket should expect to send
  • (str) role - 'client' or 'server' (optional, defaults to server)
  • (str) protocol - 'tcp' or 'udp' (optional, defaults to udp)
  • (float) pstc - post-synaptic time constant in seconds (optional, defaults to 0.03)

Usage patterns

Initialization
To create a socket node, you must first call the SocketNodeFactory, which will return the appropriate class object. This is simply to allow arbitrary dimensions for the "out" termination. Nengo either uses the default value of the keyword argument "dimensions" for the termination function or evaluates the function once to determine the dimension. After all connections have been established, you can start the socket communication by calling the start() function with the address and port of the intended connection.

Suppose we want a socket node to communicate with a 3 DOF robot. The input from the robot will be 6-D (3 joint angles and 3 joint velocities) and the output will be 3-D (3 torque commands). The initialization would look like this:

socket_node_class = SocketNodeFactory(3) # Since we will be sending out 3-d information
robot_socket_node = socket_node_class("robot node", 6, 3, role='server', protocol='tcp', pstc=0.015)
# Make other connections...
robot_socket_node.start("127.0.0.1", 5001, buffersize=1024, respond=True)

TO DO
Currently, the socket communication uses the machine's native byte order. This has not caused any problems, since both sides have been on the same computer until now. Will need to use network byte order and convert the doubles appropriately to generalize

Updated