diff --git a/README.md b/README.md index 0ef4cbe735034cbac80b0a20e2660b663b8f38bc..ccf3efca5db7a17d02fa6edc608c6ac4a2dead61 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,50 @@ in world coordinates of the ball to all its subscribers Both services use configuration files (JSON). You can see examples in the example folder. +### Client (Subscriber) Example + +* The client can be written in any programming language +* Can also be executed in a separate machine as the vision system +* Assuming the server runs in a machine called "Rodau" in the TCP port 7660, see +the following example written in Python: + +``` +import sys +import zmq +import json + +url = "tcp://rodau:7660" +context = zmq.Context() +socket = context.socket(zmq.SUB) + +print "Connecting to {0}".format(url) +socket.connect(url) + +topicfilter = "" +socket.setsockopt(zmq.SUBSCRIBE, topicfilter) + +num_obs = 1000 +obs = [] +ball_in_scene = False +null_warn = 10 +while (len(obs) < num_obs): + #topic = socket.recv() + body = socket.recv() + msg = json.loads(body) + if msg['obs'] is None and null_warn>0: + print "Observing null" + null_warn-=1 + if msg['obs'] is not None and not ball_in_scene: + ball_in_scene = True + print "First ball observed" + if ball_in_scene: + obs.append(msg) + print msg +``` + +* The example fills the list **obs** with all the 3D observations returned by the vision system until +1000 are read +* If there is no ball in the scene, the server returns **null**. ## Installation